diff options
| author | Sophia Pearson <codergal89@gmail.com> | 2022-11-26 10:08:44 +0100 |
|---|---|---|
| committer | Sophia Pearson <codergal89@gmail.com> | 2022-11-26 10:08:44 +0100 |
| commit | d7eefa488135c477f39ea0953b032c7dcdad8bc7 (patch) | |
| tree | d9725b73b342ff3d9df4d800616dd010b48c7222 /Scripts/Terminal | |
| parent | 8e8a58bac339aa06e860b977670f16c8b4eb30a8 (diff) | |
| download | texty-d7eefa488135c477f39ea0953b032c7dcdad8bc7.tar.xz texty-d7eefa488135c477f39ea0953b032c7dcdad8bc7.zip | |
scripts: perform code cleanup actions
Diffstat (limited to 'Scripts/Terminal')
| -rw-r--r-- | Scripts/Terminal/ButtonBlock.cs | 35 | ||||
| -rw-r--r-- | Scripts/Terminal/InputArea.cs | 18 | ||||
| -rw-r--r-- | Scripts/Terminal/MenuScreen.cs | 35 | ||||
| -rw-r--r-- | Scripts/Terminal/OutputArea.cs | 60 | ||||
| -rw-r--r-- | Scripts/Terminal/OutputBlock.cs | 37 | ||||
| -rw-r--r-- | Scripts/Terminal/StatusArea.cs | 37 |
6 files changed, 107 insertions, 115 deletions
diff --git a/Scripts/Terminal/ButtonBlock.cs b/Scripts/Terminal/ButtonBlock.cs index ef25f8c..ff0e83e 100644 --- a/Scripts/Terminal/ButtonBlock.cs +++ b/Scripts/Terminal/ButtonBlock.cs @@ -2,27 +2,26 @@ using System.Linq; using Godot; using Texty.Scripts.GodotExtensions; -namespace Texty.Scripts.Terminal +namespace Texty.Scripts.Terminal; + +public partial class ButtonBlock : MarginContainer { - public partial class ButtonBlock : MarginContainer - { - private VBoxContainer Buttons => GetNodeOrNull<VBoxContainer>($"%{nameof(Buttons)}"); + private VBoxContainer Buttons => GetNodeOrNull<VBoxContainer>($"%{nameof(Buttons)}"); - public override void _Ready() - { - ConnectButtons(); - Buttons.GetChildren<Button>().ForEach(button => button.MouseFilter = MouseFilterEnum.Ignore); - Buttons.GetChildren<Button>().FirstOrDefault()?.GrabFocus(); - } + public override void _Ready() + { + ConnectButtons(); + Buttons.GetChildren<Button>().ForEach(button => button.MouseFilter = MouseFilterEnum.Ignore); + Buttons.GetChildren<Button>().FirstOrDefault()?.GrabFocus(); + } - protected virtual void OnButtonPressed(int index) - { - } + protected virtual void OnButtonPressed(int index) + { + } - private void ConnectButtons() - { - foreach (var (button, index) in Buttons.GetChildren<Button>().Select((button, index) => (button, index))) - button.Pressed += () => OnButtonPressed(index); - } + private void ConnectButtons() + { + foreach (var (button, index) in Buttons.GetChildren<Button>().Select((button, index) => (button, index))) + button.Pressed += () => OnButtonPressed(index); } }
\ No newline at end of file diff --git a/Scripts/Terminal/InputArea.cs b/Scripts/Terminal/InputArea.cs index a32ad2c..04c0887 100644 --- a/Scripts/Terminal/InputArea.cs +++ b/Scripts/Terminal/InputArea.cs @@ -1,17 +1,15 @@ using Godot; -namespace Texty.Scripts.Terminal +namespace Texty.Scripts.Terminal; + +public partial class InputArea : HBoxContainer { - public partial class InputArea : HBoxContainer - { - protected Label PromptLabel => GetNodeOrNull<Label>($"%{nameof(PromptLabel)}"); - protected LineEdit TextInput => GetNodeOrNull<LineEdit>($"%{nameof(TextInput)}"); + protected Label PromptLabel => GetNodeOrNull<Label>($"%{nameof(PromptLabel)}"); + protected LineEdit TextInput => GetNodeOrNull<LineEdit>($"%{nameof(TextInput)}"); - public new bool HasFocus => TextInput?.HasFocus() ?? false; + public new bool HasFocus => TextInput?.HasFocus() ?? false; - public virtual void OnTextEntered(string text) - { - - } + public virtual void OnTextEntered(string text) + { } }
\ No newline at end of file diff --git a/Scripts/Terminal/MenuScreen.cs b/Scripts/Terminal/MenuScreen.cs index 1259b31..ee6e765 100644 --- a/Scripts/Terminal/MenuScreen.cs +++ b/Scripts/Terminal/MenuScreen.cs @@ -1,27 +1,26 @@ using Godot; -namespace Texty.Scripts.Terminal +namespace Texty.Scripts.Terminal; + +[Tool] +public partial class MenuScreen : Control { - [Tool] - public partial class MenuScreen : Control - { - private string _title = ""; - private StatusArea TitleArea => GetNodeOrNull<StatusArea>($"%{nameof(TitleArea)}"); + private string _title = ""; + private StatusArea TitleArea => GetNodeOrNull<StatusArea>($"%{nameof(TitleArea)}"); - [Export] - public string Title + [Export] + public string Title + { + get => _title; + set { - get => _title; - set - { - _title = value; - if (TitleArea != null) TitleArea.Title = $"[center]{GodotSharp.Singleton.Tr(_title)}[/center]"; - } + _title = value; + if (TitleArea != null) TitleArea.Title = $"[center]{GodotSharp.Singleton.Tr(_title)}[/center]"; } + } - public override void _Ready() - { - Title = _title; - } + public override void _Ready() + { + Title = _title; } }
\ No newline at end of file diff --git a/Scripts/Terminal/OutputArea.cs b/Scripts/Terminal/OutputArea.cs index e297c49..e5f7535 100644 --- a/Scripts/Terminal/OutputArea.cs +++ b/Scripts/Terminal/OutputArea.cs @@ -3,44 +3,42 @@ using System.Diagnostics; using System.Linq; using Godot; using Godot.Collections; -using Texty.Scripts.Game; -namespace Texty.Scripts.Terminal +namespace Texty.Scripts.Terminal; + +public partial class OutputArea : ScrollContainer { - public partial class OutputArea : ScrollContainer - { - [Export(PropertyHint.File, "*.tscn")] public PackedScene OutputBlockScene; - public Array<string> TextBlocks => new Array<string>(BlockNodes.ToList().Select(block => block.Content)); + [Export(PropertyHint.File, "*.tscn")] public PackedScene OutputBlockScene; + public Array<string> TextBlocks => new(BlockNodes.ToList().Select(block => block.Content)); - private VBoxContainer LineContainer => GetNodeOrNull<VBoxContainer>($"%{nameof(LineContainer)}"); + private VBoxContainer LineContainer => GetNodeOrNull<VBoxContainer>($"%{nameof(LineContainer)}"); - private IEnumerable<OutputBlock> BlockNodes => - GD.Range(LineContainer?.GetChildCount() ?? 0) - .Select(index => LineContainer.GetChild(index)) - .Cast<OutputBlock>(); + 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.CanInstantiate(), "OutputBlockScene can not be instanced!"); - Clear(); - } + public override void _Ready() + { + Debug.Assert(OutputBlockScene != null, "OutputBlockScene has not been configured!"); + Debug.Assert(OutputBlockScene.CanInstantiate(), "OutputBlockScene can not be instanced!"); + Clear(); + } - public void Clear() + public void Clear() + { + BlockNodes.ToList().ForEach(block => { - BlockNodes.ToList().ForEach(block => - { - LineContainer.RemoveChild(block); - block.QueueFree(); - }); - } + LineContainer.RemoveChild(block); + block.QueueFree(); + }); + } - public void Push(string text) - { - if (string.IsNullOrEmpty(text)) return; - var block = OutputBlockScene.Instantiate<OutputBlock>(); - block.Content = text; - LineContainer.AddChild(block); - } + public void Push(string text) + { + if (string.IsNullOrEmpty(text)) return; + var block = OutputBlockScene.Instantiate<OutputBlock>(); + block.Content = text; + LineContainer.AddChild(block); } }
\ No newline at end of file diff --git a/Scripts/Terminal/OutputBlock.cs b/Scripts/Terminal/OutputBlock.cs index 4512446..3f50f44 100644 --- a/Scripts/Terminal/OutputBlock.cs +++ b/Scripts/Terminal/OutputBlock.cs @@ -1,29 +1,28 @@ using Godot; -namespace Texty.Scripts.Terminal +namespace Texty.Scripts.Terminal; + +[Tool] +public partial class OutputBlock : MarginContainer { - [Tool] - public partial class OutputBlock : MarginContainer - { - private string _content = ""; + private string _content = ""; - private RichTextLabel ContentLabel => GetNodeOrNull<RichTextLabel>($"%{nameof(ContentLabel)}"); + private RichTextLabel ContentLabel => GetNodeOrNull<RichTextLabel>($"%{nameof(ContentLabel)}"); - [Export(PropertyHint.MultilineText)] - public string Content + [Export(PropertyHint.MultilineText)] + public string Content + { + get => ContentLabel?.Text ?? ""; + set { - get => ContentLabel?.Text ?? ""; - set - { - _content = value; - if (ContentLabel != null) - ContentLabel.Text = GodotSharp.Singleton.Tr(_content); - } + _content = value; + if (ContentLabel != null) + ContentLabel.Text = GodotSharp.Singleton.Tr(_content); } + } - public override void _Ready() - { - Content = _content; - } + public override void _Ready() + { + Content = _content; } }
\ No newline at end of file diff --git a/Scripts/Terminal/StatusArea.cs b/Scripts/Terminal/StatusArea.cs index 3099168..8357735 100644 --- a/Scripts/Terminal/StatusArea.cs +++ b/Scripts/Terminal/StatusArea.cs @@ -1,28 +1,27 @@ using Godot; -namespace Texty.Scripts.Terminal +namespace Texty.Scripts.Terminal; + +[Tool] +public partial class StatusArea : HBoxContainer { - [Tool] - public partial class StatusArea : HBoxContainer - { - private string _titleText = ""; - private RichTextLabel TitleLabel => GetNodeOrNull<RichTextLabel>($"%{nameof(TitleLabel)}"); + private string _titleText = ""; + private RichTextLabel TitleLabel => GetNodeOrNull<RichTextLabel>($"%{nameof(TitleLabel)}"); - [Export] - public string Title + [Export] + public string Title + { + get => _titleText; + set { - get => _titleText; - set - { - _titleText = value; - if (TitleLabel != null) - TitleLabel.Text = GodotSharp.Singleton.Tr(value); - } + _titleText = value; + if (TitleLabel != null) + TitleLabel.Text = GodotSharp.Singleton.Tr(value); } + } - public override void _Ready() - { - Title = _titleText; - } + public override void _Ready() + { + Title = _titleText; } }
\ No newline at end of file |
