Early-out on comments

This commit is contained in:
Tim Van Baak 2024-08-21 09:47:13 -07:00
parent e9c4d3d2d3
commit 55dfe0ca99
4 changed files with 5 additions and 11 deletions

View File

@ -18,7 +18,7 @@ public class AdjudicationQueryScriptHandler(World world, bool strict = false) :
public IScriptHandler? HandleInput(string input) public IScriptHandler? HandleInput(string input)
{ {
var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (args.Length == 0) if (args.Length == 0 || input.StartsWith('#'))
{ {
return this; return this;
} }
@ -51,8 +51,6 @@ public class AdjudicationQueryScriptHandler(World world, bool strict = false) :
throw new NotImplementedException(); throw new NotImplementedException();
default: default:
// noop on comments that begin with #
if (command.StartsWith('#')) break;
Console.WriteLine($"Unrecognized command: \"{command}\""); Console.WriteLine($"Unrecognized command: \"{command}\"");
if (Strict) return null; if (Strict) return null;
break; break;

View File

@ -24,6 +24,7 @@ public class GameScriptHandler(World world, bool strict = false) : IScriptHandle
CurrentPower = null; CurrentPower = null;
return this; return this;
} }
if (input.StartsWith('#')) return this;
// "---" submits the orders and allows queries about the outcome // "---" submits the orders and allows queries about the outcome
if (input == "---") { if (input == "---") {

View File

@ -12,7 +12,7 @@ public class ReplScriptHandler : IScriptHandler
public IScriptHandler? HandleInput(string input) public IScriptHandler? HandleInput(string input)
{ {
var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (args.Length == 0) if (args.Length == 0 || input.StartsWith('#'))
{ {
return this; return this;
} }
@ -52,10 +52,7 @@ public class ReplScriptHandler : IScriptHandler
return new SetupScriptHandler(world); return new SetupScriptHandler(world);
default: default:
// noop on comments that begin with #
if (!command.StartsWith('#')) {
Console.WriteLine($"Unrecognized command: \"{command}\""); Console.WriteLine($"Unrecognized command: \"{command}\"");
}
break; break;
} }

View File

@ -24,7 +24,7 @@ public class SetupScriptHandler(World world, bool strict = false) : IScriptHandl
public IScriptHandler? HandleInput(string input) public IScriptHandler? HandleInput(string input)
{ {
var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (args.Length == 0) if (args.Length == 0 || input.StartsWith('#'))
{ {
return this; return this;
} }
@ -88,8 +88,6 @@ public class SetupScriptHandler(World world, bool strict = false) : IScriptHandl
break; break;
default: default:
// noop on comments that begin with #
if (command.StartsWith('#')) break;
Console.WriteLine($"Unrecognized command: \"{command}\""); Console.WriteLine($"Unrecognized command: \"{command}\"");
if (Strict) return null; if (Strict) return null;
break; break;