JSON data table parsing stuff

This commit is contained in:
Kyle Belanger
2024-02-19 17:35:16 -05:00
parent 27acfdff08
commit f33a60d33c
16 changed files with 1392296 additions and 16 deletions

View File

@@ -1,25 +0,0 @@
namespace BLHX.Server.Common.Utils;
public class Config : Singleton<Config>
{
public string Address { get; set; } = "127.0.0.1";
public uint Port { get; set; } = 20000;
public static void Load()
{
Instance = JSON.Load<Config>(JSON.ConfigPath);
#if DEBUG
Logger.c.Log($"Loaded Config:\n{JSON.Stringify(Instance)}");
#endif
}
public static void Save()
{
JSON.Save(JSON.ConfigPath, Instance);
#if DEBUG
Logger.c.Log("Saved Config");
#endif
}
}

View File

@@ -1,35 +0,0 @@
using System.Text.Json;
namespace BLHX.Server.Common.Utils;
public static class JSON
{
public static string ConfigPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config.json");
public static T Load<T>(string path) where T : new()
{
if (!File.Exists(path))
{
T obj = new T();
Save(path, obj);
}
return JsonSerializer.Deserialize<T>(File.ReadAllText(path));
}
public static void Save<T>(string path, T obj)
{
File.WriteAllText(path, JsonSerializer.Serialize(obj, new JsonSerializerOptions()
{
WriteIndented = true
}));
}
public static string Stringify<T>(T obj)
{
return JsonSerializer.Serialize(obj, new JsonSerializerOptions()
{
WriteIndented = true
});
}
}