2020-04-12 23:31:06 +00:00
|
|
|
using System.Reflection;
|
|
|
|
|
2020-05-03 19:31:09 +00:00
|
|
|
using HarmonyLib;
|
2020-04-12 23:31:06 +00:00
|
|
|
using RobocraftX.Blocks;
|
|
|
|
using RobocraftX.Common;
|
|
|
|
using Svelto.ECS;
|
|
|
|
|
|
|
|
using GamecraftModdingAPI.Utility;
|
2020-05-12 00:28:26 +00:00
|
|
|
using GamecraftModdingAPI.Engines;
|
2020-04-12 23:31:06 +00:00
|
|
|
|
|
|
|
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);
|
2020-10-28 23:37:47 +00:00
|
|
|
var groups = entitiesDB.FindGroups<MachineGraphConnectionsEntityStruct>();
|
|
|
|
var connStructMapper =
|
|
|
|
entitiesDB.QueryNativeMappedEntities<MachineGraphConnectionsEntityStruct>(groups);
|
2020-06-12 15:27:36 +00:00
|
|
|
for (int i = connections.connections.Count<MachineConnectionStruct>() - 1; i >= 0; i--)
|
2020-10-28 23:37:47 +00:00
|
|
|
_connectionFactory.RemoveConnection(connections, i, connStructMapper);
|
2020-04-12 23:31:06 +00:00
|
|
|
_entityFunctions.RemoveEntity<BlockEntityDescriptor>(target);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Ready()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntitiesDB entitiesDB { get; set; }
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Name { get; } = "GamecraftModdingAPIRemovalGameEngine";
|
|
|
|
|
2020-05-12 00:28:26 +00:00
|
|
|
public bool isRemovable => false;
|
|
|
|
|
|
|
|
[HarmonyPatch]
|
2020-04-12 23:31:06 +00:00
|
|
|
public class FactoryObtainerPatch
|
|
|
|
{
|
|
|
|
static void Postfix(IEntityFunctions entityFunctions,
|
|
|
|
MachineGraphConnectionEntityFactory machineGraphConnectionEntityFactory)
|
|
|
|
{
|
|
|
|
_entityFunctions = entityFunctions;
|
|
|
|
_connectionFactory = machineGraphConnectionEntityFactory;
|
|
|
|
Logging.MetaDebugLog("Requirements injected.");
|
|
|
|
}
|
|
|
|
|
2020-05-03 19:31:09 +00:00
|
|
|
static MethodBase TargetMethod(Harmony instance)
|
2020-04-12 23:31:06 +00:00
|
|
|
{
|
|
|
|
return AccessTools.TypeByName("RobocraftX.CR.MachineEditing.RemoveBlockEngine").GetConstructors()[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|