|
- using HarmonyLib;
- using Svelto.DataStructures;
- using Svelto.ECS;
-
- namespace CLre.API.Engines
- {
- /// <summary>
- /// Engine to be registered before vanilla engines are built.
- /// This should be called by any other constructor because this alerts CLre of its existence.
- /// </summary>
- public abstract class FrontEndEnginePreBuild : ICLreEngine
- {
- /// <summary>
- /// Construct a new instance of a FrontEndEngine.
- /// This should be called by any other constructor because this alerts CLre of its existence.
- /// </summary>
- public FrontEndEnginePreBuild()
- {
- MainFrontEnd_BuildEngines_Patch.beforeBuildEngines.Add(this);
- }
-
- public abstract void Ready();
- public abstract IEntitiesDB entitiesDB { get; set; }
- public abstract IEntityFactory entityFactory { get; set; }
- }
-
- /// <summary>
- /// Engine to be registered before obsolete vanilla engines are built.
- /// This should be called by any other constructor because this alerts CLre of its existence.
- /// </summary>
- public abstract class FrontEndObsoleteEnginePreBuild : ICLreEngine
- {
- /// <summary>
- /// Construct a new instance of a FrontEndEngine.
- /// This should be called by any other constructor because this alerts CLre of its existence.
- /// </summary>
- public FrontEndObsoleteEnginePreBuild()
- {
- MainFrontEnd_BuildObsoleteEngines_Patch.beforeBuildEngines.Add(this);
- }
-
- public abstract void Ready();
- public abstract IEntitiesDB entitiesDB { get; set; }
- public abstract IEntityFactory entityFactory { get; set; }
- }
-
- /// <summary>
- /// Engine to be registered after vanilla engines are built.
- /// </summary>
- public abstract class FrontEndEnginePostBuild : ICLreEngine
- {
- /// <summary>
- /// Construct a new instance of a FrontEndEngine.
- /// This should be called by any other constructor because this alerts CLre of its existence.
- /// </summary>
- public FrontEndEnginePostBuild()
- {
- MainFrontEnd_BuildEngines_Patch.afterBuildEngines.Add(this);
- }
-
- public abstract void Ready();
- public abstract IEntitiesDB entitiesDB { get; set; }
- public abstract IEntityFactory entityFactory { get; set; }
- }
-
- /// <summary>
- /// Engine to be registered after vanilla obsolete engines are built.
- /// </summary>
- public abstract class FrontEndObsoleteEnginePostBuild : ICLreEngine
- {
- /// <summary>
- /// Construct a new instance of a FrontEndEngine.
- /// This should be called by any other constructor because this alerts CLre of its existence.
- /// </summary>
- public FrontEndObsoleteEnginePostBuild()
- {
- MainFrontEnd_BuildObsoleteEngines_Patch.afterBuildEngines.Add(this);
- }
-
- public abstract void Ready();
- public abstract IEntitiesDB entitiesDB { get; set; }
- public abstract IEntityFactory entityFactory { get; set; }
- }
-
- [HarmonyPatch(typeof(FrontEnd.MainFrontEnd), "BuildEngines")]
- class MainFrontEnd_BuildEngines_Patch
- {
- internal static FasterList<FrontEndEnginePreBuild> beforeBuildEngines = new FasterList<FrontEndEnginePreBuild>();
-
- internal static FasterList<FrontEndEnginePostBuild> afterBuildEngines = new FasterList<FrontEndEnginePostBuild>();
-
- [HarmonyPrefix]
- public static void BeforeMethodCall(FrontEnd.MainFrontEnd __instance)
- {
- IEntityFactory factory = AccessTools.Field(typeof(FrontEnd.MainFrontEnd), "_entityFactory").GetValue(__instance) as IEntityFactory;
- foreach (ICLreEngine e in beforeBuildEngines)
- {
- e.entityFactory = factory;
- __instance.AddEngine(e);
- }
- }
-
- [HarmonyPostfix]
- public static void AfterMethodCall(FrontEnd.MainFrontEnd __instance)
- {
- IEntityFactory factory = AccessTools.Field(typeof(FrontEnd.MainFrontEnd), "_entityFactory").GetValue(__instance) as IEntityFactory;
- foreach (ICLreEngine e in afterBuildEngines)
- {
- e.entityFactory = factory;
- __instance.AddEngine(e);
- }
- }
- }
-
- [HarmonyPatch(typeof(FrontEnd.MainFrontEnd), "BuildObsoleteEngines")]
- class MainFrontEnd_BuildObsoleteEngines_Patch
- {
- internal static FasterList<FrontEndObsoleteEnginePreBuild> beforeBuildEngines = new FasterList<FrontEndObsoleteEnginePreBuild>();
-
- internal static FasterList<FrontEndObsoleteEnginePostBuild> afterBuildEngines = new FasterList<FrontEndObsoleteEnginePostBuild>();
-
- [HarmonyPrefix]
- public static void BeforeMethodCall(FrontEnd.MainFrontEnd __instance)
- {
- IEntityFactory factory = AccessTools.Field(typeof(FrontEnd.MainFrontEnd), "_entityFactory").GetValue(__instance) as IEntityFactory;
- foreach (ICLreEngine e in beforeBuildEngines)
- {
- e.entityFactory = factory;
- __instance.AddEngine(e);
- }
- }
-
- [HarmonyPostfix]
- public static void AfterMethodCall(FrontEnd.MainFrontEnd __instance)
- {
- IEntityFactory factory = AccessTools.Field(typeof(FrontEnd.MainFrontEnd), "_entityFactory").GetValue(__instance) as IEntityFactory;
- foreach (ICLreEngine e in afterBuildEngines)
- {
- e.entityFactory = factory;
- __instance.AddEngine(e);
- }
- }
- }
- }
|