TechbloxModdingAPI/GamecraftModdingAPI/Events/GameStateSimulationEmitterEngine.cs

54 lines
1.4 KiB
C#
Raw Normal View History

using System;
using Unity.Jobs;
2020-04-07 17:05:00 +00:00
using RobocraftX.SimulationModeState;
using RobocraftX.StateSync;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Event emitter engine for switching to simulation mode.
/// </summary>
2020-05-14 15:42:34 +00:00
public class GameStateSimulationEmitterEngine : IEventEmitterEngine, IUnorderedInitializeOnTimeRunningModeEntered
{
public string Name { get; } = "GamecraftModdingAPIGameStateSimulationEventEmitter" ;
public EntitiesDB entitiesDB { set; private get; }
public int type { get; } = (int)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 });
}
2020-04-07 17:05:00 +00:00
public void EmitIfSimMode()
{
2020-05-14 15:42:34 +00:00
if (entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP).nextSimulationMode == SimulationMode.TimeRunning)
2020-04-07 17:05:00 +00:00
{
Emit();
}
}
2020-05-14 15:42:34 +00:00
public JobHandle OnInitializeTimeRunningMode()
{
Emit();
return default(JobHandle);
}
public void Ready() { }
}
}