diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index f85721dd2..374ada130 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -35,6 +35,7 @@ RequirePlayerSettingsEveSurface(root); RequireMainMenuContinueRunState(root); RequirePropertiesPanelReadOnlyInspector(root); RequireTypedBehaviorMetadataCoverage(root); +RequireNameToolsUsesUiToolkit(root); RequireNoDeadRuntimeProjectionCaches(root); RequireNoDeadInspectorMetadata(root); RequireRuntimeSimulationTuningCommits(root); @@ -495,6 +496,7 @@ Console.WriteLine("Main-menu settings authority: player name, gameplay, and grap Console.WriteLine("Main-menu Continue authority: Continue selects typed run state instead of a null button"); Console.WriteLine("PropertiesPanel inspector authority: dead generic reflection inspector path is deleted"); Console.WriteLine("Typed behavior metadata authority: live heat/mining/thermotoggle payload kinds stay owned by package metadata"); +Console.WriteLine("NameTools editor shell: the remaining name helper window lowers through UI Toolkit instead of IMGUI"); Console.WriteLine("Runtime simulation tuning authority: UI writes flow through gameplay checkpoint commits"); Console.WriteLine("Hull conductivity authority: inventory UI toggles flow through gameplay checkpoint commits"); Console.WriteLine("Inventory entity rename authority: UI rename flows through gameplay checkpoint commits"); @@ -2726,6 +2728,56 @@ static void RequireTypedBehaviorMetadataCoverage(string root) } } +static void RequireNameToolsUsesUiToolkit(string root) +{ + var nameToolsPath = Path.Combine(root, "Assets", "Scripts", "Editor", "NameTools.cs"); + var source = File.Exists(nameToolsPath) + ? File.ReadAllText(nameToolsPath) + : throw new InvalidOperationException("Cannot verify NameTools editor shell; NameTools.cs is missing."); + + var requiredSymbols = new[] + { + "using UnityEditor.UIElements;", + "using UnityEngine.UIElements;", + "private void CreateGUI()", + "new ObjectField(\"Name File\")", + "new IntegerField(", + "new Toggle(\"Strip Number Tokens\")", + "new Button(CleanNameFile)", + "new Button(ProcessNameFile)", + "new Button(GenerateName)" + }; + + var missingSymbols = requiredSymbols + .Where(symbol => !source.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + + if (missingSymbols.Length > 0) + { + throw new InvalidOperationException( + "NameTools no longer owns a UI Toolkit editor shell for the remaining name helper workflow: " + + string.Join(", ", missingSymbols)); + } + + var forbiddenSymbols = new[] + { + "void OnGUI()", + "EditorGUILayout.", + "GUILayout." + }; + + var hits = forbiddenSymbols + .Where(symbol => source.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + + if (hits.Length > 0) + { + throw new InvalidOperationException( + "NameTools should not regress to IMGUI editor widgets: " + + string.Join(", ", hits)); + } +} + static void RequireRuntimeSimulationTuningCommits(string root) { var requiredActionGameManagerPath = Path.Combine(root, "Assets", "Scripts", "Gameplay", "ActionGameManager.cs"); diff --git a/Assets/Scripts/Editor/NameTools.cs b/Assets/Scripts/Editor/NameTools.cs index eea72b4fe..909b2f631 100644 --- a/Assets/Scripts/Editor/NameTools.cs +++ b/Assets/Scripts/Editor/NameTools.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; using Unity.Mathematics; -using UnityEngine; using UnityEditor; +using UnityEditor.UIElements; +using UnityEngine; +using UnityEngine.UIElements; using Random = Unity.Mathematics.Random; public class NameTools : EditorWindow @@ -11,79 +13,184 @@ public class NameTools : EditorWindow public int NameGeneratorMinLength = 5; public int NameGeneratorMaxLength = 10; public int NameGeneratorOrder = 4; - private int minWordLength = 4; - private TextAsset nameFile; + + private int _minWordLength = 4; + private TextAsset _nameFile; private MarkovNameGenerator _nameGenerator; private bool _stripNumberTokens; + private Button _generateNameButton; + private Label _statusLabel; - - // Add menu named "My Window" to the Window menu [MenuItem("Window/Aetheria/Name Tools")] - static void Init() + private static void Init() { - // Get existing open window or if none, make a new one: - NameTools window = (NameTools)EditorWindow.GetWindow(typeof(NameTools)); + var window = GetWindow(); + window.titleContent = new GUIContent("Name Tools"); window.Show(); } - - bool HasNonASCIIChars(string str) + + private void CreateGUI() { - return (System.Text.Encoding.UTF8.GetByteCount(str) != str.Length); + var root = rootVisualElement; + root.Clear(); + root.style.paddingLeft = 12; + root.style.paddingRight = 12; + root.style.paddingTop = 12; + root.style.paddingBottom = 12; + root.style.flexDirection = FlexDirection.Column; + + var nameFileField = new ObjectField("Name File") + { + objectType = typeof(TextAsset), + allowSceneObjects = false, + value = _nameFile + }; + nameFileField.RegisterValueChangedCallback(evt => _nameFile = evt.newValue as TextAsset); + root.Add(nameFileField); + + root.Add(CreateIntegerField("Minimum File Word Length", _minWordLength, value => _minWordLength = value)); + root.Add(CreateIntegerField("Generated Minimum Word Length", NameGeneratorMinLength, value => NameGeneratorMinLength = value)); + root.Add(CreateIntegerField("Generated Maximum Word Length", NameGeneratorMaxLength, value => NameGeneratorMaxLength = value)); + root.Add(CreateIntegerField("Generator Order", NameGeneratorOrder, value => NameGeneratorOrder = value)); + + var stripNumbersField = new Toggle("Strip Number Tokens") + { + value = _stripNumberTokens + }; + stripNumbersField.RegisterValueChangedCallback(evt => _stripNumberTokens = evt.newValue); + root.Add(stripNumbersField); + + var cleanButton = new Button(CleanNameFile) + { + text = "Clean Name File" + }; + root.Add(cleanButton); + + var processButton = new Button(ProcessNameFile) + { + text = "Process Name File" + }; + root.Add(processButton); + + _generateNameButton = new Button(GenerateName) + { + text = "Generate Name" + }; + root.Add(_generateNameButton); + + _statusLabel = new Label(); + _statusLabel.style.unityFontStyleAndWeight = FontStyle.Italic; + _statusLabel.style.marginTop = 8; + root.Add(_statusLabel); + + RefreshUiState(); } - void OnGUI() + private IntegerField CreateIntegerField(string label, int value, System.Action onChanged) { - nameFile = (TextAsset) EditorGUILayout.ObjectField("Name File", nameFile, typeof(TextAsset), false); - minWordLength = EditorGUILayout.IntField("Minimum File Word Length", minWordLength); - NameGeneratorMinLength = EditorGUILayout.IntField("Generated Minimum Word Length", NameGeneratorMinLength); - NameGeneratorMaxLength = EditorGUILayout.IntField("Generated Maximum Word Length", NameGeneratorMaxLength); - NameGeneratorOrder = EditorGUILayout.IntField("Generator Order", NameGeneratorOrder); - _stripNumberTokens = GUILayout.Toggle(_stripNumberTokens, "Strip Number Tokens"); - - if (GUILayout.Button("Clean Name File")) + var field = new IntegerField(label) { - var lines = nameFile.text.Split('\n'); - using StreamWriter outputFile = new StreamWriter(Path.Combine(Application.dataPath, nameFile.name + ".csv")); - var names = new HashSet(); - foreach (var line in lines) + value = value + }; + field.RegisterValueChangedCallback(evt => onChanged(evt.newValue)); + return field; + } + + private void CleanNameFile() + { + if (_nameFile == null) + { + SetStatus("Pick a name file first."); + return; + } + + var lines = _nameFile.text.Split('\n'); + var outputPath = Path.Combine(Application.dataPath, _nameFile.name + ".csv"); + using var outputFile = new StreamWriter(outputPath); + var names = new HashSet(); + foreach (var line in lines) + { + var tokens = line.Split(',', ' '); + foreach (var token in tokens) { - var tokens = line.Split(',', ' '); - foreach (var t in tokens) - { - if (!HasNonASCIIChars(t)) - { - var s = new string(t.Where(c => char.IsLetter(c) || c == '-' || c == '`' || c == '\'').ToArray()).Trim().Trim('`','-'); - if(s.Length >= minWordLength && !names.Contains(s)) - { - names.Add(s); - outputFile.WriteLine(s); - } - } - } + if (HasNonAsciiChars(token)) + continue; + + var cleaned = new string(token + .Where(ch => char.IsLetter(ch) || ch == '-' || ch == '`' || ch == '\'') + .ToArray()) + .Trim() + .Trim('`', '-'); + + if (_stripNumberTokens && cleaned.Any(char.IsDigit)) + continue; + + if (cleaned.Length < _minWordLength || !names.Add(cleaned)) + continue; + + outputFile.WriteLine(cleaned); } } - if (GUILayout.Button("Process Name File") && nameFile != null) + AssetDatabase.Refresh(); + SetStatus($"Wrote {names.Count} cleaned names to {Path.GetFileName(outputPath)}."); + } + + private void ProcessNameFile() + { + if (_nameFile == null) { - var names = new HashSet(); - var lines = nameFile.text.Split('\n'); - foreach (var line in lines) - { - foreach(var word in line.ToUpperInvariant().Split(' ', ',', '.', '"')) - if (word.Length >= minWordLength && !names.Contains(word)) - names.Add(word); - } - Debug.Log($"Found {lines.Length} lines, with {names.Count} unique names!"); - var random = new Random(1337); - _nameGenerator = new MarkovNameGenerator(ref random, names, NameGeneratorOrder, NameGeneratorMinLength, NameGeneratorMaxLength); + SetStatus("Pick a name file first."); + return; } - if (_nameGenerator != null) + var names = new HashSet(); + var lines = _nameFile.text.Split('\n'); + foreach (var line in lines) { - if (GUILayout.Button("Generate Name")) + foreach (var word in line.ToUpperInvariant().Split(' ', ',', '.', '"')) { - Debug.Log(_nameGenerator.NextName); + if (_stripNumberTokens && word.Any(char.IsDigit)) + continue; + + if (word.Length >= _minWordLength) + names.Add(word); } } + + Debug.Log($"Found {lines.Length} lines, with {names.Count} unique names!"); + var random = new Random(1337); + _nameGenerator = new MarkovNameGenerator(ref random, names, NameGeneratorOrder, NameGeneratorMinLength, NameGeneratorMaxLength); + SetStatus($"Processed {names.Count} unique names."); + RefreshUiState(); + } + + private void GenerateName() + { + if (_nameGenerator == null) + { + SetStatus("Process a name file before generating names."); + return; + } + + var generatedName = _nameGenerator.NextName; + Debug.Log(generatedName); + SetStatus($"Generated: {generatedName}"); + } + + private void RefreshUiState() + { + _generateNameButton?.SetEnabled(_nameGenerator != null); + } + + private void SetStatus(string message) + { + if (_statusLabel != null) + _statusLabel.text = message ?? ""; + } + + private static bool HasNonAsciiChars(string value) + { + return System.Text.Encoding.UTF8.GetByteCount(value ?? "") != (value ?? "").Length; } } diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index bfc559599..6ed8d1d3a 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -544,9 +544,10 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. not registered as a VoidBot Discord identity yet, so mutations use the repo-local `void-self-state.mjs apply-operation` typed boundary rather than the registered Face MCP path. -- The old IMGUI DB inspector has been deleted. `NameTools` can still - clean/generate names, but the legacy NameFile `.msgpack` export control has - been deleted instead of leaving a warning-only writer stub. The +- The old IMGUI DB inspector has been deleted. `NameTools` still + clean/generate names, but it now uses a UI Toolkit editor shell, and the + legacy NameFile `.msgpack` export control has been deleted instead of leaving + a warning-only writer stub. The remaining Unity helper files formerly under `Assets/Scripts/CultCache` now live under `Assets/Scripts/UnitySupport` because they are color/curve helpers, not cache authority.