using System.Collections.Generic; using System.Text.Json.Serialization; namespace RynthCore.Loot.Editing; // The JSON contract between RynthAi's loot edit bridge and the engine's ImGui // Loot Editor face (RynthCore docs/IMGUI_LOOT_EDITOR.md). The engine mirrors // these types in UI\Data\LootEditData.cs; keep the two in step. Strings cross // the export boundary as UTF-8. /// The open profile: header, the rule list (one row per rule) and the last command's result. public sealed class LootEditState { /// Changes whenever anything below changes. public long Revision { get; set; } /// Full path of the open profile; empty when none is open. public string Path { get; set; } = string.Empty; public string FileName { get; set; } = string.Empty; /// "utl", "json", or empty. public string Format { get; set; } = string.Empty; /// False for a new profile that Save will create. public bool Exists { get; set; } public bool ReadOnly { get; set; } public string ReadOnlyReason { get; set; } = string.Empty; public bool Dirty { get; set; } /// The file changed on disk while there were unsaved edits: Save refuses unless forced. public bool ChangedOnDisk { get; set; } /// RynthAi's loot profile (what looting uses now). public string InUsePath { get; set; } = string.Empty; public bool InUse { get; set; } /// Result of the last command (or load); MessageSeq counts them. public string Message { get; set; } = string.Empty; public bool MessageOk { get; set; } = true; public long MessageSeq { get; set; } /// The rule the last command made or moved (to select it), or -1. public int Focus { get; set; } = -1; /// Profiles in the loot folder, for the picker. public List Files { get; set; } = new(); public List Rules { get; set; } = new(); } public sealed class LootEditFile { public string Path { get; set; } = string.Empty; public string Display { get; set; } = string.Empty; } /// One rule in the list. public sealed class LootEditRow { public string Name { get; set; } = string.Empty; public bool Enabled { get; set; } = true; /// VTank action code: 1 Keep, 2 Salvage, 3 Sell, 4 Read, 10 Keep #. public int Action { get; set; } public int KeepCount { get; set; } /// Conditions in words (ASCII), shortened. public string Summary { get; set; } = string.Empty; public int Conditions { get; set; } } /// A whole rule: what the rule view edits and sends back with "update_rule". public sealed class LootEditRule { public int Index { get; set; } = -1; public string Name { get; set; } = string.Empty; public bool Enabled { get; set; } = true; public int Action { get; set; } = 1; public int KeepCount { get; set; } /// Passed through untouched (Phase 1 does not edit these). public int Priority { get; set; } /// Null for v0 files, which have no custom expression line. public string? CustomExpression { get; set; } /// Every condition node in file order, DisabledRule (9999) nodes included. public List Conditions { get; set; } = new(); } public sealed class LootEditCondition { /// VTank node type; -1 for a read-only JSON condition shown as text. public int NodeType { get; set; } /// The v1 length-code line, kept verbatim ("0" for new conditions). public string LengthCode { get; set; } = "0"; /// The data lines, raw. public List Lines { get; set; } = new(); } /// An edit from the face. Commands that target a rule carry the name the face saw (Expect). public sealed class LootEditCommand { /// open, reload, save, set_enabled, move, add, duplicate, delete, rename, update_rule. public string Op { get; set; } = string.Empty; public int Index { get; set; } = -1; /// move: the index the rule ends up at. public int To { get; set; } = -1; public string Value { get; set; } = string.Empty; public string Path { get; set; } = string.Empty; /// The rule's name as the face saw it; a mismatch means the list changed under it. public string? Expect { get; set; } /// open/reload: discard unsaved edits; save: overwrite a file that changed on disk. public bool Force { get; set; } public LootEditRule? Rule { get; set; } } /// Names for the face's pickers. Sent once per plugin load. public sealed class LootEditVocab { public List Actions { get; set; } = new(); public List NodeTypes { get; set; } = new(); public List ObjectClasses { get; set; } = new(); public List LongKeys { get; set; } = new(); public List DoubleKeys { get; set; } = new(); public List StringKeys { get; set; } = new(); public List Skills { get; set; } = new(); /// /// Names for long keys' values (WieldSkilltype's skills, MaterialType's /// materials...), added 2026-10. An older engine ignores this; a newer engine /// with an older RynthAi gets it empty and keeps the value a text box. /// public List LongValueTables { get; set; } = new(); } public sealed class LootEditName { public int Id { get; set; } public string Name { get; set; } = string.Empty; } /// What one long key's numbers mean (LootRuleText.ValueTableFor). public sealed class LootEditValueTable { /// The long key (e.g. 159 WieldSkilltype). public int Key { get; set; } /// The value is a set of flags: a named value is one flag (or a common pair). public bool Flags { get; set; } public List Values { get; set; } = new(); } public sealed class LootEditNodeType { public int Id { get; set; } public string Name { get; set; } = string.Empty; /// Data lines the node takes. public int Lines { get; set; } public List Labels { get; set; } = new(); public List Defaults { get; set; } = new(); /// /// The face's editor: "class" (object class), "keyval" (value, key), "keypattern" /// (pattern, key), "text" (one string), "value" (one number), "raw" (the lines as text). /// public string Editor { get; set; } = "raw"; /// For keyval/keypattern: "long", "double", "string" or "skill". public string KeyTable { get; set; } = string.Empty; /// /// keyval "long" only: the value is picked by name when the key has a /// LongValueTables entry (GE/LE/E/NE and buffed GE; not "has flag"). Added 2026-10. /// public bool NamedValues { get; set; } } [JsonSourceGenerationOptions(WriteIndented = false, PropertyNameCaseInsensitive = true)] [JsonSerializable(typeof(LootEditState))] [JsonSerializable(typeof(LootEditRule))] [JsonSerializable(typeof(LootEditCommand))] [JsonSerializable(typeof(LootEditVocab))] public sealed partial class LootEditJsonContext : JsonSerializerContext { }