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.

51 lines
1.7KB

  1. using System;
  2. using Techblox.ObjectIDBlockServer;
  3. namespace TechbloxModdingAPI.Blocks
  4. {
  5. using Svelto.ECS;
  6. public class ObjectID : SignalingBlock
  7. {
  8. /// <summary>
  9. /// Constructs a(n) ObjectID object representing an existing block.
  10. /// </summary>
  11. public ObjectID(EGID egid) :
  12. base(egid)
  13. {
  14. }
  15. /// <summary>
  16. /// Constructs a(n) ObjectID object representing an existing block.
  17. /// </summary>
  18. public ObjectID(uint id) :
  19. base(new EGID(id, ObjectIDBlockExclusiveGroups.OBJECT_ID_BLOCK_GROUP))
  20. {
  21. }
  22. /// <summary>
  23. /// Gets or sets the ObjectID's Identifier property. Tweakable stat.
  24. /// </summary>
  25. public char Identifier
  26. {
  27. get => (char) (BlockEngine.GetBlockInfo<ObjectIDTweakableComponent>(this).objectIDToTrigger + 'A');
  28. set
  29. {
  30. if(value is < 'A' or > 'Z')
  31. throw new ArgumentOutOfRangeException(nameof(value), "ObjectIdentifier must be set to a letter between A and Z.");
  32. BlockEngine.GetBlockInfo<ObjectIDTweakableComponent>(this).objectIDToTrigger = (byte) (value - 'A');
  33. Label = value + ""; //The label isn't updated automatically
  34. }
  35. }
  36. /// <summary>
  37. /// Finds the identifier blocks with the given ID.
  38. /// </summary>
  39. /// <param name="id">The ID to look for</param>
  40. /// <returns>An array that may be empty</returns>
  41. public static ObjectID[] GetByID(char id) => BlockEngine.GetObjectIDsFromID((byte) (id - 'A'));
  42. }
  43. }