Skip to content

Commit

Permalink
Fixes to LongString class
Browse files Browse the repository at this point in the history
  • Loading branch information
Orange-Panda committed Jan 24, 2022
1 parent c2733c5 commit 248ca3b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private string TranslateParameter(Type type)
{
return "WORD";
}
else if (type == typeof(Longstring))
else if (type == typeof(LongString))
{
return "PHRASE";
}
Expand Down
20 changes: 10 additions & 10 deletions Runtime/DevConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("<color=red>Error:</color> Bad command syntax");
return;
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -169,10 +169,10 @@ public static void ProcessCommand(string submitText)
/// <param name="input">The user input to parse</param>
/// <param name="commandName">The name of the command that the user has input</param>
/// <param name="args">None to many long array of the arguments provided by the user.</param>
/// <param name="longstring">All parameters provided by the user in a single spaced string.</param>
/// <param name="longString">All parameters provided by the user in a single spaced string.</param>
/// <remarks>All output variables will be null if the parsing failed.</remarks>
/// <returns>True if the input was parsed properly, false if the parsing failed.</returns>
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
{
Expand All @@ -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;
}
}
Expand Down
10 changes: 6 additions & 4 deletions Runtime/Longstring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ namespace LMirman.VespaIO
/// Long string is just a regular string but when provided as a parameter for a <see cref="StaticCommandAttribute"/> will send the entire console parameters (besides the command itself) to the method
/// </summary>
/// <remarks>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.</remarks>
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;
}
}
6 changes: 3 additions & 3 deletions Runtime/NativeCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 248ca3b

Please sign in to comment.