using System; using Gamecraft.Blocks.GUI; using Svelto.ECS; using Unity.Mathematics; using GamecraftModdingAPI; using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Blocks { public class TextBlock : Block { public static TextBlock PlaceNew(float3 position, float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0, int uscale = 1, float3 scale = default, Player player = null) { if (PlacementEngine.IsInGame && GameState.IsBuildMode()) { EGID id = PlacementEngine.PlaceBlock(BlockIDs.TextBlock, color, darkness, position, uscale, scale, player, rotation); return new TextBlock(id); } return null; } public TextBlock(EGID id) : base(id) { if (!BlockEngine.GetBlockInfoExists(this.Id)) { throw new BlockTypeException($"Block is not a {this.GetType().Name} block"); } } public TextBlock(uint id) : base(id) { if (!BlockEngine.GetBlockInfoExists(this.Id)) { throw new BlockTypeException($"Block is not a {this.GetType().Name} block"); } } // custom text block properties /// /// The text block's current text. /// public string Text { get { return BlockEngine.GetBlockInfo(Id).textCurrent; } set { ref TextBlockDataStruct tbds = ref BlockEngine.GetBlockInfo(Id); tbds.textCurrent.Set(value); tbds.textStored.Set(value); BlockEngine.GetBlockInfo(Id).newTextBlockStringContent.Set(value); } } /// /// The text block's current text block ID (used in ChangeTextBlockCommand). /// public string TextBlockId { get { return BlockEngine.GetBlockInfo(Id).textBlockID; } set { BlockEngine.GetBlockInfo(Id).textBlockID.Set(value); BlockEngine.GetBlockInfo(Id).newTextBlockID.Set(value); } } } }