Some tiny stuff. More tomorrow
This commit is contained in:
parent
b2bc9fa7ee
commit
0c07c9cfe5
11
SrcMod/Shell/Modules/ConfigModule.cs
Normal file
11
SrcMod/Shell/Modules/ConfigModule.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace SrcMod.Shell.Modules;
|
||||||
|
|
||||||
|
[Module("config")]
|
||||||
|
public static class ConfigModule
|
||||||
|
{
|
||||||
|
[Command("display")]
|
||||||
|
public static void DisplayConfig()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
8
SrcMod/Shell/ObjectModels/AskMode.cs
Normal file
8
SrcMod/Shell/ObjectModels/AskMode.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace SrcMod.Shell.ObjectModels;
|
||||||
|
|
||||||
|
public enum AskMode : sbyte
|
||||||
|
{
|
||||||
|
Never = -1,
|
||||||
|
Ask = 0,
|
||||||
|
Always = 1
|
||||||
|
}
|
||||||
@ -24,18 +24,21 @@ public struct Config
|
|||||||
Defaults = new();
|
Defaults = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string[] SteamDirectories;
|
public string[] GameDirectories;
|
||||||
|
public AskMode RunUnsafeCommands;
|
||||||
|
|
||||||
public Config ApplyChanges(ConfigChanges changes) => this with
|
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)
|
public ConfigChanges GetChanges(Config? baseConfig = null)
|
||||||
{
|
{
|
||||||
Config reference = baseConfig ?? Defaults;
|
Config reference = baseConfig ?? Defaults;
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
SteamDirectories = reference.SteamDirectories == SteamDirectories ? null : SteamDirectories
|
GameDirectories = reference.GameDirectories == GameDirectories ? null : GameDirectories,
|
||||||
|
RunUnsafeCommands = reference.RunUnsafeCommands == RunUnsafeCommands ? null : RunUnsafeCommands
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
public record struct ConfigChanges
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace SrcMod.Shell;
|
using System.Numerics;
|
||||||
|
|
||||||
|
namespace SrcMod.Shell;
|
||||||
|
|
||||||
public static class Tools
|
public static class Tools
|
||||||
{
|
{
|
||||||
@ -16,7 +18,8 @@ public static class Tools
|
|||||||
{
|
{
|
||||||
Serializer = JsonSerializer.Create(new()
|
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()
|
public static bool ValidateUnsafe()
|
||||||
{
|
{
|
||||||
Write("You are about to execute an unsafe command.\nProceed? > ", ConsoleColor.DarkYellow, false);
|
Write("You are about to execute an unsafe command.\nProceed? > ", ConsoleColor.DarkYellow, false);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user