TechbloxModdingAPI/GamecraftModdingAPI/Blocks/ObjectIdentifier.cs

52 lines
1.7 KiB
C#
Raw Normal View History

2020-05-24 17:29:02 +00:00
using Gamecraft.Wires;
using RobocraftX.Common;
2020-05-24 17:29:02 +00:00
using Svelto.ECS;
namespace GamecraftModdingAPI.Blocks
{
public class ObjectIdentifier : Block
{
public ObjectIdentifier(EGID id) : base(id)
{
}
2020-11-09 21:18:25 +00:00
public ObjectIdentifier(uint id) : base(new EGID(id, CommonExclusiveGroups.OBJID_BLOCK_GROUP))
2020-05-24 17:29:02 +00:00
{
}
public char Identifier
{
get => (char) BlockEngine.GetBlockInfo(this, (ObjectIdEntityStruct st) => st.objectId + 'A');
2020-05-24 17:29:02 +00:00
set
{
BlockEngine.SetBlockInfo(this, (ref ObjectIdEntityStruct st, char val) =>
{
st.objectId = (byte) (val - 'A');
Label = val + ""; //The label isn't updated automatically
}, value);
2020-05-24 17:29:02 +00:00
}
}
/// <summary>
/// Simulation-time ID. Assigned by the game starting from 0.
/// </summary>
public byte SimID
{
get => BlockEngine.GetBlockInfo(this, (ObjectIdEntityStruct st) => st.simObjectId);
}
/// <summary>
/// Finds the identifier blocks with the given ID.
2020-05-24 17:29:02 +00:00
/// </summary>
/// <param name="id">The ID to look for</param>
/// <returns>An array that may be empty</returns>
public static ObjectIdentifier[] GetByID(char id) => BlockEngine.GetObjectIDsFromID((byte) (id - 'A'), false);
/// <summary>
/// Finds the identifier blocks with the given simulation-time ID. This ID is assigned by the game starting from 0.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static ObjectIdentifier[] GetBySimID(byte id) => BlockEngine.GetObjectIDsFromID(id, true);
2020-05-24 17:29:02 +00:00
}
}