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/Commands | |
| parent | 0967a4654c9fa67b5cfc19edf3cfc075bf6bde92 (diff) | |
| download | texty-2f3abbb6f1141f15ef77ac27e431bc66bb0c7899.tar.xz texty-2f3abbb6f1141f15ef77ac27e431bc66bb0c7899.zip | |
game: adapt scripts to new design
Diffstat (limited to 'Scripts/Game/Commands')
| -rw-r--r-- | Scripts/Game/Commands/LookCommand.cs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Scripts/Game/Commands/LookCommand.cs b/Scripts/Game/Commands/LookCommand.cs new file mode 100644 index 0000000..b7910cc --- /dev/null +++ b/Scripts/Game/Commands/LookCommand.cs @@ -0,0 +1,58 @@ +using System.Linq; +using Texty.Scripts.Game; + +namespace Texty.Scripts.Commands +{ + public enum LookModifier + { + At, + Around + } + + public class LookCommand : Command + { + public LookCommand() + { + } + + 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) + { + 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) + }; + } + } +}
\ No newline at end of file |
