namespace Aeshnidae.Inspect; /// /// Per-mod configuration, read from Settings.json in the deployed mod folder /// (next to the dll, not in source). Written with defaults on first run so it is /// easy to find, and openable in-game with "/mod settings Aeshnidae.Inspect". /// public class Settings { public const string FileName = "Settings.json"; /// /// Whether players may inspect other PLAYERS. Monsters are always open; a /// player's effective defenses are theirs to keep unless this is on. /// public bool AllowInspectingPlayers { get; set; } = false; /// /// How far away (metres) a creature may be and still be found by name with /// "/inspect ". Selecting it in the client has no range - if you can /// select it, you can inspect it. /// public float NameSearchRange { get; set; } = 60f; private static readonly JsonSerializerOptions JsonOptions = new() { WriteIndented = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true, }; public static Settings Load(string modPath) { var path = Path.Combine(modPath, FileName); try { if (File.Exists(path)) return JsonSerializer.Deserialize(File.ReadAllText(path), JsonOptions) ?? new Settings(); var defaults = new Settings(); defaults.Save(modPath); ModManager.Log($"[{Mod.Name}] wrote default settings to {path}"); return defaults; } catch (Exception ex) { ModManager.Log($"[{Mod.Name}] could not read {path}, using defaults: {ex.Message}", ModManager.LogLevel.Warn); return new Settings(); } } public void Save(string modPath) { try { File.WriteAllText(Path.Combine(modPath, FileName), JsonSerializer.Serialize(this, JsonOptions)); } catch (Exception ex) { ModManager.Log($"[{Mod.Name}] could not save settings: {ex.Message}", ModManager.LogLevel.Error); } } }