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.

91 lines
2.4KB

  1. using System;
  2. using Gamecraft.Blocks.GUI;
  3. using Svelto.ECS;
  4. using Unity.Mathematics;
  5. using GamecraftModdingAPI;
  6. using GamecraftModdingAPI.Utility;
  7. namespace GamecraftModdingAPI.Blocks
  8. {
  9. public class TextBlock : Block
  10. {
  11. public static TextBlock PlaceNew(float3 position,
  12. float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
  13. int uscale = 1, float3 scale = default, Player player = null)
  14. {
  15. if (PlacementEngine.IsInGame && GameState.IsBuildMode())
  16. {
  17. try
  18. {
  19. EGID id = PlacementEngine.PlaceBlock(BlockIDs.TextBlock, color, darkness,
  20. position, uscale, scale, player, rotation);
  21. return new TextBlock(id);
  22. }
  23. catch (Exception e)
  24. {
  25. Logging.MetaDebugLog(e);
  26. }
  27. }
  28. return null;
  29. }
  30. public TextBlock(EGID id) : base(id)
  31. {
  32. if (!BlockEngine.GetBlockInfoExists<TextBlockDataStruct>(this.Id))
  33. {
  34. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  35. }
  36. }
  37. public TextBlock(uint id) : base(id)
  38. {
  39. if (!BlockEngine.GetBlockInfoExists<TextBlockDataStruct>(this.Id))
  40. {
  41. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  42. }
  43. }
  44. // custom text block properties
  45. /// <summary>
  46. /// The text block's current text.
  47. /// </summary>
  48. public string Text
  49. {
  50. get
  51. {
  52. return BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textCurrent;
  53. }
  54. set
  55. {
  56. ref TextBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id);
  57. tbds.textCurrent.Set(value);
  58. tbds.textStored.Set(value);
  59. BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id).newTextBlockStringContent.Set(value);
  60. }
  61. }
  62. /// <summary>
  63. /// The text block's current text block ID (used in ChangeTextBlockCommand).
  64. /// </summary>
  65. public string TextBlockId
  66. {
  67. get
  68. {
  69. return BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textBlockID;
  70. }
  71. set
  72. {
  73. BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textBlockID.Set(value);
  74. BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id).newTextBlockID.Set(value);
  75. }
  76. }
  77. }
  78. }