Some tiny stuff. More tomorrow

This commit is contained in:
That-One-Nerd 2023-04-10 19:23:46 -04:00
parent b2bc9fa7ee
commit 0c07c9cfe5
5 changed files with 58 additions and 7 deletions

View File

@ -0,0 +1,11 @@
namespace SrcMod.Shell.Modules;
[Module("config")]
public static class ConfigModule
{
[Command("display")]
public static void DisplayConfig()
{
// TODO
}
}

View File

@ -0,0 +1,8 @@
namespace SrcMod.Shell.ObjectModels;
public enum AskMode : sbyte
{
Never = -1,
Ask = 0,
Always = 1
}

View File

@ -24,18 +24,21 @@ public struct Config
Defaults = new();
}
public string[] SteamDirectories;
public string[] GameDirectories;
public AskMode RunUnsafeCommands;
public Config ApplyChanges(ConfigChanges changes) => this with
{
SteamDirectories = changes.SteamDirectories ?? SteamDirectories
GameDirectories = changes.GameDirectories ?? GameDirectories,
RunUnsafeCommands = changes.RunUnsafeCommands ?? RunUnsafeCommands
};
public ConfigChanges GetChanges(Config? baseConfig = null)
{
Config reference = baseConfig ?? Defaults;
return new()
{
SteamDirectories = reference.SteamDirectories == SteamDirectories ? null : SteamDirectories
GameDirectories = reference.GameDirectories == GameDirectories ? null : GameDirectories,
RunUnsafeCommands = reference.RunUnsafeCommands == RunUnsafeCommands ? null : RunUnsafeCommands
};
}

View File

@ -2,7 +2,9 @@
public record struct ConfigChanges
{
public bool HasChange => SteamDirectories is not null;
[JsonIgnore]
public bool HasChange => GameDirectories is not null || RunUnsafeCommands is not null;
public string[]? SteamDirectories;
public string[]? GameDirectories;
public AskMode? RunUnsafeCommands;
}

View File

@ -1,4 +1,6 @@
namespace SrcMod.Shell;
using System.Numerics;
namespace SrcMod.Shell;
public static class Tools
{
@ -16,7 +18,8 @@ public static class Tools
{
Serializer = JsonSerializer.Create(new()
{
Formatting = Formatting.Indented
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
});
}
@ -165,6 +168,30 @@ public static class Tools
}
}
public static void WriteAutoColor(object? message, bool newLine = true)
{
ConsoleColor? col = null;
if (message is null) col = ConsoleColor.DarkGray;
else if (message is bool typeBool)
{
if (typeBool) col = ConsoleColor.Green;
else col = ConsoleColor.Red;
}
else if (message is sbyte || message is byte || message is short || message is ushort ||
message is int || message is uint || message is long || message is ulong ||
message is float || message is double || message is decimal) col = ConsoleColor.DarkGreen;
else if (message is char) col = ConsoleColor.DarkYellow;
else if (message is AskMode typeAskMode) col = typeAskMode switch
{
AskMode.Never => ConsoleColor.Red,
AskMode.Ask => ConsoleColor.DarkGray,
AskMode.Always => ConsoleColor.Green,
_ => null
};
Write(message, col, newLine);
}
public static bool ValidateUnsafe()
{
Write("You are about to execute an unsafe command.\nProceed? > ", ConsoleColor.DarkYellow, false);