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.

84 lines
2.2KB

  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. EGID id = PlacementEngine.PlaceBlock(BlockIDs.TextBlock, color, darkness,
  18. position, uscale, scale, player, rotation);
  19. return new TextBlock(id);
  20. }
  21. return null;
  22. }
  23. public TextBlock(EGID id) : base(id)
  24. {
  25. if (!BlockEngine.GetBlockInfoExists<TextBlockDataStruct>(this.Id))
  26. {
  27. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  28. }
  29. }
  30. public TextBlock(uint 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. // custom text block properties
  38. /// <summary>
  39. /// The text block's current text.
  40. /// </summary>
  41. public string Text
  42. {
  43. get
  44. {
  45. return BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textCurrent;
  46. }
  47. set
  48. {
  49. ref TextBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id);
  50. tbds.textCurrent.Set(value);
  51. tbds.textStored.Set(value);
  52. BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id).newTextBlockStringContent.Set(value);
  53. }
  54. }
  55. /// <summary>
  56. /// The text block's current text block ID (used in ChangeTextBlockCommand).
  57. /// </summary>
  58. public string TextBlockId
  59. {
  60. get
  61. {
  62. return BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textBlockID;
  63. }
  64. set
  65. {
  66. BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textBlockID.Set(value);
  67. BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id).newTextBlockID.Set(value);
  68. }
  69. }
  70. }
  71. }