TechbloxModdingAPI/GamecraftModdingAPI/Blocks/TextBlock.cs
NorbiPeti 3592c6f464 Add support for initializing blocks with properties
Newly created blocks use the initializer to set properties, allowing the user to set per-block properties
2020-07-15 21:58:24 +02:00

60 lines
1.6 KiB
C#

using System;
using Gamecraft.Blocks.GUI;
using RobocraftX.Common;
using Svelto.ECS;
using Unity.Mathematics;
using GamecraftModdingAPI;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
public class TextBlock : Block
{
public TextBlock(EGID id) : base(id)
{
}
public TextBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_TEXT_BLOCK_GROUP))
{
}
// custom text block properties
/// <summary>
/// The text block's current text.
/// </summary>
public string Text
{
get => BlockEngine.GetBlockInfo(this, (TextBlockDataStruct st) => st.textCurrent);
set
{
BlockEngine.SetBlockInfo(this, (ref TextBlockDataStruct tbds, string val) =>
{
tbds.textCurrent.Set(val);
tbds.textStored.Set(val);
}, value);
BlockEngine.SetBlockInfo(this,
(ref TextBlockNetworkDataStruct st, string val) => st.newTextBlockStringContent.Set(val), value);
}
}
/// <summary>
/// The text block's current text block ID (used in ChangeTextBlockCommand).
/// </summary>
public string TextBlockId
{
get => BlockEngine.GetBlockInfo(this, (TextBlockDataStruct st) => st.textBlockID);
set
{
BlockEngine.SetBlockInfo(this, (ref TextBlockDataStruct tbds, string val) =>
tbds.textBlockID.Set(val), value);
BlockEngine.SetBlockInfo(this,
(ref TextBlockNetworkDataStruct st, string val) => st.newTextBlockID.Set(val), value);
}
}
}
}