Browse Source

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

tags/v0.1.3.0
NGnius 4 years ago
parent
commit
2f5064a41d
5 changed files with 47 additions and 0 deletions
  1. +8
    -0
      GamecraftModdingAPI/Commands/CommandManager.cs
  2. +13
    -0
      GamecraftModdingAPI/Events/EventManager.cs
  3. +10
    -0
      GamecraftModdingAPI/Events/SimpleEventHandlerEngine.cs
  4. +8
    -0
      GamecraftModdingAPI/Utility/GameEngineManager.cs
  5. +8
    -0
      GamecraftModdingAPI/Utility/MenuEngineManager.cs

+ 8
- 0
GamecraftModdingAPI/Commands/CommandManager.cs 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}");


+ 13
- 0
GamecraftModdingAPI/Events/EventManager.cs 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)


+ 10
- 0
GamecraftModdingAPI/Events/SimpleEventHandlerEngine.cs 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)


+ 8
- 0
GamecraftModdingAPI/Utility/GameEngineManager.cs 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}");


+ 8
- 0
GamecraftModdingAPI/Utility/MenuEngineManager.cs 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}");


Loading…
Cancel
Save