From 55dfe0ca99e9bdb0b7e8c6a7cb0433e3ce1ddea8 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Wed, 21 Aug 2024 09:47:13 -0700 Subject: [PATCH] Early-out on comments --- .../Script/AdjudicationQueryScriptHandler.cs | 4 +--- MultiversalDiplomacy/Script/GameScriptHandler.cs | 1 + MultiversalDiplomacy/Script/ReplScriptHandler.cs | 7 ++----- MultiversalDiplomacy/Script/SetupScriptHandler.cs | 4 +--- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/MultiversalDiplomacy/Script/AdjudicationQueryScriptHandler.cs b/MultiversalDiplomacy/Script/AdjudicationQueryScriptHandler.cs index 5ed7570..70e2fa2 100644 --- a/MultiversalDiplomacy/Script/AdjudicationQueryScriptHandler.cs +++ b/MultiversalDiplomacy/Script/AdjudicationQueryScriptHandler.cs @@ -18,7 +18,7 @@ public class AdjudicationQueryScriptHandler(World world, bool strict = false) : public IScriptHandler? HandleInput(string input) { var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); - if (args.Length == 0) + if (args.Length == 0 || input.StartsWith('#')) { return this; } @@ -51,8 +51,6 @@ public class AdjudicationQueryScriptHandler(World world, bool strict = false) : throw new NotImplementedException(); default: - // noop on comments that begin with # - if (command.StartsWith('#')) break; Console.WriteLine($"Unrecognized command: \"{command}\""); if (Strict) return null; break; diff --git a/MultiversalDiplomacy/Script/GameScriptHandler.cs b/MultiversalDiplomacy/Script/GameScriptHandler.cs index 2e84b26..647bb70 100644 --- a/MultiversalDiplomacy/Script/GameScriptHandler.cs +++ b/MultiversalDiplomacy/Script/GameScriptHandler.cs @@ -24,6 +24,7 @@ public class GameScriptHandler(World world, bool strict = false) : IScriptHandle CurrentPower = null; return this; } + if (input.StartsWith('#')) return this; // "---" submits the orders and allows queries about the outcome if (input == "---") { diff --git a/MultiversalDiplomacy/Script/ReplScriptHandler.cs b/MultiversalDiplomacy/Script/ReplScriptHandler.cs index 932cb05..ba17760 100644 --- a/MultiversalDiplomacy/Script/ReplScriptHandler.cs +++ b/MultiversalDiplomacy/Script/ReplScriptHandler.cs @@ -12,7 +12,7 @@ public class ReplScriptHandler : IScriptHandler public IScriptHandler? HandleInput(string input) { var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); - if (args.Length == 0) + if (args.Length == 0 || input.StartsWith('#')) { return this; } @@ -52,10 +52,7 @@ public class ReplScriptHandler : IScriptHandler return new SetupScriptHandler(world); default: - // noop on comments that begin with # - if (!command.StartsWith('#')) { - Console.WriteLine($"Unrecognized command: \"{command}\""); - } + Console.WriteLine($"Unrecognized command: \"{command}\""); break; } diff --git a/MultiversalDiplomacy/Script/SetupScriptHandler.cs b/MultiversalDiplomacy/Script/SetupScriptHandler.cs index 5981f82..03daa6d 100644 --- a/MultiversalDiplomacy/Script/SetupScriptHandler.cs +++ b/MultiversalDiplomacy/Script/SetupScriptHandler.cs @@ -24,7 +24,7 @@ public class SetupScriptHandler(World world, bool strict = false) : IScriptHandl public IScriptHandler? HandleInput(string input) { var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); - if (args.Length == 0) + if (args.Length == 0 || input.StartsWith('#')) { return this; } @@ -88,8 +88,6 @@ public class SetupScriptHandler(World world, bool strict = false) : IScriptHandl break; default: - // noop on comments that begin with # - if (command.StartsWith('#')) break; Console.WriteLine($"Unrecognized command: \"{command}\""); if (Strict) return null; break;