Extended the Log to filter through the displayed responced using console

This commit is contained in:
Twirlbug 2023-06-28 00:26:21 -05:00
parent 8e4c603cad
commit 92eebc7de1
4 changed files with 203 additions and 37 deletions

View file

@ -10,6 +10,7 @@ cheat allgadgets
Unlocks all of the gagets in the game
cheat spawn [id] ([amount])
spawns given item for the given ammount
tp [DestinationPlayer]
Teleports the player that entered in the commant to the player entered
@ -17,4 +18,9 @@ listplayers
Prints the list of current players to the console
sleep [Hours]
Sleep command followed by the time in in game hours to "sleep"". Fast forwards the game the alotted hours.
Sleep command followed by the time in in game hours to "sleep"". Fast forwards the game the alotted hours.
console [enable/disable] [logtype]
Sets whether a specific log type should be displaying in the console.
All type default to enabled.
Log Types: Error, Assert, Warning, Log, Exception

View file

@ -9,7 +9,7 @@ namespace SRMultiplayer
{
public string inputString = "";
public event Action<string> OnInputText;
public void ClearLine()
{
Console.CursorLeft = 0;
@ -17,7 +17,7 @@ namespace SRMultiplayer
Console.CursorTop--;
Console.CursorLeft = 0;
}
public void RedrawInputLine()
{
bool flag = Console.CursorLeft > 0;
@ -29,7 +29,7 @@ namespace SRMultiplayer
Console.Write("> ");
Console.Write(this.inputString);
}
internal void OnBackspace()
{
bool flag = this.inputString.Length <= 0;
@ -39,14 +39,14 @@ namespace SRMultiplayer
this.RedrawInputLine();
}
}
internal void OnEscape()
{
this.ClearLine();
this.inputString = "";
this.RedrawInputLine();
}
internal void OnEnter()
{
this.ClearLine();
@ -57,10 +57,45 @@ namespace SRMultiplayer
bool flag = this.OnInputText != null;
if (flag)
{
//on text inputed reset the search loc and cycle the search tree
searchLoc = -1; //searchLoc set to -1 to always go to place 0 on first arrow
AddToCommandTree(obj);
this.OnInputText(obj);
}
}
List<string> cmdTree = new List<string>();
internal void AddToCommandTree(string cmdText)
{
cmdTree.Insert(0,cmdText);
//if tree gets larger than 10 remove the 11th item
if (cmdTree.Count > 10) { cmdTree.RemoveAt(10); };
}
//handle internal cycling of last 10 commands
int searchLoc = -1;
internal void GetCommand(int diff)
{
if (cmdTree.Count > 0)
{
searchLoc = searchLoc + diff;
//prevent below 0 or over max position
if (searchLoc > (cmdTree.Count - 1)) searchLoc = (cmdTree.Count - 1);
if (searchLoc < 0) searchLoc = 0;
//if a new location is found enter the search text in the input and redraw it.
this.inputString = cmdTree[searchLoc];
this.RedrawInputLine();
}
else
{
Console.WriteLine("cmdTree is empty");
}
}
public void Update()
{
bool flag = !Console.KeyAvailable;
@ -94,6 +129,24 @@ namespace SRMultiplayer
this.inputString += consoleKeyInfo.KeyChar.ToString();
this.RedrawInputLine();
}
else
{
//handle up pressed to get previous lines
bool flag6 = consoleKeyInfo.Key == ConsoleKey.UpArrow;
if (flag6)
{
this.GetCommand(1);
}
else
{
//handle down pressed to get next lines
bool flag7 = consoleKeyInfo.Key == ConsoleKey.DownArrow;
if (flag7)
{
this.GetCommand(-1);
}
}
}
}
}
}

View file

@ -1,4 +1,5 @@
using MonomiPark.SlimeRancher.Regions;
using JetBrains.Annotations;
using MonomiPark.SlimeRancher.Regions;
using SRMultiplayer.Networking;
using System;
using System.Collections.Generic;
@ -30,27 +31,98 @@ namespace SRMultiplayer
SRMP.Log("Console Started");
}
//used to prevent duplicate messages displaying and list what number duplicate it is
string LastMessage = "";
int duplicateCount = 0;
//types of console types that can be enabled/disabled
//server automatically starts with all active
List<LogType> blockMessages = new List<LogType>(); //keeps a list of message types that have been disabled
private void Application_logMessageReceived(string condition, string stackTrace, LogType type)
{
if (type == LogType.Warning)
Console.ForegroundColor = ConsoleColor.Yellow;
else if (type == LogType.Error)
Console.ForegroundColor = ConsoleColor.Red;
else
Console.ForegroundColor = ConsoleColor.White;
// We're half way through typing something, so clear this line ..
if (Console.CursorLeft != 0)
input.ClearLine();
Console.WriteLine(condition);
//construct message
string message = condition;
if (!string.IsNullOrEmpty(stackTrace))
Console.WriteLine(stackTrace);
{
//add stack strace if included
message += Environment.NewLine + stackTrace;
}
if (message == LastMessage)
{
//do not process duplicate marks if the last item was not written
if(duplicateCount >0) duplicateCount++;
}
else
{
//add write line for duplicate notices if necessary
if (duplicateCount > 0)
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("Output Duplicated: " + duplicateCount);
}
//format color for message
if (type == LogType.Warning)
Console.ForegroundColor = ConsoleColor.Yellow;
else if (type == LogType.Error)
Console.ForegroundColor = ConsoleColor.Red;
else
Console.ForegroundColor = ConsoleColor.White;
// mark new message
LastMessage = message;
//check data for inner types
string data = condition;
//remove the srmp tag and the time to check inner tags
if (type == LogType.Log) data = data.Substring(17);
//only write the message type if its not blocked
//always allow console replay to display
if (!blockMessages.Contains(type) || data.StartsWith("[Console]"))
{
//write the new line if not blocked
duplicateCount = 0;
Console.WriteLine(message);
}
else
{
//for testing log disabled display
//Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine(type.ToString() + " Dismissed");
//mark dupilcate count to -1
//prevent duplicate count for supressed messages from displaying
duplicateCount = -1;
}
}
// If we were typing something re-add it.
input.RedrawInputLine();
}
public static void ClearCurrentConsoleLine()
{
int currentLineCursor = Console.CursorTop;
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write(new string(' ', Console.BufferWidth));
Console.SetCursorPosition(0, currentLineCursor);
}
//create a log call that marks all console sent replys
void ConsoleLog(string message)
{
SRMP.Log(message, "Console");
}
@ -74,17 +146,17 @@ namespace SRMultiplayer
{
if (args.Length != 2 || !int.TryParse(args[1], out int money))
{
SRMP.Log("Usage: cheat money <amount>");
ConsoleLog("Usage: cheat money <amount>");
}
else
{
if(money > 0)
if (money > 0)
SRSingleton<SceneContext>.Instance.PlayerState.AddCurrency(money);
else
SRSingleton<SceneContext>.Instance.PlayerState.SpendCurrency(money);
}
}
else if(args[0].Equals("enable"))
else if (args[0].Equals("enable"))
{
//TestUI.Instance.cheat = !TestUI.Instance.cheat;
}
@ -92,7 +164,7 @@ namespace SRMultiplayer
{
if (args.Length != 2 || !int.TryParse(args[1], out int value))
{
SRMP.Log("Usage: cheat keys <amount>");
ConsoleLog("Usage: cheat keys <amount>");
}
else
{
@ -123,7 +195,7 @@ namespace SRMultiplayer
}
else
{
SRMP.Log(id + " can not be spawned");
ConsoleLog(id + " can not be spawned");
}
}
else
@ -132,7 +204,7 @@ namespace SRMultiplayer
SRMP.Log(args[1] + " not found. " + (data.Count() > 0 ? " Did you mean one of these?" : ""));
foreach (var name in data)
{
SRMP.Log(name);
ConsoleLog(name);
}
}
}
@ -156,26 +228,26 @@ namespace SRMultiplayer
else
{
var data = Enum.GetNames(typeof(Identifiable.Id)).Where(n => n.ToLower().Contains(args[1].ToLower()));
SRMP.Log(args[1] + " not found. " + (data.Count() > 0 ? " Did you mean one of these?" : ""));
ConsoleLog(args[1] + " not found. " + (data.Count() > 0 ? " Did you mean one of these?" : ""));
foreach (var name in data)
{
SRMP.Log(name);
ConsoleLog(name);
}
}
}
else
{
SRMP.Log("Usage: cheat spawn <id> (<amount>)");
ConsoleLog("Usage: cheat spawn <id> (<amount>)");
}
}
}
else
{
SRMP.Log("Available sub commands:");
SRMP.Log("cheat money <amount>");
SRMP.Log("cheat keys <amount>");
SRMP.Log("cheat spawn <id> (<amount>)");
SRMP.Log("cheat allgadgets");
ConsoleLog("Available sub commands:");
ConsoleLog("cheat money <amount>");
ConsoleLog("cheat keys <amount>");
ConsoleLog("cheat spawn <id> (<amount>)");
ConsoleLog("cheat allgadgets");
}
}
break;
@ -190,18 +262,18 @@ namespace SRMultiplayer
}
else
{
SRMP.Log("Player not found");
ConsoleLog("Player not found");
}
}
else
{
SRMP.Log("Usage: tp <username>");
ConsoleLog("Usage: tp <username>");
}
}
break;
case "listplayers":
{
SRMP.Log("Players:");
ConsoleLog("Players:");
foreach (var player in Globals.Players.Values)
{
SRMP.Log(player.Username);
@ -213,10 +285,45 @@ namespace SRMultiplayer
if (args.Length == 1)
{
SRSingleton<SceneContext>.Instance.TimeDirector.FastForwardTo(SRSingleton<SceneContext>.Instance.TimeDirector.HoursFromNow(float.Parse(args[0])));
ConsoleLog("Sleeoing for " + args[0] + " hours");
}
else
{
ConsoleLog("Usage: sleep <hours>");
}
}
break;
case "console": //add toggle option for turning on and off logging types
if (args.Length > 1 && (args[0] == "enable"|| args[0] == "disable"))
{
bool enable = args[0] == "enable";
//double check type
if (LogType.TryParse(args[1], true, out LogType logType))
{
if (enable)
{
if (!blockMessages.Contains(logType)) blockMessages.Remove(logType);
ConsoleLog(logType.ToString() + " Messages Enabled");
}
else
{
if (blockMessages.Contains(logType)) blockMessages.Add(logType);
ConsoleLog("[Console] " + logType.ToString() + " Messages Disabled");
}
}
else
{
ConsoleLog("Invalid Feed back Type");
ConsoleLog("Suggestions: " + string.Join(", ", logType));
}
}
else
{
ConsoleLog("Usage: console <enable/disable> <feedbackType>");
}
break;
}
}

View file

@ -133,14 +133,14 @@ public class MultiplayerUI : SRSingleton<MultiplayerUI>
}
private void FunctionKeys()
{
GUILayout.Label("Press Button or Corresponding Key To Change Menu");
GUILayout.Label("Press Button or Key To Change Style");
GUILayout.BeginHorizontal();
if (GUILayout.Button(menuOpen == 1 ? "F3 - Full" : "F3 - Mini"))
{
menuOpen = menuOpen == 1 ? 2 : 1;
}
GUILayout.FlexibleSpace();
if (GUILayout.Button(menuOpen == 0 ? "F4 - Full" : "F4 - Closed"))
if (GUILayout.Button(menuOpen == 0 ? "F4 - Full" : "F4 - Colapsed"))
{
menuOpen = menuOpen == 0 ? 2 : 0;
}