From 248ca3ba834100299d3b33743defda1ef84c3d0d Mon Sep 17 00:00:00 2001 From: Luke Mirman Date: Sun, 23 Jan 2022 19:21:13 -0500 Subject: [PATCH] Fixes to LongString class --- CHANGELOG.md | 8 ++++++++ Runtime/Commands.cs | 2 +- Runtime/DevConsole.cs | 20 ++++++++++---------- Runtime/Longstring.cs | 10 ++++++---- Runtime/NativeCommands.cs | 6 +++--- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f122035..26a46d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this package are documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.0.2] - 2022-01-23 + +### Changed +- Casing of Longstring has been changed to LongString. + +### Fixed +- LongString not properly overriding ToString() + ## [1.0.1] - 2022-01-22 ### Added diff --git a/Runtime/Commands.cs b/Runtime/Commands.cs index 834a8aa..aeb3eac 100644 --- a/Runtime/Commands.cs +++ b/Runtime/Commands.cs @@ -171,7 +171,7 @@ private string TranslateParameter(Type type) { return "WORD"; } - else if (type == typeof(Longstring)) + else if (type == typeof(LongString)) { return "PHRASE"; } diff --git a/Runtime/DevConsole.cs b/Runtime/DevConsole.cs index 71f83ba..16a502f 100644 --- a/Runtime/DevConsole.cs +++ b/Runtime/DevConsole.cs @@ -33,7 +33,7 @@ public static void ProcessCommand(string submitText) } // Parse input into useful variables - if (!TryParseCommand(submitText, out string commandName, out object[] args, out Longstring longstring)) + if (!TryParseCommand(submitText, out string commandName, out object[] args, out LongString longString)) { Log("Error: Bad command syntax"); return; @@ -88,7 +88,7 @@ public static void ProcessCommand(string submitText) // Get the best method from the arguments // The best method is the one with all parameters of the same type and the most parameters matched - MethodInfo longstringMethod = null; + MethodInfo longStringMethod = null; MethodInfo bestMethod = null; int bestMethodArgCount = -1; for (int i = 0; i < validMethods.Count; i++) @@ -119,16 +119,16 @@ public static void ProcessCommand(string submitText) bestMethodArgCount = parameters.Length; } - if (parameters.Length == 1 && parameters[0].ParameterType == typeof(Longstring)) + if (parameters.Length == 1 && parameters[0].ParameterType == typeof(LongString)) { - longstringMethod = method; + longStringMethod = method; } } // Execute the best method found in the previous step, if one is found - if (longstringMethod != null && !string.IsNullOrWhiteSpace(longstring) && (bestMethod == null || bestMethodArgCount == 0)) + if (longStringMethod != null && !string.IsNullOrWhiteSpace(longString) && (bestMethod == null || bestMethodArgCount == 0)) { - longstringMethod.Invoke(null, new object[] { longstring }); + longStringMethod.Invoke(null, new object[] { longString }); } else if (bestMethod != null) { @@ -169,10 +169,10 @@ public static void ProcessCommand(string submitText) /// The user input to parse /// The name of the command that the user has input /// None to many long array of the arguments provided by the user. - /// All parameters provided by the user in a single spaced string. + /// All parameters provided by the user in a single spaced string. /// All output variables will be null if the parsing failed. /// True if the input was parsed properly, false if the parsing failed. - private static bool TryParseCommand(string input, out string commandName, out object[] args, out Longstring longstring) + private static bool TryParseCommand(string input, out string commandName, out object[] args, out LongString longString) { try { @@ -187,14 +187,14 @@ private static bool TryParseCommand(string input, out string commandName, out ob } } args = foundArgs.ToArray(); - longstring = foundArgs.Count > 0 ? (Longstring)input.Remove(0, commandName.Length + 1) : (Longstring)string.Empty; + longString = foundArgs.Count > 0 ? (LongString)input.Remove(0, commandName.Length + 1) : (LongString)string.Empty; return true; } catch { args = null; commandName = null; - longstring = null; + longString = null; return false; } } diff --git a/Runtime/Longstring.cs b/Runtime/Longstring.cs index b65772c..fe241e7 100644 --- a/Runtime/Longstring.cs +++ b/Runtime/Longstring.cs @@ -4,16 +4,18 @@ namespace LMirman.VespaIO /// Long string is just a regular string but when provided as a parameter for a will send the entire console parameters (besides the command itself) to the method /// /// In order for a long string to be received it must be the only parameter of method. The invoked method is reponsible for any parsing done after the fact. - public readonly struct Longstring + public readonly struct LongString { public readonly string value; - public static implicit operator string(Longstring longstring) => longstring.value; - public static implicit operator Longstring(string value) => new Longstring(value); + public static implicit operator string(LongString longString) => longString.value; + public static implicit operator LongString(string value) => new LongString(value); - public Longstring(string value) + public LongString(string value) { this.value = value; } + + public override string ToString() => value; } } \ No newline at end of file diff --git a/Runtime/NativeCommands.cs b/Runtime/NativeCommands.cs index 71e1eb0..e6072f0 100644 --- a/Runtime/NativeCommands.cs +++ b/Runtime/NativeCommands.cs @@ -39,14 +39,14 @@ public static void Scene() } [StaticCommand("scene", Cheat = true)] - public static void Scene(Longstring target) + public static void Scene(LongString target) { DevConsole.Log($"Attempting to load scene: {target}"); SceneManager.LoadScene(target); } [StaticCommand("echo", Name = "Echo", Description = "Repeat the input back to the console.")] - public static void Echo(Longstring message) + public static void Echo(LongString message) { DevConsole.Log(message); } @@ -89,7 +89,7 @@ public static void Help(int pageNum) } [StaticCommand("help")] - public static void Help(Longstring query) + public static void Help(LongString query) { string value = ((string)query).ToLower(); if (Commands.Lookup.TryGetValue(value, out Command command))