Add Simulation and Build switch to events
This commit is contained in:
parent
7519bc37ae
commit
7ac5120ef5
6 changed files with 137 additions and 1 deletions
|
@ -0,0 +1,40 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Harmony;
|
||||||
|
using Svelto.ECS;
|
||||||
|
using RobocraftX.StateSync;
|
||||||
|
|
||||||
|
using GamecraftModdingAPI.Utility;
|
||||||
|
|
||||||
|
namespace GamecraftModdingAPI.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Patch of RobocraftX.StateSync.DeterministicStepCompositionRoot.ComposeEnginesGroups(...)
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(DeterministicStepCompositionRoot), "ComposeEnginesGroups")]
|
||||||
|
//[HarmonyPatch]
|
||||||
|
class DeterministicStepComposeEngineGroupsPatch
|
||||||
|
{
|
||||||
|
|
||||||
|
public static readonly GameStateBuildEmitterEngine buildEngine = new GameStateBuildEmitterEngine();
|
||||||
|
|
||||||
|
public static readonly GameStateSimulationEmitterEngine simEngine = new GameStateSimulationEmitterEngine();
|
||||||
|
|
||||||
|
public static void Prefix(ref StateSyncRegistrationHelper stateSyncReg)
|
||||||
|
{
|
||||||
|
stateSyncReg.buildModeInitializationEngines.Add(buildEngine);
|
||||||
|
stateSyncReg.simulationModeInitializationEngines.Add(simEngine);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MethodBase NopeTargetMethod()
|
||||||
|
{
|
||||||
|
return typeof(DeterministicStepCompositionRoot).GetMethods().First(m => m.Name == "ComposeEnginesGroups")
|
||||||
|
.MakeGenericMethod(typeof(object));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,8 @@ namespace GamecraftModdingAPI.Events
|
||||||
MenuSwitchedTo,
|
MenuSwitchedTo,
|
||||||
Game,
|
Game,
|
||||||
GameReloaded,
|
GameReloaded,
|
||||||
GameSwitchedTo
|
GameSwitchedTo,
|
||||||
|
SimulationSwitchedTo,
|
||||||
|
BuildSwitchedTo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
44
GamecraftModdingAPI/Events/GameStateBuildEmitterEngine.cs
Normal file
44
GamecraftModdingAPI/Events/GameStateBuildEmitterEngine.cs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
using Unity.Jobs;
|
||||||
|
using RobocraftX.StateSync;
|
||||||
|
using Svelto.ECS;
|
||||||
|
|
||||||
|
using GamecraftModdingAPI.Utility;
|
||||||
|
|
||||||
|
namespace GamecraftModdingAPI.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Event emitter engine for switching to to build mode.
|
||||||
|
/// </summary>
|
||||||
|
public class GameStateBuildEmitterEngine : IEventEmitterEngine, IInitializeOnBuildStart
|
||||||
|
{
|
||||||
|
public string Name { get; } = "GamecraftModdingAPIGameStateBuildEventEmitter" ;
|
||||||
|
|
||||||
|
public IEntitiesDB entitiesDB { set; private get; }
|
||||||
|
|
||||||
|
public object type { get; } = EventType.BuildSwitchedTo;
|
||||||
|
|
||||||
|
public bool isRemovable { get; } = false;
|
||||||
|
|
||||||
|
public IEntityFactory Factory { set; private get; }
|
||||||
|
|
||||||
|
public void Dispose() { }
|
||||||
|
|
||||||
|
public void Emit()
|
||||||
|
{
|
||||||
|
Logging.Log("Dispatching Build Switched To event");
|
||||||
|
if (Factory == null) { return; }
|
||||||
|
Factory.BuildEntity<ModEventEntityDescriptor>(ApiExclusiveGroups.eventID++, ApiExclusiveGroups.eventsExclusiveGroup)
|
||||||
|
.Init(new ModEventEntityStruct { type = type });
|
||||||
|
}
|
||||||
|
|
||||||
|
public JobHandle OnInitializeBuildMode()
|
||||||
|
{
|
||||||
|
Emit();
|
||||||
|
return default(JobHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Ready() { }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
using Unity.Jobs;
|
||||||
|
using RobocraftX.StateSync;
|
||||||
|
using Svelto.ECS;
|
||||||
|
|
||||||
|
using GamecraftModdingAPI.Utility;
|
||||||
|
|
||||||
|
namespace GamecraftModdingAPI.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Event emitter engine for switching to simulation mode.
|
||||||
|
/// </summary>
|
||||||
|
public class GameStateSimulationEmitterEngine : IEventEmitterEngine, IInitializeOnSimulationStart
|
||||||
|
{
|
||||||
|
public string Name { get; } = "GamecraftModdingAPIGameStateSimulationEventEmitter" ;
|
||||||
|
|
||||||
|
public IEntitiesDB entitiesDB { set; private get; }
|
||||||
|
|
||||||
|
public object type { get; } = EventType.SimulationSwitchedTo;
|
||||||
|
|
||||||
|
public bool isRemovable { get; } = false;
|
||||||
|
|
||||||
|
public IEntityFactory Factory { set; private get; }
|
||||||
|
|
||||||
|
public void Dispose() { }
|
||||||
|
|
||||||
|
public void Emit()
|
||||||
|
{
|
||||||
|
Logging.Log("Dispatching Simulation Switched To event");
|
||||||
|
if (Factory == null) { return; }
|
||||||
|
Factory.BuildEntity<ModEventEntityDescriptor>(ApiExclusiveGroups.eventID++, ApiExclusiveGroups.eventsExclusiveGroup)
|
||||||
|
.Init(new ModEventEntityStruct { type = type });
|
||||||
|
}
|
||||||
|
|
||||||
|
public JobHandle OnInitializeSimulationMode()
|
||||||
|
{
|
||||||
|
Emit();
|
||||||
|
return default(JobHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Ready() { }
|
||||||
|
}
|
||||||
|
}
|
|
@ -56,6 +56,8 @@ namespace GamecraftModdingAPI
|
||||||
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.Game, "GamecraftModdingAPIGameActivatedEventEmitter", false));
|
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.Game, "GamecraftModdingAPIGameActivatedEventEmitter", false));
|
||||||
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.GameReloaded, "GamecraftModdingAPIGameReloadedEventEmitter", false));
|
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.GameReloaded, "GamecraftModdingAPIGameReloadedEventEmitter", false));
|
||||||
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.GameSwitchedTo, "GamecraftModdingAPIGameSwitchedToEventEmitter", false));
|
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.GameSwitchedTo, "GamecraftModdingAPIGameSwitchedToEventEmitter", false));
|
||||||
|
EventManager.AddEventEmitter(DeterministicStepComposeEngineGroupsPatch.buildEngine);
|
||||||
|
EventManager.AddEventEmitter(DeterministicStepComposeEngineGroupsPatch.simEngine);
|
||||||
// init block implementors
|
// init block implementors
|
||||||
Logging.MetaDebugLog($"Initializing Blocks");
|
Logging.MetaDebugLog($"Initializing Blocks");
|
||||||
Blocks.Movement.Init();
|
Blocks.Movement.Init();
|
||||||
|
|
|
@ -68,6 +68,10 @@ namespace GamecraftModdingAPI.Tests
|
||||||
EventType.GameReloaded, "gamerel API debug"));
|
EventType.GameReloaded, "gamerel API debug"));
|
||||||
EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Switched To event!"); }, () => { },
|
EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Switched To event!"); }, () => { },
|
||||||
EventType.GameSwitchedTo, "gameswitch API debug"));
|
EventType.GameSwitchedTo, "gameswitch API debug"));
|
||||||
|
EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Mode Simulation Switched To event!"); }, () => { },
|
||||||
|
EventType.SimulationSwitchedTo, "simulationswitch API debug"));
|
||||||
|
EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Mode Build Switched To event!"); }, () => { },
|
||||||
|
EventType.BuildSwitchedTo, "buildswitch API debug"));
|
||||||
|
|
||||||
// debug/test commands
|
// debug/test commands
|
||||||
if (Dependency.Hell("ExtraCommands"))
|
if (Dependency.Hell("ExtraCommands"))
|
||||||
|
|
Loading…
Reference in a new issue