- Fixed the time mode toggle not working during testing (changed the runner) - Made the testing thing wait until the time toggle finishes - Fixed the Game.Enter/Exit event being triggered on time mode change - Added a way to spawn and despawn the player's machine (which doesn't work yet) - Fixed the Player.Id property always being 0 - Attempted to fix the fake action inputs not working in simulation
81 lines
2.6 KiB
C#
81 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
using RobocraftX.StateSync;
|
|
using Svelto.ECS;
|
|
using TechbloxModdingAPI.Engines;
|
|
|
|
namespace TechbloxModdingAPI.Utility
|
|
{
|
|
/// <summary>
|
|
/// Keeps track of custom game-modifying engines
|
|
/// </summary>
|
|
public static class GameEngineManager
|
|
{
|
|
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);
|
|
if (engine is IFactoryEngine factoryEngine)
|
|
factoryEngine.Factory = _lastEngineRoot.GenerateEntityFactory();
|
|
if (engine is IFunEngine funEngine)
|
|
funEngine.Functions = _lastEngineRoot.GenerateEntityFunctions();
|
|
}
|
|
}
|
|
|
|
public static bool ExistsGameEngine(string name)
|
|
{
|
|
return _gameEngines.ContainsKey(name);
|
|
}
|
|
|
|
public static bool ExistsGameEngine(IApiEngine engine)
|
|
{
|
|
return ExistsGameEngine(engine.Name);
|
|
}
|
|
|
|
public static IApiEngine GetGameEngine(string name)
|
|
{
|
|
return _gameEngines[name];
|
|
}
|
|
|
|
public static string[] GetGameEngineNames()
|
|
{
|
|
return _gameEngines.Keys.ToArray();
|
|
}
|
|
|
|
public static void RemoveGameEngine(string name)
|
|
{
|
|
if (_gameEngines[name].isRemovable)
|
|
{
|
|
_gameEngines.Remove(name);
|
|
}
|
|
}
|
|
|
|
public static void RegisterEngines(StateSyncRegistrationHelper helper)
|
|
{
|
|
var enginesRoot = helper.enginesRoot;
|
|
_lastEngineRoot = enginesRoot;
|
|
IEntityFactory factory = enginesRoot.GenerateEntityFactory();
|
|
IEntityFunctions functions = enginesRoot.GenerateEntityFunctions();
|
|
foreach (var key in _gameEngines.Keys)
|
|
{
|
|
Logging.MetaDebugLog($"Registering Game IApiEngine {_gameEngines[key].Name}");
|
|
if (_gameEngines[key] is IDeterministicEngine detEngine)
|
|
helper.AddDeterministicEngine(detEngine);
|
|
else
|
|
enginesRoot.AddEngine(_gameEngines[key]);
|
|
if (_gameEngines[key] is IFactoryEngine factEngine)
|
|
factEngine.Factory = factory;
|
|
if (_gameEngines[key] is IFunEngine funEngine)
|
|
funEngine.Functions = functions;
|
|
}
|
|
}
|
|
}
|
|
}
|