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 | |
| parent | 8e8a58bac339aa06e860b977670f16c8b4eb30a8 (diff) | |
| download | texty-d7eefa488135c477f39ea0953b032c7dcdad8bc7.tar.xz texty-d7eefa488135c477f39ea0953b032c7dcdad8bc7.zip | |
scripts: perform code cleanup actions
| -rw-r--r-- | Scenes/Menus/MainMenu.tscn | 28 | ||||
| -rw-r--r-- | Scripts/Credits.cs | 22 | ||||
| -rw-r--r-- | Scripts/Game/Command.cs | 31 | ||||
| -rw-r--r-- | Scripts/Game/CommandInputArea.cs | 45 | ||||
| -rw-r--r-- | Scripts/Game/CommandParser.cs | 25 | ||||
| -rw-r--r-- | Scripts/Game/Commands/LookCommand.cs | 91 | ||||
| -rw-r--r-- | Scripts/Game/Game.cs | 33 | ||||
| -rw-r--r-- | Scripts/GodotExtensions/ArrayExtensions.cs | 11 | ||||
| -rw-r--r-- | Scripts/GodotExtensions/NodeExtensions.cs | 11 | ||||
| -rw-r--r-- | Scripts/Location.cs | 9 | ||||
| -rw-r--r-- | Scripts/Menus/MainMenu.cs | 39 | ||||
| -rw-r--r-- | Scripts/Menus/MainMenuButtons.cs | 55 | ||||
| -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 | ||||
| -rw-r--r-- | Texty.csproj | 2 | ||||
| -rw-r--r-- | addons/ClassExporter/Plugin.cs | 12 |
20 files changed, 295 insertions, 341 deletions
diff --git a/Scenes/Menus/MainMenu.tscn b/Scenes/Menus/MainMenu.tscn index 8a19ecd..268cf6a 100644 --- a/Scenes/Menus/MainMenu.tscn +++ b/Scenes/Menus/MainMenu.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=4 format=3 uid="uid://bf4ll56nce4ps"] -[ext_resource type="PackedScene" path="res://Scenes/Terminal/MenuScreen.tscn" id="1"] +[ext_resource type="PackedScene" uid="uid://bhu0kaqbhdr74" path="res://Scenes/Terminal/MenuScreen.tscn" id="1"] [ext_resource type="PackedScene" uid="uid://j5l33sidadvf" path="res://Scenes/Menus/MainMenuButtons.tscn" id="2"] [ext_resource type="Script" path="res://Scripts/Menus/MainMenu.cs" id="3"] @@ -8,35 +8,18 @@ script = ExtResource("3") [node name="MenuScreen" parent="." instance=ExtResource("1")] -layout_mode = 3 -anchors_preset = 15 -grow_horizontal = 2 -grow_vertical = 2 Title = "TITLE_MAIN_MENU" -[node name="ScreenContainer" parent="MenuScreen" index="0"] -layout_mode = 1 -anchors_preset = 15 -grow_horizontal = 2 -grow_vertical = 2 - [node name="TopBar" parent="MenuScreen/ScreenContainer" index="0"] -layout_mode = 2 -offset_right = 1152.0 offset_bottom = 25.0 -theme_type_variation = &"InvertedPanelContainer" [node name="TitleArea" parent="MenuScreen/ScreenContainer/TopBar" index="0"] -layout_mode = 2 -offset_right = 1144.0 offset_bottom = 25.0 +grow_horizontal = 1 Title = "[center]TITLE_MAIN_MENU[/center]" [node name="Content" parent="MenuScreen/ScreenContainer" index="1"] -layout_mode = 2 offset_top = 25.0 -offset_right = 1152.0 -offset_bottom = 648.0 [node name="Buttons" parent="MenuScreen/ScreenContainer/Content" index="0" instance=ExtResource("2")] layout_mode = 2 @@ -51,13 +34,6 @@ offset_bottom = 623.0 grow_horizontal = 1 grow_vertical = 1 -[node name="BottomBar" parent="MenuScreen/ScreenContainer" index="2"] -layout_mode = 2 -offset_top = 648.0 -offset_right = 1152.0 -offset_bottom = 648.0 -theme_type_variation = &"InvertedPanelContainer" - [connection signal="CreditsButtonPressed" from="MenuScreen/ScreenContainer/Content/Buttons" to="." method="OnCreditsButtonPressed"] [connection signal="QuitButtonPressed" from="MenuScreen/ScreenContainer/Content/Buttons" to="." method="OnQuitButtonPressed"] [connection signal="StartButtonPressed" from="MenuScreen/ScreenContainer/Content/Buttons" to="." method="OnStartButtonPressed"] diff --git a/Scripts/Credits.cs b/Scripts/Credits.cs index 5432d02..11b7e08 100644 --- a/Scripts/Credits.cs +++ b/Scripts/Credits.cs @@ -1,16 +1,12 @@ using Godot; -namespace Texty.Scripts -{ - public partial class Credits : Node - { - public override void _UnhandledKeyInput(InputEvent @event) - { - if (@event is InputEventKey { Keycode: Key.Escape }) - { - GetTree().ChangeSceneToFile("res://Scenes/Menus/MainMenu.tscn"); - } - } - } -} +namespace Texty.Scripts; +public partial class Credits : Node +{ + public override void _UnhandledKeyInput(InputEvent @event) + { + if (@event is InputEventKey { Keycode: Key.Escape }) + GetTree().ChangeSceneToFile("res://Scenes/Menus/MainMenu.tscn"); + } +}
\ No newline at end of file diff --git a/Scripts/Game/Command.cs b/Scripts/Game/Command.cs index 20b8437..56d80a7 100644 --- a/Scripts/Game/Command.cs +++ b/Scripts/Game/Command.cs @@ -1,25 +1,24 @@ using Godot; -namespace Texty.Scripts.Game +namespace Texty.Scripts.Game; + +public enum CommandType +{ + Look +} + +public partial class Command : Object { - public enum CommandType + public Command() { - Look } - public partial class Command : Object + public Command(CommandType type, string[] arguments) { - public Command() - { - } - - public Command(CommandType type, string[] arguments) - { - RawArguments = arguments; - Type = type; - } - - public string[] RawArguments { get; } - public CommandType Type { get; } + RawArguments = arguments; + Type = type; } + + public string[] RawArguments { get; } + public CommandType Type { get; } }
\ No newline at end of file diff --git a/Scripts/Game/CommandInputArea.cs b/Scripts/Game/CommandInputArea.cs index af54a15..3b88417 100644 --- a/Scripts/Game/CommandInputArea.cs +++ b/Scripts/Game/CommandInputArea.cs @@ -1,32 +1,31 @@ using Godot; using Texty.Scripts.Terminal; -namespace Texty.Scripts.Game +namespace Texty.Scripts.Game; + +[Tool] +public partial class CommandInputArea : InputArea { - [Tool] - public partial class CommandInputArea : InputArea + [Signal] public delegate void CommandSubmittedEventHandler(Command command); + [Signal] public delegate void UnknownInputSubmittedEventHandler(string text); + + private CommandParser CommandParser => GetNodeOrNull<CommandParser>($"%{nameof(CommandParser)}"); + + public override void _Ready() { - [Signal] public delegate void CommandSubmittedEventHandler(Command command); - [Signal] public delegate void UnknownInputSubmittedEventHandler(string text); - - private CommandParser CommandParser => GetNodeOrNull<CommandParser>($"%{nameof(CommandParser)}"); - - public override void _Ready() - { - TextInput.GrabFocus(); - } + TextInput.GrabFocus(); + } - public override void OnTextEntered(string text) - { - if (text.Length == 0) - return; + public override void OnTextEntered(string text) + { + if (text.Length == 0) + return; - TextInput.Clear(); - var command = CommandParser.TryParse(text); - if (command != null) - EmitSignal(SignalName.CommandSubmitted, command); - else - EmitSignal(SignalName.UnknownInputSubmitted, text); - } + TextInput.Clear(); + var command = CommandParser.TryParse(text); + if (command != null) + EmitSignal(SignalName.CommandSubmitted, command); + else + EmitSignal(SignalName.UnknownInputSubmitted, text); } }
\ No newline at end of file diff --git a/Scripts/Game/CommandParser.cs b/Scripts/Game/CommandParser.cs index 9b02ee5..6c29545 100644 --- a/Scripts/Game/CommandParser.cs +++ b/Scripts/Game/CommandParser.cs @@ -2,22 +2,21 @@ using System.Linq; using Godot; using Texty.Scripts.Commands; -namespace Texty.Scripts.Game +namespace Texty.Scripts.Game; + +public partial class CommandParser : Node { - public partial class CommandParser : Node + public override void _Ready() { - public override void _Ready() - { - } + } - public Command TryParse(string text) + public Command TryParse(string text) + { + var components = text.Split(' '); + return components[0].ToLower() switch { - var components = text.Split(' '); - return components[0].ToLower() switch - { - "look" => new LookCommand(components.Skip(1).ToArray()), - _ => null - }; - } + "look" => new LookCommand(components.Skip(1).ToArray()), + _ => null + }; } }
\ No newline at end of file diff --git a/Scripts/Game/Commands/LookCommand.cs b/Scripts/Game/Commands/LookCommand.cs index 22ba77e..c66fa43 100644 --- a/Scripts/Game/Commands/LookCommand.cs +++ b/Scripts/Game/Commands/LookCommand.cs @@ -1,58 +1,57 @@ using System.Linq; using Texty.Scripts.Game; -namespace Texty.Scripts.Commands +namespace Texty.Scripts.Commands; + +public enum LookModifier +{ + At, + Around +} + +public partial class LookCommand : Command { - public enum LookModifier + public LookCommand() { - At, - Around } - public partial class LookCommand : Command + public LookCommand(string[] arguments) : base(CommandType.Look, arguments) { - public LookCommand() - { - } + (Modifier, arguments) = TryParseModifier(arguments); + Target = string.Join(" ", arguments); + } - public LookCommand(string[] arguments) : base(CommandType.Look, arguments) - { - (Modifier, arguments) = TryParseModifier(arguments); - Target = string.Join(" ", arguments); - } - - public string Target { get; } - public LookModifier? Modifier { get; } - - /// <summary> - /// Access this <c>LookCommand</c>'s modifier as a string. - /// </summary> - /// <remarks> - /// This function is provided as a means for testing the modifier parsing from GDScript. - /// </remarks> - private string ModifierAsString => Modifier?.ToString(); - - public override string ToString() - { - return $"look {ModifierAsString?.ToLower()} {string.Join(" ", Target)}"; - } - - /// <summary> - /// Try to parse this <c>LookCommand</c>'s modifier from the given arguments. - /// </summary> - /// <param name="arguments">The arguments given to this look commands</param> - /// <returns>A pair consisting of the parse modifier and the remaining arguments</returns> - private static (LookModifier?, string[]) TryParseModifier(string[] arguments) + public string Target { get; } + public LookModifier? Modifier { get; } + + /// <summary> + /// Access this <c>LookCommand</c>'s modifier as a string. + /// </summary> + /// <remarks> + /// This function is provided as a means for testing the modifier parsing from GDScript. + /// </remarks> + private string ModifierAsString => Modifier?.ToString(); + + public override string ToString() + { + return $"look {ModifierAsString?.ToLower()} {string.Join(" ", Target)}"; + } + + /// <summary> + /// Try to parse this <c>LookCommand</c>'s modifier from the given arguments. + /// </summary> + /// <param name="arguments">The arguments given to this look commands</param> + /// <returns>A pair consisting of the parse modifier and the remaining arguments</returns> + private static (LookModifier?, string[]) TryParseModifier(string[] arguments) + { + if (arguments.Length == 0) + return (null, arguments); + + return arguments[0].ToLower() switch { - if (arguments.Length == 0) - return (null, arguments); - - return arguments[0].ToLower() switch - { - "at" => (LookModifier.At, arguments.Skip(1).ToArray()), - "around" => (LookModifier.Around, new string[] { }), - _ => (null, arguments) - }; - } + "at" => (LookModifier.At, arguments.Skip(1).ToArray()), + "around" => (LookModifier.Around, new string[] { }), + _ => (null, arguments) + }; } }
\ No newline at end of file diff --git a/Scripts/Game/Game.cs b/Scripts/Game/Game.cs index 07d42b2..e6d4c6a 100644 --- a/Scripts/Game/Game.cs +++ b/Scripts/Game/Game.cs @@ -1,26 +1,25 @@ using Godot; using Texty.Scripts.Terminal; -namespace Texty.Scripts.Game +namespace Texty.Scripts.Game; + +public partial class Game : Node { - public partial class Game : Node - { - private InputArea InputArea => GetNodeOrNull<InputArea>($"%{nameof(InputArea)}"); - private OutputArea OutputArea => GetNodeOrNull<OutputArea>($"%{nameof(OutputArea)}"); - private StatusArea StatusArea => GetNodeOrNull<StatusArea>($"%{nameof(StatusArea)}"); + private InputArea InputArea => GetNodeOrNull<InputArea>($"%{nameof(InputArea)}"); + private OutputArea OutputArea => GetNodeOrNull<OutputArea>($"%{nameof(OutputArea)}"); + private StatusArea StatusArea => GetNodeOrNull<StatusArea>($"%{nameof(StatusArea)}"); - public override void _Ready() - { - } + public override void _Ready() + { + } - public void OnCommandSubmitted(Command command) - { - OutputArea.Push($"! {command}"); - } + public void OnCommandSubmitted(Command command) + { + OutputArea.Push($"! {command}"); + } - public void OnUnknownInputSubmitted(string text) - { - OutputArea.Push($"? {text}"); - } + public void OnUnknownInputSubmitted(string text) + { + OutputArea.Push($"? {text}"); } }
\ No newline at end of file diff --git a/Scripts/GodotExtensions/ArrayExtensions.cs b/Scripts/GodotExtensions/ArrayExtensions.cs index 2712232..ad72f94 100644 --- a/Scripts/GodotExtensions/ArrayExtensions.cs +++ b/Scripts/GodotExtensions/ArrayExtensions.cs @@ -2,13 +2,12 @@ using System; using Godot; using Godot.Collections; -namespace Texty.Scripts.GodotExtensions +namespace Texty.Scripts.GodotExtensions; + +public static class ArrayExtensions { - public static class ArrayExtensions + public static void ForEach<[MustBeVariant] T>(this Array<T> array, Action<T> action) { - public static void ForEach<[MustBeVariant] T>(this Array<T> array, Action<T> action) - { - foreach (var element in array) action.Invoke(element); - } + foreach (var element in array) action.Invoke(element); } }
\ No newline at end of file diff --git a/Scripts/GodotExtensions/NodeExtensions.cs b/Scripts/GodotExtensions/NodeExtensions.cs index c361496..0acc012 100644 --- a/Scripts/GodotExtensions/NodeExtensions.cs +++ b/Scripts/GodotExtensions/NodeExtensions.cs @@ -2,13 +2,12 @@ using System.Linq; using Godot; using Godot.Collections; -namespace Texty.Scripts.GodotExtensions +namespace Texty.Scripts.GodotExtensions; + +public static class NodeExtensions { - public static class NodeExtensions + public static Array<T> GetChildren<[MustBeVariant] T>(this Node node) { - public static Array<T> GetChildren<[MustBeVariant] T>(this Node node) - { - return new Array<T>(node.GetChildren().OfType<T>()); - } + return new Array<T>(node.GetChildren().OfType<T>()); } }
\ No newline at end of file diff --git a/Scripts/Location.cs b/Scripts/Location.cs index aaca980..8cebcf1 100644 --- a/Scripts/Location.cs +++ b/Scripts/Location.cs @@ -1,9 +1,8 @@ using Godot; -namespace Texty.Scripts +namespace Texty.Scripts; + +public partial class Location : Resource { - public partial class Location : Resource - { - [Export(PropertyHint.MultilineText)] public string FlavourText = string.Empty; - } + [Export(PropertyHint.MultilineText)] public string FlavourText = string.Empty; }
\ No newline at end of file diff --git a/Scripts/Menus/MainMenu.cs b/Scripts/Menus/MainMenu.cs index 2991fec..5a7c3dd 100644 --- a/Scripts/Menus/MainMenu.cs +++ b/Scripts/Menus/MainMenu.cs @@ -1,26 +1,25 @@ using Godot; -namespace Texty.Scripts.Menus +namespace Texty.Scripts.Menus; + +public partial class MainMenu : Node { - public partial class MainMenu : Node - { - public override void _Ready() - { - } + public override void _Ready() + { + } - private void OnStartButtonPressed() - { - GetTree().ChangeSceneToFile("res://Scenes/Game/Game.tscn"); - } + private void OnStartButtonPressed() + { + GetTree().ChangeSceneToFile("res://Scenes/Game/Game.tscn"); + } - private void OnCreditsButtonPressed() - { - GetTree().ChangeSceneToFile("res://Scenes/Credits.tscn"); - } + private void OnCreditsButtonPressed() + { + GetTree().ChangeSceneToFile("res://Scenes/Credits.tscn"); + } - private void OnQuitButtonPressed() - { - GetTree().Quit(); - } - } -} + private void OnQuitButtonPressed() + { + GetTree().Quit(); + } +}
\ No newline at end of file diff --git a/Scripts/Menus/MainMenuButtons.cs b/Scripts/Menus/MainMenuButtons.cs index 64e8914..e343135 100644 --- a/Scripts/Menus/MainMenuButtons.cs +++ b/Scripts/Menus/MainMenuButtons.cs @@ -2,38 +2,37 @@ using System; using Godot; using Texty.Scripts.Terminal; -namespace Texty.Scripts.Menus +namespace Texty.Scripts.Menus; + +public partial class MainMenuButtons : ButtonBlock { - public partial class MainMenuButtons : ButtonBlock - { - [Signal] public delegate void CreditsButtonPressedEventHandler(); - [Signal] public delegate void QuitButtonPressedEventHandler(); - [Signal] public delegate void StartButtonPressedEventHandler(); + [Signal] public delegate void CreditsButtonPressedEventHandler(); + [Signal] public delegate void QuitButtonPressedEventHandler(); + [Signal] public delegate void StartButtonPressedEventHandler(); - protected override void OnButtonPressed(int index) + protected override void OnButtonPressed(int index) + { + if (!Enum.IsDefined(typeof(Buttons), 1)) return; + switch ((Buttons)index) { - if (!Enum.IsDefined(typeof(Buttons), 1)) return; - switch ((Buttons)index) - { - case Buttons.Start: - EmitSignal(SignalName.StartButtonPressed); - break; - case Buttons.Credits: - EmitSignal(SignalName.CreditsButtonPressed); - break; - case Buttons.Quit: - EmitSignal(SignalName.QuitButtonPressed); - break; - default: - throw new ArgumentOutOfRangeException(nameof(index), index, "Button not implemented!"); - } + case Buttons.Start: + EmitSignal(SignalName.StartButtonPressed); + break; + case Buttons.Credits: + EmitSignal(SignalName.CreditsButtonPressed); + break; + case Buttons.Quit: + EmitSignal(SignalName.QuitButtonPressed); + break; + default: + throw new ArgumentOutOfRangeException(nameof(index), index, "Button not implemented!"); } + } - private enum Buttons - { - Start = 0, - Credits = 1, - Quit = 2 - } + private enum Buttons + { + Start = 0, + Credits = 1, + Quit = 2 } }
\ No newline at end of file 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 diff --git a/Texty.csproj b/Texty.csproj index fadc26c..4c516b5 100644 --- a/Texty.csproj +++ b/Texty.csproj @@ -1,4 +1,4 @@ -<Project Sdk="Godot.NET.Sdk/4.0.0-beta2"> +<Project Sdk="Godot.NET.Sdk/4.0.0-beta.6"> <PropertyGroup> <TargetFramework>net6.0</TargetFramework> <EnableDynamicLoading>true</EnableDynamicLoading> diff --git a/addons/ClassExporter/Plugin.cs b/addons/ClassExporter/Plugin.cs index 475b003..3d08112 100644 --- a/addons/ClassExporter/Plugin.cs +++ b/addons/ClassExporter/Plugin.cs @@ -13,13 +13,13 @@ namespace Texty.addons.ClassExporter { private const string LoadTypesMenuItem = "Load types"; private const string ReloadTypesMenuItem = "Reload types"; - private readonly List<TypeEntry> _registeredTypes = new List<TypeEntry>(); + private readonly List<TypeEntry> _registeredTypes = new(); public override void _EnterTree() { - Connect("resource_saved", new Callable(this,nameof(OnResourceSaved))); - AddToolMenuItem(LoadTypesMenuItem, new Callable(() => OnReloadTypes(false))); - AddToolMenuItem(ReloadTypesMenuItem, new Callable(() => OnReloadTypes(true))); + Connect("resource_saved", new Callable(this, nameof(OnResourceSaved))); + AddToolMenuItem(LoadTypesMenuItem, Callable.From(() => OnReloadTypes(false))); + AddToolMenuItem(ReloadTypesMenuItem, Callable.From(() => OnReloadTypes(true))); RegisterTypes(); } @@ -27,7 +27,7 @@ namespace Texty.addons.ClassExporter { RegisterTypes(); } - + public override void _DisablePlugin() { DeRegisterTypes(); @@ -38,7 +38,7 @@ namespace Texty.addons.ClassExporter DeRegisterTypes(); RemoveToolMenuItem(LoadTypesMenuItem); RemoveToolMenuItem(ReloadTypesMenuItem); - Disconnect("resource_saved",new Callable(this,nameof(OnResourceSaved))); + Disconnect("resource_saved", new Callable(this, nameof(OnResourceSaved))); } // Required by Godot |
