using System.Collections.Generic; using RobocraftX.Blocks; using RobocraftX.Common; using Svelto.DataStructures; using Svelto.ECS; using GamecraftModdingAPI.Engines; namespace GamecraftModdingAPI.Blocks { public class BlockEngine : IApiEngine { public string Name { get; } = "GamecraftModdingAPIBlockGameEngine"; public EntitiesDB entitiesDB { set; private get; } public bool isRemovable => false; public void Dispose() { } public void Ready() { } public Block[] GetConnectedBlocks(EGID blockID) { if (!BlockExists(blockID)) return new Block[0]; Stack cubeStack = new Stack(); FasterList cubesToProcess = new FasterList(); ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID.entityID, cubeStack, cubesToProcess, (in GridConnectionsEntityStruct g) => { return false; }); var ret = new Block[cubesToProcess.count]; for (int i = 0; i < cubesToProcess.count; i++) ret[i] = new Block(cubesToProcess[i]); return ret; } /// /// Get a struct of a block. Can be used to set properties. /// When only querying parameters, use the other overload for convenience. /// /// /// /// /// public ref T GetBlockInfo(EGID blockID, ref T def) where T : struct, IEntityComponent { if (entitiesDB.Exists(blockID)) return ref entitiesDB.QueryEntity(blockID); return ref def; } /// /// Get a struct of a block. Can only be used to retrieve information. /// Use the overload with a default parameter to get the struct by reference to set values. /// /// The block's EGID /// The struct's type to get /// A copy of the struct or null public T? GetBlockInfo(EGID blockID) where T : struct, IEntityComponent { if (entitiesDB.Exists(blockID)) return entitiesDB.QueryEntity(blockID); return null; } public bool BlockExists(EGID id) { return entitiesDB.Exists(id); } public bool GetBlockInfoExists(EGID blockID) where T : struct, IEntityComponent { return entitiesDB.Exists(blockID); } #if DEBUG public EntitiesDB GetEntitiesDB() { return entitiesDB; } #endif } }