From 5be5bed0c537f84962777aaab06e2b6d7cfc48e5 Mon Sep 17 00:00:00 2001 From: iisaev Date: Tue, 27 Oct 2026 01:07:29 +0100 Subject: [PATCH] Support schema field options in entity editors --- src/EntityEditor/EntityEditorWindow.cs | 2 +- src/Schemas/ISchemaFieldEditor.cs | 4 +++- src/Schemas/ListFieldEditor.cs | 16 +++++++++------- src/Schemas/LocaleFieldEditor.cs | 8 +++++--- src/Schemas/MapFieldEditor.cs | 14 ++++++++------ src/Schemas/ScalarFieldEditor.cs | 10 ++++++---- src/Schemas/SchemaFieldControl.cs | 8 +++++--- src/Schemas/SchemaFieldEditors.cs | 4 +++- 8 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/EntityEditor/EntityEditorWindow.cs b/src/EntityEditor/EntityEditorWindow.cs index 7afa71c..58c1059 100644 --- a/src/EntityEditor/EntityEditorWindow.cs +++ b/src/EntityEditor/EntityEditorWindow.cs @@ -201,7 +201,7 @@ namespace Cthangover.Tools.EntityEditor private void BuildSchemaFields() { - var described = SchemaCatalog.Current.FieldsOf(kind) + var described = Cthangover.Mods.Schemas.SchemaCatalog.Current.FieldsOf(kind) .Where(f => !string.Equals(f.Key, "Id", StringComparison.OrdinalIgnoreCase) && !fields.Any(e => string.Equals(e.Key, f.Key, StringComparison.OrdinalIgnoreCase))) .ToList(); if (described.Count == 0) diff --git a/src/Schemas/ISchemaFieldEditor.cs b/src/Schemas/ISchemaFieldEditor.cs index a2be780..bc5cb04 100644 --- a/src/Schemas/ISchemaFieldEditor.cs +++ b/src/Schemas/ISchemaFieldEditor.cs @@ -1,13 +1,15 @@ namespace Cthangover.Tools.Schemas { using Cthangover.Mods.Schemas; + using SchemaFieldDefinition = Cthangover.Mods.Schemas.FieldSchema; + using SchemaJsonValues = Cthangover.Mods.Schemas.SchemaJson; using System.Text.Json.Nodes; /// One field's editor in the data editor form: shows the field's JSON and gives it back edited. public interface ISchemaFieldEditor { /// The described field. - FieldSchema Field { get; } + SchemaFieldDefinition Field { get; } /// Shows (null: the field is absent). void Load(JsonNode node); diff --git a/src/Schemas/ListFieldEditor.cs b/src/Schemas/ListFieldEditor.cs index 2f25f46..a3b9915 100644 --- a/src/Schemas/ListFieldEditor.cs +++ b/src/Schemas/ListFieldEditor.cs @@ -1,6 +1,8 @@ namespace Cthangover.Tools.Schemas { using Cthangover.Mods.Schemas; + using SchemaFieldDefinition = Cthangover.Mods.Schemas.FieldSchema; + using SchemaJsonValues = Cthangover.Mods.Schemas.SchemaJson; using System; using System.Collections.Generic; using System.Globalization; @@ -12,7 +14,7 @@ namespace Cthangover.Tools.Schemas using Godot; /// - /// Edits a list field — an array of objects described by + /// Edits a list field — an array of objects described by /// (an item's traits, an archetype's learnings, a shop's goods) — as a stack of small /// cards with an add and a remove button, each card a form of the sub-fields. /// @@ -22,7 +24,7 @@ namespace Cthangover.Tools.Schemas /// public class ListFieldEditor : ISchemaFieldEditor { - private readonly FieldSchema field; + private readonly SchemaFieldDefinition field; private readonly Action changed; private readonly VBoxContainer cards; private readonly List> rows = new(); @@ -30,10 +32,10 @@ namespace Cthangover.Tools.Schemas private bool suppress; /// - public FieldSchema Field => field; + public SchemaFieldDefinition Field => field; /// Adds the editor for to . - public ListFieldEditor(Container parent, FieldSchema field, Action changed) + public ListFieldEditor(Container parent, SchemaFieldDefinition field, Action changed) { this.field = field; this.changed = changed; @@ -87,7 +89,7 @@ namespace Cthangover.Tools.Schemas { var item = new JsonObject(); foreach (var control in card.Where(c => c.Value.Length > 0)) - item[control.Field.Key] = SchemaJson.ToNode(control.Field, control.Value); + item[control.Field.Key] = SchemaJsonValues.ToNode(control.Field, control.Value); if (item.Count > 0) array.Add(item); } @@ -126,10 +128,10 @@ namespace Cthangover.Tools.Schemas var column = new VBoxContainer(); card.AddChild(column); var controls = new List(); - foreach (var sub in field.Of ?? new List()) + foreach (var sub in field.Of ?? new List()) { var control = new SchemaFieldControl(column, sub, OnChanged); - control.Value = SchemaJson.ToText(Find(item, sub.Key)); + control.Value = SchemaJsonValues.ToText(Find(item, sub.Key)); controls.Add(control); } if (!IsValues) diff --git a/src/Schemas/LocaleFieldEditor.cs b/src/Schemas/LocaleFieldEditor.cs index c98be21..f78237b 100644 --- a/src/Schemas/LocaleFieldEditor.cs +++ b/src/Schemas/LocaleFieldEditor.cs @@ -1,6 +1,8 @@ namespace Cthangover.Tools.Schemas { using Cthangover.Mods.Schemas; + using SchemaFieldDefinition = Cthangover.Mods.Schemas.FieldSchema; + using SchemaJsonValues = Cthangover.Mods.Schemas.SchemaJson; using System; using System.Collections.Generic; using System.Text.Json.Nodes; @@ -18,7 +20,7 @@ namespace Cthangover.Tools.Schemas /// public class LocaleFieldEditor : ISchemaFieldEditor { - private readonly FieldSchema field; + private readonly SchemaFieldDefinition field; private readonly Action changed; private readonly LineEdit keyEdit; private readonly VBoxContainer texts; @@ -28,10 +30,10 @@ namespace Cthangover.Tools.Schemas private bool suppress; /// - public FieldSchema Field => field; + public SchemaFieldDefinition Field => field; /// Adds the editor for to . - public LocaleFieldEditor(Container parent, FieldSchema field, Action changed) + public LocaleFieldEditor(Container parent, SchemaFieldDefinition field, Action changed) { this.field = field; this.changed = changed; diff --git a/src/Schemas/MapFieldEditor.cs b/src/Schemas/MapFieldEditor.cs index 4a25715..9eff86a 100644 --- a/src/Schemas/MapFieldEditor.cs +++ b/src/Schemas/MapFieldEditor.cs @@ -1,6 +1,8 @@ namespace Cthangover.Tools.Schemas { using Cthangover.Mods.Schemas; + using SchemaFieldDefinition = Cthangover.Mods.Schemas.FieldSchema; + using SchemaJsonValues = Cthangover.Mods.Schemas.SchemaJson; using System; using System.Collections.Generic; using System.Linq; @@ -11,24 +13,24 @@ namespace Cthangover.Tools.Schemas using Godot; /// - /// Edits a map field — an object whose keys are ids of + /// Edits a map field — an object whose keys are ids of /// and whose values are numbers or formulas (a character's own Stats, an archetype's /// growth): one row per key with a key picker, a value box and a remove button. A number /// is written as a number, anything else as a formula text. /// public class MapFieldEditor : ISchemaFieldEditor { - private readonly FieldSchema field; + private readonly SchemaFieldDefinition field; private readonly Action changed; private readonly VBoxContainer lines; private readonly List<(OptionButton Key, List Keys, LineEdit Value, Control Row)> rows = new(); private bool suppress; /// - public FieldSchema Field => field; + public SchemaFieldDefinition Field => field; /// Adds the editor for to . - public MapFieldEditor(Container parent, FieldSchema field, Action changed) + public MapFieldEditor(Container parent, SchemaFieldDefinition field, Action changed) { this.field = field; this.changed = changed; @@ -56,7 +58,7 @@ namespace Cthangover.Tools.Schemas if (node is JsonObject obj) { foreach (var pair in obj) - AddRow(pair.Key, SchemaJson.ToText(pair.Value)); + AddRow(pair.Key, SchemaJsonValues.ToText(pair.Value)); } suppress = false; } @@ -69,7 +71,7 @@ namespace Cthangover.Tools.Schemas { var key = row.Key.Selected >= 0 && row.Key.Selected < row.Keys.Count ? row.Keys[row.Key.Selected] : null; if (!string.IsNullOrEmpty(key) && row.Value.Text.Trim().Length > 0) - obj[key] = SchemaJson.NumberOrText(row.Value.Text.Trim()); + obj[key] = SchemaJsonValues.NumberOrText(row.Value.Text.Trim()); } return obj.Count == 0 ? null : obj; } diff --git a/src/Schemas/ScalarFieldEditor.cs b/src/Schemas/ScalarFieldEditor.cs index 390b582..babc260 100644 --- a/src/Schemas/ScalarFieldEditor.cs +++ b/src/Schemas/ScalarFieldEditor.cs @@ -1,6 +1,8 @@ namespace Cthangover.Tools.Schemas { using Cthangover.Mods.Schemas; + using SchemaFieldDefinition = Cthangover.Mods.Schemas.FieldSchema; + using SchemaJsonValues = Cthangover.Mods.Schemas.SchemaJson; using System; using System.Text.Json.Nodes; using Godot; @@ -11,18 +13,18 @@ namespace Cthangover.Tools.Schemas private readonly SchemaFieldControl control; /// Adds the row for to . - public ScalarFieldEditor(Container parent, FieldSchema field, Action changed) + public ScalarFieldEditor(Container parent, SchemaFieldDefinition field, Action changed) { control = new SchemaFieldControl(parent, field, changed); } /// - public FieldSchema Field => control.Field; + public SchemaFieldDefinition Field => control.Field; /// - public void Load(JsonNode node) => control.Value = SchemaJson.ToText(node); + public void Load(JsonNode node) => control.Value = SchemaJsonValues.ToText(node); /// - public JsonNode Save() => SchemaJson.ToNode(control.Field, control.Value); + public JsonNode Save() => SchemaJsonValues.ToNode(control.Field, control.Value); } } diff --git a/src/Schemas/SchemaFieldControl.cs b/src/Schemas/SchemaFieldControl.cs index 52ebad5..c7ae93e 100644 --- a/src/Schemas/SchemaFieldControl.cs +++ b/src/Schemas/SchemaFieldControl.cs @@ -1,6 +1,8 @@ namespace Cthangover.Tools.Schemas { using Cthangover.Mods.Schemas; + using SchemaFieldDefinition = Cthangover.Mods.Schemas.FieldSchema; + using SchemaJsonValues = Cthangover.Mods.Schemas.SchemaJson; using System; using System.Collections.Generic; using System.Linq; @@ -10,7 +12,7 @@ namespace Cthangover.Tools.Schemas using Godot; /// - /// The form control of one scalar , chosen by its type, as a + /// The form control of one scalar , chosen by its type, as a /// "label | editor" row. Everything reads and writes a text value, the way the DSL and /// most JSON fields hold it, so the palette and the data editor window share these rows: /// @@ -36,7 +38,7 @@ namespace Cthangover.Tools.Schemas private bool suppress; /// Adds the row for to ; runs on every edit. - public SchemaFieldControl(Container parent, FieldSchema field, Action changed) + public SchemaFieldControl(Container parent, SchemaFieldDefinition field, Action changed) { Field = field; this.changed = changed; @@ -97,7 +99,7 @@ namespace Cthangover.Tools.Schemas } /// The described field. - public FieldSchema Field { get; } + public SchemaFieldDefinition Field { get; } /// The editor control (the row's right part). public Control Editor { get; } diff --git a/src/Schemas/SchemaFieldEditors.cs b/src/Schemas/SchemaFieldEditors.cs index d2912ac..aeae918 100644 --- a/src/Schemas/SchemaFieldEditors.cs +++ b/src/Schemas/SchemaFieldEditors.cs @@ -2,6 +2,8 @@ namespace Cthangover.Tools.Schemas { using System; using Cthangover.Mods.Schemas; + using SchemaFieldDefinition = Cthangover.Mods.Schemas.FieldSchema; + using SchemaJsonValues = Cthangover.Mods.Schemas.SchemaJson; using Godot; /// @@ -13,7 +15,7 @@ namespace Cthangover.Tools.Schemas public static class SchemaFieldEditors { /// Adds the editor of to ; runs on every edit. - public static ISchemaFieldEditor Create(Container parent, FieldSchema field, Action changed) + public static ISchemaFieldEditor Create(Container parent, SchemaFieldDefinition field, Action changed) { switch (field.Type?.ToLowerInvariant()) {