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.

92 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. 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;
  54. }
  55. set
  56. {
  57. ref TextBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id);
  58. tbds.textCurrent.Set(value);
  59. tbds.textStored.Set(value);
  60. BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id).newTextBlockStringContent.Set(value);
  61. }
  62. }
  63. /// <summary>
  64. /// The text block's current text block ID (used in ChangeTextBlockCommand).
  65. /// </summary>
  66. public string TextBlockId
  67. {
  68. get
  69. {
  70. return BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textBlockID;
  71. }
  72. set
  73. {
  74. BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textBlockID.Set(value);
  75. BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id).newTextBlockID.Set(value);
  76. }
  77. }
  78. }
  79. }