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.

70 lines
1.8KB

  1. using System;
  2. using Gamecraft.Blocks.GUI;
  3. using RobocraftX.Common;
  4. using Svelto.ECS;
  5. using Unity.Mathematics;
  6. using GamecraftModdingAPI;
  7. using GamecraftModdingAPI.Utility;
  8. namespace GamecraftModdingAPI.Blocks
  9. {
  10. public class TextBlock : Block
  11. {
  12. public TextBlock(EGID id) : base(id)
  13. {
  14. if (!BlockEngine.GetBlockInfoExists<TextBlockDataStruct>(this.Id))
  15. {
  16. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  17. }
  18. }
  19. public TextBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_TEXT_BLOCK_GROUP))
  20. {
  21. if (!BlockEngine.GetBlockInfoExists<TextBlockDataStruct>(this.Id))
  22. {
  23. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  24. }
  25. }
  26. // custom text block properties
  27. /// <summary>
  28. /// The text block's current text.
  29. /// </summary>
  30. public string Text
  31. {
  32. get
  33. {
  34. return BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textCurrent;
  35. }
  36. set
  37. {
  38. ref TextBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id);
  39. tbds.textCurrent.Set(value);
  40. tbds.textStored.Set(value);
  41. BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id).newTextBlockStringContent.Set(value);
  42. }
  43. }
  44. /// <summary>
  45. /// The text block's current text block ID (used in ChangeTextBlockCommand).
  46. /// </summary>
  47. public string TextBlockId
  48. {
  49. get
  50. {
  51. return BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textBlockID;
  52. }
  53. set
  54. {
  55. BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textBlockID.Set(value);
  56. BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id).newTextBlockID.Set(value);
  57. }
  58. }
  59. }
  60. }