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.

93 lines
2.5KB

  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. Sync();
  22. return new TextBlock(id);
  23. }
  24. catch (Exception e)
  25. {
  26. Logging.MetaDebugLog(e);
  27. }
  28. }
  29. return null;
  30. }
  31. public TextBlock(EGID id) : base(id)
  32. {
  33. if (!BlockEngine.GetBlockInfoExists<TextBlockDataStruct>(this.Id))
  34. {
  35. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  36. }
  37. }
  38. public TextBlock(uint id) : base(id)
  39. {
  40. if (!BlockEngine.GetBlockInfoExists<TextBlockDataStruct>(this.Id))
  41. {
  42. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  43. }
  44. }
  45. // custom text block properties
  46. /// <summary>
  47. /// The text block's current text.
  48. /// </summary>
  49. public string Text
  50. {
  51. get
  52. {
  53. return BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id)?.textCurrent ?? null;
  54. }
  55. set
  56. {
  57. TextBlockDataStruct def = default;
  58. ref TextBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id, ref def);
  59. tbds.textCurrent.Set(value);
  60. tbds.textStored.Set(value);
  61. BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id)?.newTextBlockStringContent.Set(value);
  62. }
  63. }
  64. /// <summary>
  65. /// The text block's current text block ID (used in ChangeTextBlockCommand).
  66. /// </summary>
  67. public string TextBlockId
  68. {
  69. get
  70. {
  71. return BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id)?.textBlockID ?? null;
  72. }
  73. set
  74. {
  75. BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id)?.textBlockID.Set(value);
  76. BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id)?.newTextBlockID.Set(value);
  77. }
  78. }
  79. }
  80. }