diff options
| author | Sophia Pearson <codergal89@gmail.com> | 2022-09-04 15:43:12 +0200 |
|---|---|---|
| committer | Sophia Pearson <codergal89@gmail.com> | 2022-09-04 15:44:04 +0200 |
| commit | 2f3abbb6f1141f15ef77ac27e431bc66bb0c7899 (patch) | |
| tree | 17f7ee50161e1de1c11c6dd14a54a11614e7de03 /Scripts/Game/Output.cs | |
| parent | 0967a4654c9fa67b5cfc19edf3cfc075bf6bde92 (diff) | |
| download | texty-2f3abbb6f1141f15ef77ac27e431bc66bb0c7899.tar.xz texty-2f3abbb6f1141f15ef77ac27e431bc66bb0c7899.zip | |
game: adapt scripts to new design
Diffstat (limited to 'Scripts/Game/Output.cs')
| -rw-r--r-- | Scripts/Game/Output.cs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Scripts/Game/Output.cs b/Scripts/Game/Output.cs new file mode 100644 index 0000000..be943f7 --- /dev/null +++ b/Scripts/Game/Output.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Godot; +using Godot.Collections; + +namespace Texty.Scripts.Game +{ + public class Output : PanelContainer + { + [Export(PropertyHint.File, "*.tscn")] public PackedScene OutputBlockScene; + public Array<string> TextBlocks => new Array<string>(BlockNodes.ToList().Select(block => block.Content)); + + private VBoxContainer LineContainer => GetNodeOrNull<VBoxContainer>($"%{nameof(LineContainer)}"); + + private IEnumerable<OutputBlock> BlockNodes => + GD.Range(LineContainer?.GetChildCount() ?? 0) + .Select(index => LineContainer.GetChild(index)) + .Cast<OutputBlock>(); + + public override void _Ready() + { + Debug.Assert(OutputBlockScene != null, "OutputBlockScene has not been configured!"); + Debug.Assert(OutputBlockScene.CanInstance(), "OutputBlockScene can not be instanced!"); + } + + public void Clear() + { + BlockNodes.ToList().ForEach(block => + { + LineContainer.RemoveChild(block); + block.QueueFree(); + }); + } + + public void Push(string text) + { + var block = OutputBlockScene.Instance<OutputBlock>(); + block.Content = text; + LineContainer.AddChild(block); + } + } +}
\ No newline at end of file |
