2020-05-13 12:02:36 +00:00
|
|
|
using System.Collections.Generic;
|
2020-05-13 14:52:21 +00:00
|
|
|
|
2020-05-13 12:02:36 +00:00
|
|
|
using RobocraftX.Blocks;
|
|
|
|
using RobocraftX.Common;
|
|
|
|
using Svelto.DataStructures;
|
|
|
|
using Svelto.ECS;
|
2020-05-13 14:52:21 +00:00
|
|
|
|
|
|
|
using GamecraftModdingAPI.Engines;
|
2020-05-13 12:02:36 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-17 18:13:45 +00:00
|
|
|
public Block[] GetConnectedBlocks(EGID blockID)
|
2020-05-13 12:02:36 +00:00
|
|
|
{
|
2020-05-17 18:13:45 +00:00
|
|
|
if (!BlockExists(blockID)) return new Block[0];
|
2020-05-13 12:02:36 +00:00
|
|
|
Stack<uint> cubeStack = new Stack<uint>();
|
|
|
|
FasterList<uint> cubesToProcess = new FasterList<uint>();
|
2020-05-17 18:13:45 +00:00
|
|
|
ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID.entityID, cubeStack, cubesToProcess, (in GridConnectionsEntityStruct g) => { return false; });
|
2020-05-13 12:02:36 +00:00
|
|
|
var ret = new Block[cubesToProcess.count];
|
|
|
|
for (int i = 0; i < cubesToProcess.count; i++)
|
|
|
|
ret[i] = new Block(cubesToProcess[i]);
|
|
|
|
return ret;
|
|
|
|
}
|
2020-05-13 14:52:21 +00:00
|
|
|
|
2020-05-17 18:13:45 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Get a struct of a block. Can be used to set properties.
|
|
|
|
/// When only querying parameters, use the other overload for convenience.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="blockID"></param>
|
|
|
|
/// <param name="def"></param>
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
/// <returns></returns>
|
|
|
|
public ref T GetBlockInfo<T>(EGID blockID, ref T def) where T : struct, IEntityComponent
|
2020-05-13 14:52:21 +00:00
|
|
|
{
|
2020-05-17 18:13:45 +00:00
|
|
|
if (entitiesDB.Exists<T>(blockID))
|
|
|
|
return ref entitiesDB.QueryEntity<T>(blockID);
|
|
|
|
return ref def;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 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.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="blockID">The block's EGID</param>
|
|
|
|
/// <typeparam name="T">The struct's type to get</typeparam>
|
|
|
|
/// <returns>A copy of the struct or null</returns>
|
|
|
|
public T? GetBlockInfo<T>(EGID blockID) where T : struct, IEntityComponent
|
|
|
|
{
|
|
|
|
if (entitiesDB.Exists<T>(blockID))
|
|
|
|
return entitiesDB.QueryEntity<T>(blockID);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool BlockExists(EGID id)
|
|
|
|
{
|
|
|
|
return entitiesDB.Exists<DBEntityStruct>(id);
|
2020-05-13 14:52:21 +00:00
|
|
|
}
|
2020-05-13 12:02:36 +00:00
|
|
|
}
|
|
|
|
}
|