summaryrefslogtreecommitdiff
path: root/Scripts
diff options
context:
space:
mode:
authorSophia Pearson <codergal89@gmail.com>2022-10-03 22:22:50 +0200
committerSophia Pearson <codergal89@gmail.com>2022-10-04 22:18:18 +0200
commite127ad39e742396030352240d829bc903b1d4464 (patch)
tree10cc21d70bf13181aef7c8ad0344077ff63579a3 /Scripts
parentddbb045f6387a8ba23b1210b27a745516a387a52 (diff)
downloadtexty-e127ad39e742396030352240d829bc903b1d4464.tar.xz
texty-e127ad39e742396030352240d829bc903b1d4464.zip
godot: inital Godot 4 migration
Diffstat (limited to 'Scripts')
-rw-r--r--Scripts/Game/Command.cs2
-rw-r--r--Scripts/Game/CommandInputArea.cs12
-rw-r--r--Scripts/Game/CommandParser.cs2
-rw-r--r--Scripts/Game/Commands/LookCommand.cs2
-rw-r--r--Scripts/Game/Game.cs2
-rw-r--r--Scripts/GodotExtensions/ArrayExtensions.cs3
-rw-r--r--Scripts/GodotExtensions/NodeExtensions.cs2
-rw-r--r--Scripts/Location.cs2
-rw-r--r--Scripts/Menus/MainMenu.cs38
-rw-r--r--Scripts/Menus/MainMenuButtons.cs14
-rw-r--r--Scripts/Terminal/ButtonBlock.cs10
-rw-r--r--Scripts/Terminal/InputArea.cs10
-rw-r--r--Scripts/Terminal/MenuScreen.cs2
-rw-r--r--Scripts/Terminal/OutputArea.cs8
-rw-r--r--Scripts/Terminal/OutputBlock.cs6
-rw-r--r--Scripts/Terminal/StatusArea.cs4
16 files changed, 62 insertions, 57 deletions
diff --git a/Scripts/Game/Command.cs b/Scripts/Game/Command.cs
index 07d7c84..20b8437 100644
--- a/Scripts/Game/Command.cs
+++ b/Scripts/Game/Command.cs
@@ -7,7 +7,7 @@ namespace Texty.Scripts.Game
Look
}
- public class Command : Object
+ public partial class Command : Object
{
public Command()
{
diff --git a/Scripts/Game/CommandInputArea.cs b/Scripts/Game/CommandInputArea.cs
index 2f1fc09..af54a15 100644
--- a/Scripts/Game/CommandInputArea.cs
+++ b/Scripts/Game/CommandInputArea.cs
@@ -4,10 +4,10 @@ using Texty.Scripts.Terminal;
namespace Texty.Scripts.Game
{
[Tool]
- public class CommandInputArea : InputArea
+ public partial class CommandInputArea : InputArea
{
- [Signal] public delegate void CommandSubmitted(Command command);
- [Signal] public delegate void UnknownInputSubmitted(string text);
+ [Signal] public delegate void CommandSubmittedEventHandler(Command command);
+ [Signal] public delegate void UnknownInputSubmittedEventHandler(string text);
private CommandParser CommandParser => GetNodeOrNull<CommandParser>($"%{nameof(CommandParser)}");
@@ -18,15 +18,15 @@ namespace Texty.Scripts.Game
public override void OnTextEntered(string text)
{
- if (text.Empty())
+ if (text.Length == 0)
return;
TextInput.Clear();
var command = CommandParser.TryParse(text);
if (command != null)
- EmitSignal(nameof(CommandSubmitted), command);
+ EmitSignal(SignalName.CommandSubmitted, command);
else
- EmitSignal(nameof(UnknownInputSubmitted), text);
+ EmitSignal(SignalName.UnknownInputSubmitted, text);
}
}
} \ No newline at end of file
diff --git a/Scripts/Game/CommandParser.cs b/Scripts/Game/CommandParser.cs
index 5f8249a..9b02ee5 100644
--- a/Scripts/Game/CommandParser.cs
+++ b/Scripts/Game/CommandParser.cs
@@ -4,7 +4,7 @@ using Texty.Scripts.Commands;
namespace Texty.Scripts.Game
{
- public class CommandParser : Node
+ public partial class CommandParser : Node
{
public override void _Ready()
{
diff --git a/Scripts/Game/Commands/LookCommand.cs b/Scripts/Game/Commands/LookCommand.cs
index b7910cc..22ba77e 100644
--- a/Scripts/Game/Commands/LookCommand.cs
+++ b/Scripts/Game/Commands/LookCommand.cs
@@ -9,7 +9,7 @@ namespace Texty.Scripts.Commands
Around
}
- public class LookCommand : Command
+ public partial class LookCommand : Command
{
public LookCommand()
{
diff --git a/Scripts/Game/Game.cs b/Scripts/Game/Game.cs
index ff7e4f7..07d42b2 100644
--- a/Scripts/Game/Game.cs
+++ b/Scripts/Game/Game.cs
@@ -3,7 +3,7 @@ using Texty.Scripts.Terminal;
namespace Texty.Scripts.Game
{
- public class Game : Node
+ public partial class Game : Node
{
private InputArea InputArea => GetNodeOrNull<InputArea>($"%{nameof(InputArea)}");
private OutputArea OutputArea => GetNodeOrNull<OutputArea>($"%{nameof(OutputArea)}");
diff --git a/Scripts/GodotExtensions/ArrayExtensions.cs b/Scripts/GodotExtensions/ArrayExtensions.cs
index aa3a9c4..2712232 100644
--- a/Scripts/GodotExtensions/ArrayExtensions.cs
+++ b/Scripts/GodotExtensions/ArrayExtensions.cs
@@ -1,11 +1,12 @@
using System;
+using Godot;
using Godot.Collections;
namespace Texty.Scripts.GodotExtensions
{
public static class ArrayExtensions
{
- public static void ForEach<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);
}
diff --git a/Scripts/GodotExtensions/NodeExtensions.cs b/Scripts/GodotExtensions/NodeExtensions.cs
index b398985..c361496 100644
--- a/Scripts/GodotExtensions/NodeExtensions.cs
+++ b/Scripts/GodotExtensions/NodeExtensions.cs
@@ -6,7 +6,7 @@ namespace Texty.Scripts.GodotExtensions
{
public static class NodeExtensions
{
- public static Array<T> GetChildren<T>(this Node node)
+ public static Array<T> GetChildren<[MustBeVariant] T>(this Node node)
{
return new Array<T>(node.GetChildren().OfType<T>());
}
diff --git a/Scripts/Location.cs b/Scripts/Location.cs
index ab8543b..aaca980 100644
--- a/Scripts/Location.cs
+++ b/Scripts/Location.cs
@@ -2,7 +2,7 @@ using Godot;
namespace Texty.Scripts
{
- public class Location : Resource
+ public partial class Location : Resource
{
[Export(PropertyHint.MultilineText)] public string FlavourText = string.Empty;
}
diff --git a/Scripts/Menus/MainMenu.cs b/Scripts/Menus/MainMenu.cs
index 0d84ee1..53183d1 100644
--- a/Scripts/Menus/MainMenu.cs
+++ b/Scripts/Menus/MainMenu.cs
@@ -2,23 +2,25 @@ using Godot;
namespace Texty.Scripts.Menus
{
- public class MainMenu : Node
- {
- public void OnStartButtonPressed()
- {
- var game = ResourceLoader.Load<PackedScene>("res://Scenes/Game/Game.tscn");
- GetTree().ChangeSceneTo(game);
- }
+ public partial class MainMenu : Node
+ {
+ public override void _Ready()
+ {
+ }
- public void OnCreditsButtonPressed()
- {
- var credits = ResourceLoader.Load<PackedScene>("res://Scenes/Credits.tscn");
- GetTree().ChangeSceneTo(credits);
- }
+ public void OnStartButtonPressed()
+ {
+ GD.Print("Start button was pressed.");
+ }
- public void OnQuitButtonPressed()
- {
- GetTree().Quit();
- }
- }
-} \ No newline at end of file
+ public void OnCreditsButtonPressed()
+ {
+ GD.Print("Credits button was pressed.");
+ }
+
+ public void OnQuitButtonPressed()
+ {
+ GetTree().Quit();
+ }
+ }
+}
diff --git a/Scripts/Menus/MainMenuButtons.cs b/Scripts/Menus/MainMenuButtons.cs
index c2af034..64e8914 100644
--- a/Scripts/Menus/MainMenuButtons.cs
+++ b/Scripts/Menus/MainMenuButtons.cs
@@ -4,11 +4,11 @@ using Texty.Scripts.Terminal;
namespace Texty.Scripts.Menus
{
- public class MainMenuButtons : ButtonBlock
+ public partial class MainMenuButtons : ButtonBlock
{
- [Signal] public delegate void CreditsButtonPressed();
- [Signal] public delegate void QuitButtonPressed();
- [Signal] public delegate void StartButtonPressed();
+ [Signal] public delegate void CreditsButtonPressedEventHandler();
+ [Signal] public delegate void QuitButtonPressedEventHandler();
+ [Signal] public delegate void StartButtonPressedEventHandler();
protected override void OnButtonPressed(int index)
{
@@ -16,13 +16,13 @@ namespace Texty.Scripts.Menus
switch ((Buttons)index)
{
case Buttons.Start:
- EmitSignal(nameof(StartButtonPressed));
+ EmitSignal(SignalName.StartButtonPressed);
break;
case Buttons.Credits:
- EmitSignal(nameof(CreditsButtonPressed));
+ EmitSignal(SignalName.CreditsButtonPressed);
break;
case Buttons.Quit:
- EmitSignal(nameof(QuitButtonPressed));
+ EmitSignal(SignalName.QuitButtonPressed);
break;
default:
throw new ArgumentOutOfRangeException(nameof(index), index, "Button not implemented!");
diff --git a/Scripts/Terminal/ButtonBlock.cs b/Scripts/Terminal/ButtonBlock.cs
index 769fdf8..ef25f8c 100644
--- a/Scripts/Terminal/ButtonBlock.cs
+++ b/Scripts/Terminal/ButtonBlock.cs
@@ -1,12 +1,10 @@
using System.Linq;
using Godot;
-using Godot.Collections;
using Texty.Scripts.GodotExtensions;
namespace Texty.Scripts.Terminal
{
- [Tool]
- public abstract class ButtonBlock : MarginContainer
+ public partial class ButtonBlock : MarginContainer
{
private VBoxContainer Buttons => GetNodeOrNull<VBoxContainer>($"%{nameof(Buttons)}");
@@ -17,12 +15,14 @@ namespace Texty.Scripts.Terminal
Buttons.GetChildren<Button>().FirstOrDefault()?.GrabFocus();
}
- protected abstract 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.Connect("pressed", this, nameof(OnButtonPressed), new Array(index));
+ button.Pressed += () => OnButtonPressed(index);
}
}
} \ No newline at end of file
diff --git a/Scripts/Terminal/InputArea.cs b/Scripts/Terminal/InputArea.cs
index eb78d38..a32ad2c 100644
--- a/Scripts/Terminal/InputArea.cs
+++ b/Scripts/Terminal/InputArea.cs
@@ -1,15 +1,17 @@
-using System;
using Godot;
namespace Texty.Scripts.Terminal
{
- public abstract class InputArea : HBoxContainer
+ public partial class InputArea : HBoxContainer
{
protected Label PromptLabel => GetNodeOrNull<Label>($"%{nameof(PromptLabel)}");
protected LineEdit TextInput => GetNodeOrNull<LineEdit>($"%{nameof(TextInput)}");
public new bool HasFocus => TextInput?.HasFocus() ?? false;
-
- public abstract 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 5c3abfb..1259b31 100644
--- a/Scripts/Terminal/MenuScreen.cs
+++ b/Scripts/Terminal/MenuScreen.cs
@@ -3,7 +3,7 @@ using Godot;
namespace Texty.Scripts.Terminal
{
[Tool]
- public class MenuScreen : Control
+ public partial class MenuScreen : Control
{
private string _title = "";
private StatusArea TitleArea => GetNodeOrNull<StatusArea>($"%{nameof(TitleArea)}");
diff --git a/Scripts/Terminal/OutputArea.cs b/Scripts/Terminal/OutputArea.cs
index 6de4ac1..e297c49 100644
--- a/Scripts/Terminal/OutputArea.cs
+++ b/Scripts/Terminal/OutputArea.cs
@@ -7,7 +7,7 @@ using Texty.Scripts.Game;
namespace Texty.Scripts.Terminal
{
- public 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));
@@ -22,7 +22,7 @@ namespace Texty.Scripts.Terminal
public override void _Ready()
{
Debug.Assert(OutputBlockScene != null, "OutputBlockScene has not been configured!");
- Debug.Assert(OutputBlockScene.CanInstance(), "OutputBlockScene can not be instanced!");
+ Debug.Assert(OutputBlockScene.CanInstantiate(), "OutputBlockScene can not be instanced!");
Clear();
}
@@ -37,8 +37,8 @@ namespace Texty.Scripts.Terminal
public void Push(string text)
{
- if (text.Empty()) return;
- var block = OutputBlockScene.Instance<OutputBlock>();
+ if (string.IsNullOrEmpty(text)) return;
+ var block = OutputBlockScene.Instantiate<OutputBlock>();
block.Content = text;
LineContainer.AddChild(block);
}
diff --git a/Scripts/Terminal/OutputBlock.cs b/Scripts/Terminal/OutputBlock.cs
index 08b2ab2..4512446 100644
--- a/Scripts/Terminal/OutputBlock.cs
+++ b/Scripts/Terminal/OutputBlock.cs
@@ -3,7 +3,7 @@ using Godot;
namespace Texty.Scripts.Terminal
{
[Tool]
- public class OutputBlock : MarginContainer
+ public partial class OutputBlock : MarginContainer
{
private string _content = "";
@@ -12,12 +12,12 @@ namespace Texty.Scripts.Terminal
[Export(PropertyHint.MultilineText)]
public string Content
{
- get => ContentLabel?.BbcodeText ?? "";
+ get => ContentLabel?.Text ?? "";
set
{
_content = value;
if (ContentLabel != null)
- ContentLabel.BbcodeText = GodotSharp.Singleton.Tr(_content);
+ ContentLabel.Text = GodotSharp.Singleton.Tr(_content);
}
}
diff --git a/Scripts/Terminal/StatusArea.cs b/Scripts/Terminal/StatusArea.cs
index 35bc1c7..3099168 100644
--- a/Scripts/Terminal/StatusArea.cs
+++ b/Scripts/Terminal/StatusArea.cs
@@ -3,7 +3,7 @@ using Godot;
namespace Texty.Scripts.Terminal
{
[Tool]
- public class StatusArea : HBoxContainer
+ public partial class StatusArea : HBoxContainer
{
private string _titleText = "";
private RichTextLabel TitleLabel => GetNodeOrNull<RichTextLabel>($"%{nameof(TitleLabel)}");
@@ -16,7 +16,7 @@ namespace Texty.Scripts.Terminal
{
_titleText = value;
if (TitleLabel != null)
- TitleLabel.BbcodeText = GodotSharp.Singleton.Tr(value);
+ TitleLabel.Text = GodotSharp.Singleton.Tr(value);
}
}