Make engines get registered ASAP instead of on next engine root switch

This commit is contained in:
NGnius 2020-01-26 14:28:57 -05:00
parent bc3dc81338
commit 2f5064a41d
5 changed files with 47 additions and 0 deletions

View file

@ -18,9 +18,16 @@ namespace GamecraftModdingAPI.Commands
{
private static Dictionary<string, ICustomCommandEngine> _customCommands = new Dictionary<string, ICustomCommandEngine>();
private static EnginesRoot _lastEngineRoot;
public static void AddCommand(ICustomCommandEngine engine)
{
_customCommands[engine.Name] = engine;
if (_lastEngineRoot != null)
{
Logging.MetaDebugLog($"Registering ICustomCommandEngine {engine.Name}");
_lastEngineRoot.AddEngine(engine);
}
}
public static bool ExistsCommand(string name)
@ -50,6 +57,7 @@ namespace GamecraftModdingAPI.Commands
public static void RegisterEngines(EnginesRoot enginesRoot)
{
_lastEngineRoot = enginesRoot;
foreach (var key in _customCommands.Keys)
{
Logging.MetaDebugLog($"Registering ICustomCommandEngine {_customCommands[key].Name}");

View file

@ -20,11 +20,18 @@ namespace GamecraftModdingAPI.Events
private static Dictionary<string, IEventHandlerEngine> _eventHandlers = new Dictionary<string, IEventHandlerEngine>();
private static EnginesRoot _lastEngineRoot;
// event handler management
public static void AddEventHandler(IEventHandlerEngine engine)
{
_eventHandlers[engine.Name] = engine;
if (_lastEngineRoot != null)
{
Logging.MetaDebugLog($"Registering IEventHandlerEngine {engine.Name}");
_lastEngineRoot.AddEngine(engine);
}
}
public static bool ExistsEventHandler(string name)
@ -57,6 +64,11 @@ namespace GamecraftModdingAPI.Events
public static void AddEventEmitter(IEventEmitterEngine engine)
{
_eventEmitters[engine.Name] = engine;
if (_lastEngineRoot != null)
{
Logging.MetaDebugLog($"Registering IEventEmitterEngine {engine.Name}");
_lastEngineRoot.AddEngine(engine);
}
}
public static bool ExistsEventEmitter(string name)
@ -89,6 +101,7 @@ namespace GamecraftModdingAPI.Events
public static void RegisterEngines(EnginesRoot enginesRoot)
{
_lastEngineRoot = enginesRoot;
// Register handlers before emitters so no events are missed
var entityFactory = enginesRoot.GenerateEntityFactory();
foreach (var key in _eventHandlers.Keys)

View file

@ -33,6 +33,16 @@ namespace GamecraftModdingAPI.Events
}
}
/// <summary>
/// Manually activate the EventHandler.
/// Once activated, the next remove event will not be ignored.
/// </summary>
/// <param name="handle">Whether to invoke the activated action</param>
public void Activate(bool handle = false)
{
isActivated = true;
}
public void Ready() { }
public void Remove(ref ModEventEntityStruct entityView, EGID egid)

View file

@ -15,9 +15,16 @@ namespace GamecraftModdingAPI.Utility
{
private static Dictionary<string, IApiEngine> _gameEngines = new Dictionary<string, IApiEngine>();
private static EnginesRoot _lastEngineRoot;
public static void AddGameEngine(IApiEngine engine)
{
_gameEngines[engine.Name] = engine;
if (_lastEngineRoot != null)
{
Logging.MetaDebugLog($"Registering Game IApiEngine {engine.Name}");
_lastEngineRoot.AddEngine(engine);
}
}
public static bool ExistsGameEngine(string name)
@ -47,6 +54,7 @@ namespace GamecraftModdingAPI.Utility
public static void RegisterEngines(EnginesRoot enginesRoot)
{
_lastEngineRoot = enginesRoot;
foreach (var key in _gameEngines.Keys)
{
Logging.MetaDebugLog($"Registering Game IApiEngine {_gameEngines[key].Name}");

View file

@ -15,10 +15,17 @@ namespace GamecraftModdingAPI.Utility
{
private static Dictionary<string, IApiEngine> _menuEngines = new Dictionary<string, IApiEngine>();
private static EnginesRoot _lastEngineRoot;
// menu engine management
public static void AddMenuEngine(IApiEngine engine)
{
_menuEngines[engine.Name] = engine;
if (_lastEngineRoot != null)
{
Logging.MetaDebugLog($"Registering Menu IApiEngine {engine.Name}");
_lastEngineRoot.AddEngine(engine);
}
}
public static bool ExistsMenuEngine(string name)
@ -48,6 +55,7 @@ namespace GamecraftModdingAPI.Utility
public static void RegisterEngines(EnginesRoot enginesRoot)
{
_lastEngineRoot = enginesRoot;
foreach (var key in _menuEngines.Keys)
{
Logging.MetaDebugLog($"Registering Menu IApiEngine {_menuEngines[key].Name}");