Rework engine inheritance structure
This commit is contained in:
parent
a17e5a6449
commit
42b21bc16d
25 changed files with 140 additions and 136 deletions
|
@ -18,9 +18,10 @@ using Svelto.ECS.EntityStructs;
|
|||
using Unity.Transforms;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using Svelto.DataStructures;
|
||||
|
||||
using GamecraftModdingAPI.Utility;
|
||||
using Svelto.DataStructures;
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
namespace GamecraftModdingAPI.Blocks
|
||||
{
|
||||
|
@ -33,6 +34,8 @@ namespace GamecraftModdingAPI.Blocks
|
|||
|
||||
public EntitiesDB entitiesDB { set; private get; }
|
||||
|
||||
public bool isRemovable => false;
|
||||
|
||||
public bool IsInGame = false;
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -21,6 +21,7 @@ using UnityEngine;
|
|||
using uREPL;
|
||||
|
||||
using GamecraftModdingAPI.Utility;
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
namespace GamecraftModdingAPI.Blocks
|
||||
{
|
||||
|
@ -128,6 +129,8 @@ namespace GamecraftModdingAPI.Blocks
|
|||
|
||||
public string Name { get; } = "GamecraftModdingAPIPlacementGameEngine";
|
||||
|
||||
public bool isRemovable => false;
|
||||
|
||||
[HarmonyPatch]
|
||||
public class FactoryObtainerPatch
|
||||
{
|
||||
|
|
|
@ -12,6 +12,7 @@ using uREPL;
|
|||
|
||||
using GamecraftModdingAPI.Commands;
|
||||
using GamecraftModdingAPI.Utility;
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
namespace GamecraftModdingAPI.Blocks
|
||||
{
|
||||
|
@ -54,6 +55,8 @@ namespace GamecraftModdingAPI.Blocks
|
|||
|
||||
public string Name { get; } = "GamecraftModdingAPIRemovalGameEngine";
|
||||
|
||||
public bool isRemovable => false;
|
||||
|
||||
[HarmonyPatch]
|
||||
public class FactoryObtainerPatch
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@ using Unity.Mathematics;
|
|||
using UnityEngine;
|
||||
|
||||
using GamecraftModdingAPI.Utility;
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
namespace GamecraftModdingAPI.Blocks
|
||||
{
|
||||
|
@ -32,6 +33,8 @@ namespace GamecraftModdingAPI.Blocks
|
|||
|
||||
public EntitiesDB entitiesDB { set; private get; }
|
||||
|
||||
public bool isRemovable => false;
|
||||
|
||||
public bool IsInGame = false;
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -22,6 +22,7 @@ using UnityEngine;
|
|||
using Gamecraft.Wires;
|
||||
|
||||
using GamecraftModdingAPI.Utility;
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
namespace GamecraftModdingAPI.Blocks
|
||||
{
|
||||
|
@ -34,6 +35,8 @@ namespace GamecraftModdingAPI.Blocks
|
|||
|
||||
public EntitiesDB entitiesDB { set; private get; }
|
||||
|
||||
public bool isRemovable => false;
|
||||
|
||||
public bool IsInGame = false;
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -3,9 +3,11 @@ using System.Reflection;
|
|||
|
||||
using RobocraftX.Blocks;
|
||||
using Gamecraft.Wires;
|
||||
using Svelto.ECS;
|
||||
|
||||
using GamecraftModdingAPI.Utility;
|
||||
using Svelto.ECS;
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
|
||||
namespace GamecraftModdingAPI.Blocks
|
||||
{
|
||||
|
@ -15,6 +17,8 @@ namespace GamecraftModdingAPI.Blocks
|
|||
|
||||
public EntitiesDB entitiesDB { set; private get; }
|
||||
|
||||
public bool isRemovable => false;
|
||||
|
||||
public bool IsInGame = false;
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
|||
using Svelto.ECS;
|
||||
|
||||
using GamecraftModdingAPI.Utility;
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
namespace GamecraftModdingAPI.Commands
|
||||
{
|
||||
|
|
|
@ -31,6 +31,8 @@ namespace GamecraftModdingAPI.Commands
|
|||
|
||||
public EntitiesDB entitiesDB { set; private get; }
|
||||
|
||||
public bool isRemovable => true;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Unregistering SimpleCustomCommandEngine {this.Name}");
|
||||
|
|
|
@ -22,6 +22,8 @@ namespace GamecraftModdingAPI.Commands
|
|||
|
||||
public EntitiesDB entitiesDB { set; private get; }
|
||||
|
||||
public bool isRemovable => true;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Unregistering SimpleCustomCommandEngine {this.Name}");
|
||||
|
|
|
@ -22,6 +22,8 @@ namespace GamecraftModdingAPI.Commands
|
|||
|
||||
public EntitiesDB entitiesDB { set; private get; }
|
||||
|
||||
public bool isRemovable => true;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Unregistering SimpleCustomCommandEngine {this.Name}");
|
||||
|
|
|
@ -22,6 +22,8 @@ namespace GamecraftModdingAPI.Commands
|
|||
|
||||
public EntitiesDB entitiesDB { set; private get; }
|
||||
|
||||
public bool isRemovable => true;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Unregistering SimpleCustomCommandEngine {this.Name}");
|
||||
|
|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||
|
||||
using Svelto.ECS;
|
||||
|
||||
namespace GamecraftModdingAPI.Utility
|
||||
namespace GamecraftModdingAPI.Engines
|
||||
{
|
||||
/// <summary>
|
||||
/// Base engine interface used by all GamecraftModdingAPI engines
|
||||
|
@ -17,5 +17,10 @@ namespace GamecraftModdingAPI.Utility
|
|||
/// The name of the engine
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the emitter can be removed with Manager.RemoveEventEmitter(name)
|
||||
/// </summary>
|
||||
bool isRemovable { get; }
|
||||
}
|
||||
}
|
24
GamecraftModdingAPI/Engines/IFactoryEngine.cs
Normal file
24
GamecraftModdingAPI/Engines/IFactoryEngine.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Svelto.ECS;
|
||||
|
||||
using GamecraftModdingAPI.Utility;
|
||||
|
||||
namespace GamecraftModdingAPI.Engines
|
||||
{
|
||||
/// <summary>
|
||||
/// Engine interface to create a ModEventEntityStruct in entitiesDB when Emit() is called.
|
||||
/// </summary>
|
||||
public interface IFactoryEngine : IApiEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// The EntityFactory for the entitiesDB.
|
||||
/// Use this to create a ModEventEntityStruct when Emit() is called.
|
||||
/// </summary>
|
||||
IEntityFactory Factory { set; }
|
||||
}
|
||||
}
|
20
GamecraftModdingAPI/Engines/IReactionaryEngine.cs
Normal file
20
GamecraftModdingAPI/Engines/IReactionaryEngine.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Svelto.ECS;
|
||||
using Svelto.ECS.Internal;
|
||||
|
||||
using GamecraftModdingAPI.Events;
|
||||
|
||||
namespace GamecraftModdingAPI.Engines
|
||||
{
|
||||
/// <summary>
|
||||
/// Engine interface to handle ModEventEntityStruct events emitted by IEventEmitterEngines.
|
||||
/// </summary>
|
||||
public interface IReactionaryEngine<T> : IApiEngine, IReactOnAddAndRemove<T>, IReactOnAddAndRemove where T : unmanaged, IEntityComponent
|
||||
{
|
||||
}
|
||||
}
|
|
@ -6,34 +6,17 @@ using System.Threading.Tasks;
|
|||
|
||||
using Svelto.ECS;
|
||||
|
||||
using GamecraftModdingAPI.Utility;
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
namespace GamecraftModdingAPI.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Engine interface to create a ModEventEntityStruct in entitiesDB when Emit() is called.
|
||||
/// Engine interface to create a ModEventEntityStruct in entitiesDB when a specific event occurs.
|
||||
/// </summary>
|
||||
public interface IEventEmitterEngine : IApiEngine
|
||||
public interface IEventEmitterEngine : IFactoryEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of event emitted
|
||||
/// </summary>
|
||||
int type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the emitter can be removed with Manager.RemoveEventEmitter(name)
|
||||
/// </summary>
|
||||
bool isRemovable { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The EntityFactory for the entitiesDB.
|
||||
/// Use this to create a ModEventEntityStruct when Emit() is called.
|
||||
/// </summary>
|
||||
IEntityFactory Factory { set; }
|
||||
|
||||
/// <summary>
|
||||
/// Emit the event so IEventHandlerEngines can handle it.
|
||||
/// Call Emit() to trigger the IEventEmitterEngine's event.
|
||||
/// Emit the event. (Optional)
|
||||
/// </summary>
|
||||
void Emit();
|
||||
}
|
||||
|
|
|
@ -7,14 +7,14 @@ using System.Threading.Tasks;
|
|||
using Svelto.ECS;
|
||||
using Svelto.ECS.Internal;
|
||||
|
||||
using GamecraftModdingAPI.Utility;
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
namespace GamecraftModdingAPI.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Engine interface to handle ModEventEntityStruct events emitted by IEventEmitterEngines.
|
||||
/// </summary>
|
||||
public interface IEventHandlerEngine : IApiEngine, IReactOnAddAndRemove<ModEventEntityStruct>, IReactOnAddAndRemove
|
||||
public interface IEventHandlerEngine : IReactionaryEngine<ModEventEntityStruct>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ namespace GamecraftModdingAPI.Events
|
|||
|
||||
public EntitiesDB entitiesDB { set; private get; }
|
||||
|
||||
public bool isRemovable => true;
|
||||
|
||||
public void Add(ref ModEventEntityStruct entityView, EGID egid)
|
||||
{
|
||||
if (entityView.type.Equals(this.type))
|
||||
|
|
|
@ -5,6 +5,7 @@ using RobocraftX.Players;
|
|||
using Svelto.ECS;
|
||||
|
||||
using GamecraftModdingAPI.Utility;
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
namespace GamecraftModdingAPI.Input
|
||||
{
|
||||
|
@ -14,6 +15,8 @@ namespace GamecraftModdingAPI.Input
|
|||
|
||||
public EntitiesDB entitiesDB { set; private get; }
|
||||
|
||||
public bool isRemovable => false;
|
||||
|
||||
public bool IsReady = false;
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -10,6 +10,7 @@ using Svelto.ECS;
|
|||
|
||||
using GamecraftModdingAPI.Blocks;
|
||||
using GamecraftModdingAPI.Utility;
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
namespace GamecraftModdingAPI.Inventory
|
||||
{
|
||||
|
@ -19,6 +20,8 @@ namespace GamecraftModdingAPI.Inventory
|
|||
|
||||
public EntitiesDB entitiesDB { set; private get; }
|
||||
|
||||
public bool isRemovable => false;
|
||||
|
||||
public bool IsInGame = false;
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Reflection;
|
||||
|
||||
using Analytics;
|
||||
using HarmonyLib;
|
||||
using RobocraftX.Common;
|
||||
using Svelto.ECS;
|
||||
|
||||
namespace GamecraftModdingAPI.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Patch of Analytics.AnalyticsCompositionRoot.Compose<T>(...)
|
||||
/// This stops some analytics collection built into Gamecraft.
|
||||
/// DO NOT USE! (This will likely crash your game on shutdown)
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
class AnalyticsDisablerPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// Don't activate gameplay analytics?
|
||||
/// </summary>
|
||||
public static bool DisableAnalytics = false;
|
||||
|
||||
public static bool Prefix(object contextHolder, EnginesRoot enginesRoot, RCXMode rcxMode)
|
||||
{
|
||||
return !DisableAnalytics;
|
||||
}
|
||||
|
||||
public static MethodBase TargetMethod(Harmony instance)
|
||||
{
|
||||
return typeof(Analytics.AnalyticsCompositionRoot).GetMethod("Compose").MakeGenericMethod(typeof(object));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,8 @@ using System.Threading.Tasks;
|
|||
|
||||
using Svelto.ECS;
|
||||
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
namespace GamecraftModdingAPI.Utility
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -24,6 +26,10 @@ namespace GamecraftModdingAPI.Utility
|
|||
{
|
||||
Logging.MetaDebugLog($"Registering Game IApiEngine {engine.Name}");
|
||||
_lastEngineRoot.AddEngine(engine);
|
||||
if (typeof(IFactoryEngine).IsAssignableFrom(engine.GetType()))
|
||||
{
|
||||
((IFactoryEngine)engine).Factory = _lastEngineRoot.GenerateEntityFactory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,17 +54,25 @@ namespace GamecraftModdingAPI.Utility
|
|||
}
|
||||
|
||||
public static void RemoveGameEngine(string name)
|
||||
{
|
||||
if (_gameEngines[name].isRemovable)
|
||||
{
|
||||
_gameEngines.Remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterEngines(EnginesRoot enginesRoot)
|
||||
{
|
||||
_lastEngineRoot = enginesRoot;
|
||||
IEntityFactory factory = enginesRoot.GenerateEntityFactory();
|
||||
foreach (var key in _gameEngines.Keys)
|
||||
{
|
||||
Logging.MetaDebugLog($"Registering Game IApiEngine {_gameEngines[key].Name}");
|
||||
enginesRoot.AddEngine(_gameEngines[key]);
|
||||
if (typeof(IFactoryEngine).IsAssignableFrom(_gameEngines[key].GetType()))
|
||||
{
|
||||
((IFactoryEngine)_gameEngines[key]).Factory = factory;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ using System.Threading.Tasks;
|
|||
|
||||
using RobocraftX.SimulationModeState;
|
||||
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
namespace GamecraftModdingAPI.Utility
|
||||
{
|
||||
class GameStateEngine : IApiEngine
|
||||
|
@ -19,6 +21,8 @@ namespace GamecraftModdingAPI.Utility
|
|||
|
||||
public bool IsInGame { get { return _isInGame; } }
|
||||
|
||||
public bool isRemovable => false;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_isInGame = false;
|
||||
|
|
|
@ -6,6 +6,8 @@ using System.Threading.Tasks;
|
|||
|
||||
using Svelto.ECS;
|
||||
|
||||
using GamecraftModdingAPI.Engines;
|
||||
|
||||
namespace GamecraftModdingAPI.Utility
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -25,6 +27,10 @@ namespace GamecraftModdingAPI.Utility
|
|||
{
|
||||
Logging.MetaDebugLog($"Registering Menu IApiEngine {engine.Name}");
|
||||
_lastEngineRoot.AddEngine(engine);
|
||||
if (typeof(IFactoryEngine).IsAssignableFrom(engine.GetType()))
|
||||
{
|
||||
((IFactoryEngine)engine).Factory = _lastEngineRoot.GenerateEntityFactory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,17 +55,25 @@ namespace GamecraftModdingAPI.Utility
|
|||
}
|
||||
|
||||
public static void RemoveMenuEngine(string name)
|
||||
{
|
||||
if (_menuEngines[name].isRemovable)
|
||||
{
|
||||
_menuEngines.Remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterEngines(EnginesRoot enginesRoot)
|
||||
{
|
||||
_lastEngineRoot = enginesRoot;
|
||||
IEntityFactory factory = enginesRoot.GenerateEntityFactory();
|
||||
foreach (var key in _menuEngines.Keys)
|
||||
{
|
||||
Logging.MetaDebugLog($"Registering Menu IApiEngine {_menuEngines[key].Name}");
|
||||
enginesRoot.AddEngine(_menuEngines[key]);
|
||||
if (typeof(IFactoryEngine).IsAssignableFrom(_menuEngines[key].GetType()))
|
||||
{
|
||||
((IFactoryEngine)_menuEngines[key]).Factory = factory;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using HarmonyLib;
|
||||
using RobocraftX.FrontEnd;
|
||||
|
||||
namespace GamecraftModdingAPI.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Patch of bool RobocraftX.FrontEnd.MinimumSpecsCheck.CheckRequirementsMet()
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(MinimumSpecsCheck), "CheckRequirementsMet")]
|
||||
class MinimumSpecsCheckPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// Ignore result of the requirement check?
|
||||
/// </summary>
|
||||
public static bool ForcePassMinimumSpecCheck = false;
|
||||
|
||||
public static void Postfix(ref bool __result)
|
||||
{
|
||||
__result = __result || ForcePassMinimumSpecCheck;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using HarmonyLib;
|
||||
using RobocraftX.Common;
|
||||
|
||||
namespace GamecraftModdingAPI.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Patch of bool RobocraftX.Common.SteamManager.VerifyOrInit()
|
||||
/// This does not let you run Gamecraft without Steam.
|
||||
/// DO NOT USE!
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(SteamManager), "VerifyOrInit")]
|
||||
class SteamInitPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// Ignore the result of steam initialization?
|
||||
/// </summary>
|
||||
public static bool ForcePassSteamCheck = false;
|
||||
|
||||
public static void Postfix(ref bool __result)
|
||||
{
|
||||
__result = __result || ForcePassSteamCheck;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue