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.

56 lines
1.9KB

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