A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ObjectIdentifier.cs 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Gamecraft.Wires;
  2. using RobocraftX.Common;
  3. using Svelto.ECS;
  4. namespace GamecraftModdingAPI.Blocks
  5. {
  6. public class ObjectIdentifier : Block
  7. {
  8. public ObjectIdentifier(EGID id) : base(id)
  9. {
  10. if (!BlockEngine.GetBlockInfoExists<ObjectIdEntityStruct>(Id))
  11. {
  12. throw new BlockTypeException($"Block is not a {GetType().Name} block");
  13. }
  14. }
  15. public ObjectIdentifier(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP))
  16. {
  17. if (!BlockEngine.GetBlockInfoExists<ObjectIdEntityStruct>(Id))
  18. {
  19. throw new BlockTypeException($"Block is not a {GetType().Name} block");
  20. }
  21. }
  22. public char Identifier
  23. {
  24. get => (char) (BlockEngine.GetBlockInfo<ObjectIdEntityStruct>(Id).objectId + 'A');
  25. set
  26. {
  27. BlockEngine.GetBlockInfo<ObjectIdEntityStruct>(Id).objectId = (byte) (value - 'A');
  28. Label = value + ""; //The label isn't updated automatically
  29. }
  30. }
  31. /// <summary>
  32. /// Simulation-time ID. Assigned by the game starting from 0.
  33. /// </summary>
  34. public byte SimID
  35. {
  36. get => BlockEngine.GetBlockInfo<ObjectIdEntityStruct>(Id).simObjectId;
  37. }
  38. /// <summary>
  39. /// Finds the identifier blocks with the given ID.
  40. /// </summary>
  41. /// <param name="id">The ID to look for</param>
  42. /// <returns>An array that may be empty</returns>
  43. public static ObjectIdentifier[] GetByID(char id) => BlockEngine.GetObjectIDsFromID((byte) (id - 'A'), false);
  44. /// <summary>
  45. /// Finds the identifier blocks with the given simulation-time ID. This ID is assigned by the game starting from 0.
  46. /// </summary>
  47. /// <param name="id"></param>
  48. /// <returns></returns>
  49. public static ObjectIdentifier[] GetBySimID(byte id) => BlockEngine.GetObjectIDsFromID(id, true);
  50. }
  51. }