|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System.Reflection;
-
- using HarmonyLib;
- using RobocraftX.Blocks;
- using RobocraftX.Common;
- using Svelto.ECS;
-
- using GamecraftModdingAPI.Utility;
- using GamecraftModdingAPI.Engines;
-
- namespace GamecraftModdingAPI.Blocks
- {
- public class RemovalEngine : IApiEngine
- {
- private static IEntityFunctions _entityFunctions;
- private static MachineGraphConnectionEntityFactory _connectionFactory;
-
- public bool RemoveBlock(EGID target)
- {
- if (!entitiesDB.Exists<MachineGraphConnectionsEntityStruct>(target))
- return false;
- var connections = entitiesDB.QueryEntity<MachineGraphConnectionsEntityStruct>(target);
- var groups = entitiesDB.FindGroups<MachineGraphConnectionsEntityStruct>();
- var connStructMapper =
- entitiesDB.QueryNativeMappedEntities<MachineGraphConnectionsEntityStruct>(groups);
- for (int i = connections.connections.Count<MachineConnectionStruct>() - 1; i >= 0; i--)
- _connectionFactory.RemoveConnection(connections, i, connStructMapper);
- _entityFunctions.RemoveEntity<BlockEntityDescriptor>(target);
- return true;
- }
-
- public void Ready()
- {
- }
-
- public EntitiesDB entitiesDB { get; set; }
-
- public void Dispose()
- {
- }
-
- public string Name { get; } = "GamecraftModdingAPIRemovalGameEngine";
-
- public bool isRemovable => false;
-
- [HarmonyPatch]
- public class FactoryObtainerPatch
- {
- static void Postfix(IEntityFunctions entityFunctions,
- MachineGraphConnectionEntityFactory machineGraphConnectionEntityFactory)
- {
- _entityFunctions = entityFunctions;
- _connectionFactory = machineGraphConnectionEntityFactory;
- Logging.MetaDebugLog("Requirements injected.");
- }
-
- static MethodBase TargetMethod(Harmony instance)
- {
- return AccessTools.TypeByName("RobocraftX.CR.MachineEditing.RemoveBlockEngine").GetConstructors()[0];
- }
- }
- }
- }
|