Browse Source

Rework engine inheritance structure

tags/v1.0.0
NGnius (Graham) 4 years ago
parent
commit
42b21bc16d
25 changed files with 140 additions and 136 deletions
  1. +5
    -2
      GamecraftModdingAPI/Blocks/MovementEngine.cs
  2. +4
    -1
      GamecraftModdingAPI/Blocks/PlacementEngine.cs
  3. +4
    -1
      GamecraftModdingAPI/Blocks/RemovalEngine.cs
  4. +4
    -1
      GamecraftModdingAPI/Blocks/RotationEngine.cs
  5. +4
    -1
      GamecraftModdingAPI/Blocks/SignalEngine.cs
  6. +5
    -1
      GamecraftModdingAPI/Blocks/TweakableEngine.cs
  7. +1
    -0
      GamecraftModdingAPI/Commands/ICustomCommandEngine.cs
  8. +3
    -1
      GamecraftModdingAPI/Commands/SimpleCustomCommandEngine.cs
  9. +3
    -1
      GamecraftModdingAPI/Commands/SimpleCustomCommandEngine1.cs
  10. +3
    -1
      GamecraftModdingAPI/Commands/SimpleCustomCommandEngine2.cs
  11. +3
    -1
      GamecraftModdingAPI/Commands/SimpleCustomCommandEngine3.cs
  12. +6
    -1
      GamecraftModdingAPI/Engines/IApiEngine.cs
  13. +24
    -0
      GamecraftModdingAPI/Engines/IFactoryEngine.cs
  14. +20
    -0
      GamecraftModdingAPI/Engines/IReactionaryEngine.cs
  15. +5
    -22
      GamecraftModdingAPI/Events/IEventEmitterEngine.cs
  16. +2
    -2
      GamecraftModdingAPI/Events/IEventHandlerEngine.cs
  17. +3
    -1
      GamecraftModdingAPI/Events/SimpleEventHandlerEngine.cs
  18. +3
    -0
      GamecraftModdingAPI/Input/FakeInputEngine.cs
  19. +3
    -0
      GamecraftModdingAPI/Inventory/HotbarEngine.cs
  20. +0
    -38
      GamecraftModdingAPI/Utility/AnalyticsDisablerPatch.cs
  21. +15
    -1
      GamecraftModdingAPI/Utility/GameEngineManager.cs
  22. +5
    -1
      GamecraftModdingAPI/Utility/GameStateEngine.cs
  23. +15
    -1
      GamecraftModdingAPI/Utility/MenuEngineManager.cs
  24. +0
    -28
      GamecraftModdingAPI/Utility/MinimumSpecsCheckPatch.cs
  25. +0
    -30
      GamecraftModdingAPI/Utility/SteamInitPatch.cs

+ 5
- 2
GamecraftModdingAPI/Blocks/MovementEngine.cs View File

@@ -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,7 +34,9 @@ namespace GamecraftModdingAPI.Blocks

public EntitiesDB entitiesDB { set; private get; }

public bool IsInGame = false;
public bool isRemovable => false;

public bool IsInGame = false;

public void Dispose()
{


+ 4
- 1
GamecraftModdingAPI/Blocks/PlacementEngine.cs View File

@@ -21,6 +21,7 @@ using UnityEngine;
using uREPL;

using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;

namespace GamecraftModdingAPI.Blocks
{
@@ -128,7 +129,9 @@ namespace GamecraftModdingAPI.Blocks

public string Name { get; } = "GamecraftModdingAPIPlacementGameEngine";

[HarmonyPatch]
public bool isRemovable => false;

[HarmonyPatch]
public class FactoryObtainerPatch
{
static void Postfix(BlockEntityFactory blockEntityFactory)


+ 4
- 1
GamecraftModdingAPI/Blocks/RemovalEngine.cs View File

@@ -12,6 +12,7 @@ using uREPL;

using GamecraftModdingAPI.Commands;
using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;

namespace GamecraftModdingAPI.Blocks
{
@@ -54,7 +55,9 @@ namespace GamecraftModdingAPI.Blocks

public string Name { get; } = "GamecraftModdingAPIRemovalGameEngine";

[HarmonyPatch]
public bool isRemovable => false;

[HarmonyPatch]
public class FactoryObtainerPatch
{
static void Postfix(IEntityFunctions entityFunctions,


+ 4
- 1
GamecraftModdingAPI/Blocks/RotationEngine.cs View File

@@ -20,6 +20,7 @@ using Unity.Mathematics;
using UnityEngine;

using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;

namespace GamecraftModdingAPI.Blocks
{
@@ -32,7 +33,9 @@ namespace GamecraftModdingAPI.Blocks

public EntitiesDB entitiesDB { set; private get; }

public bool IsInGame = false;
public bool isRemovable => false;

public bool IsInGame = false;

public void Dispose()
{


+ 4
- 1
GamecraftModdingAPI/Blocks/SignalEngine.cs View File

@@ -22,6 +22,7 @@ using UnityEngine;
using Gamecraft.Wires;

using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;

namespace GamecraftModdingAPI.Blocks
{
@@ -33,8 +34,10 @@ namespace GamecraftModdingAPI.Blocks
public string Name { get; } = "GamecraftModdingAPISignalGameEngine";

public EntitiesDB entitiesDB { set; private get; }
public bool isRemovable => false;

public bool IsInGame = false;
public bool IsInGame = false;

public void Dispose()
{


+ 5
- 1
GamecraftModdingAPI/Blocks/TweakableEngine.cs View File

@@ -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()


+ 1
- 0
GamecraftModdingAPI/Commands/ICustomCommandEngine.cs View File

@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Svelto.ECS;

using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;

namespace GamecraftModdingAPI.Commands
{


+ 3
- 1
GamecraftModdingAPI/Commands/SimpleCustomCommandEngine.cs View File

@@ -31,7 +31,9 @@ namespace GamecraftModdingAPI.Commands

public EntitiesDB entitiesDB { set; private get; }

public void Dispose()
public bool isRemovable => true;

public void Dispose()
{
GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Unregistering SimpleCustomCommandEngine {this.Name}");
CommandRegistrationHelper.Unregister(this.Name);


+ 3
- 1
GamecraftModdingAPI/Commands/SimpleCustomCommandEngine1.cs View File

@@ -22,7 +22,9 @@ namespace GamecraftModdingAPI.Commands

public EntitiesDB entitiesDB { set; private get; }

public void Dispose()
public bool isRemovable => true;

public void Dispose()
{
GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Unregistering SimpleCustomCommandEngine {this.Name}");
CommandRegistrationHelper.Unregister(this.Name);


+ 3
- 1
GamecraftModdingAPI/Commands/SimpleCustomCommandEngine2.cs View File

@@ -22,7 +22,9 @@ namespace GamecraftModdingAPI.Commands

public EntitiesDB entitiesDB { set; private get; }

public void Dispose()
public bool isRemovable => true;

public void Dispose()
{
GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Unregistering SimpleCustomCommandEngine {this.Name}");
CommandRegistrationHelper.Unregister(this.Name);


+ 3
- 1
GamecraftModdingAPI/Commands/SimpleCustomCommandEngine3.cs View File

@@ -22,7 +22,9 @@ namespace GamecraftModdingAPI.Commands

public EntitiesDB entitiesDB { set; private get; }

public void Dispose()
public bool isRemovable => true;

public void Dispose()
{
GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Unregistering SimpleCustomCommandEngine {this.Name}");
CommandRegistrationHelper.Unregister(this.Name);


GamecraftModdingAPI/Utility/IApiEngine.cs → GamecraftModdingAPI/Engines/IApiEngine.cs View File

@@ -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
- 0
GamecraftModdingAPI/Engines/IFactoryEngine.cs View 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
- 0
GamecraftModdingAPI/Engines/IReactionaryEngine.cs View 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
{
}
}

+ 5
- 22
GamecraftModdingAPI/Events/IEventEmitterEngine.cs View File

@@ -6,35 +6,18 @@ 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
/// Emit the event. (Optional)
/// </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.
/// </summary>
void Emit();
void Emit();
}
}

+ 2
- 2
GamecraftModdingAPI/Events/IEventHandlerEngine.cs View File

@@ -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>
{
}
}

+ 3
- 1
GamecraftModdingAPI/Events/SimpleEventHandlerEngine.cs View File

@@ -24,7 +24,9 @@ namespace GamecraftModdingAPI.Events

public EntitiesDB entitiesDB { set; private get; }

public void Add(ref ModEventEntityStruct entityView, EGID egid)
public bool isRemovable => true;

public void Add(ref ModEventEntityStruct entityView, EGID egid)
{
if (entityView.type.Equals(this.type))
{


+ 3
- 0
GamecraftModdingAPI/Input/FakeInputEngine.cs View File

@@ -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()


+ 3
- 0
GamecraftModdingAPI/Inventory/HotbarEngine.cs View File

@@ -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()


+ 0
- 38
GamecraftModdingAPI/Utility/AnalyticsDisablerPatch.cs View File

@@ -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));
}
}
}

+ 15
- 1
GamecraftModdingAPI/Utility/GameEngineManager.cs View File

@@ -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();
}
}
}

@@ -49,16 +55,24 @@ namespace GamecraftModdingAPI.Utility

public static void RemoveGameEngine(string name)
{
_gameEngines.Remove(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;
}
}
}
}


+ 5
- 1
GamecraftModdingAPI/Utility/GameStateEngine.cs View File

@@ -7,6 +7,8 @@ using System.Threading.Tasks;

using RobocraftX.SimulationModeState;

using GamecraftModdingAPI.Engines;

namespace GamecraftModdingAPI.Utility
{
class GameStateEngine : IApiEngine
@@ -19,7 +21,9 @@ namespace GamecraftModdingAPI.Utility

public bool IsInGame { get { return _isInGame; } }

public void Dispose()
public bool isRemovable => false;

public void Dispose()
{
_isInGame = false;
}


+ 15
- 1
GamecraftModdingAPI/Utility/MenuEngineManager.cs View File

@@ -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();
}
}
}

@@ -50,16 +56,24 @@ namespace GamecraftModdingAPI.Utility

public static void RemoveMenuEngine(string name)
{
_menuEngines.Remove(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;
}
}
}
}


+ 0
- 28
GamecraftModdingAPI/Utility/MinimumSpecsCheckPatch.cs View File

@@ -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;
}
}
}

+ 0
- 30
GamecraftModdingAPI/Utility/SteamInitPatch.cs View File

@@ -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…
Cancel
Save