From 922d38ee514183a4d08aa571c35145931a4c20e8 Mon Sep 17 00:00:00 2001 From: Daniel Cumbor Date: Sun, 13 Jul 2025 19:43:32 +0100 Subject: [PATCH] Reupload to git vps. --- Editor.meta | 8 ++ Editor/DictionaryProcessorWindow.cs | 126 +++++++++++++++++++++++ Editor/DictionaryProcessorWindow.cs.meta | 2 + package.json | 13 +++ package.json.meta | 7 ++ 5 files changed, 156 insertions(+) create mode 100644 Editor.meta create mode 100644 Editor/DictionaryProcessorWindow.cs create mode 100644 Editor/DictionaryProcessorWindow.cs.meta create mode 100644 package.json create mode 100644 package.json.meta diff --git a/Editor.meta b/Editor.meta new file mode 100644 index 0000000..a640e84 --- /dev/null +++ b/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1ef57e1dadf599b4ba71061a638fd258 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/DictionaryProcessorWindow.cs b/Editor/DictionaryProcessorWindow.cs new file mode 100644 index 0000000..d2cdecd --- /dev/null +++ b/Editor/DictionaryProcessorWindow.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using UnityEditor; +using UnityEngine; + +public class DictionaryProcessorWindow : EditorWindow +{ + private int _filteredWordCount; + private int _maxWordLength = 6; + private int _minWordLength = 3; + private int _originalWordCount; + private string _outputFileName = "FilteredDictionary"; + private string _previewText = ""; + private Vector2 _scrollPosition; + private TextAsset _sourceFile; + + private void OnGUI() + { + GUILayout.Label("Dictionary Processing Tool", EditorStyles.boldLabel); + + EditorGUILayout.Space(); + + _sourceFile = (TextAsset)EditorGUILayout.ObjectField("Source Dictionary", + _sourceFile, typeof(TextAsset), false); + + EditorGUILayout.Space(); + + GUILayout.Label("Filtering Options", EditorStyles.boldLabel); + _minWordLength = EditorGUILayout.IntSlider("Min Word Length", _minWordLength, 1, 10); + _maxWordLength = EditorGUILayout.IntSlider("Max Word Length", _maxWordLength, 1, 15); + + EditorGUILayout.Space(); + + GUILayout.Label("Output Settings", EditorStyles.boldLabel); + _outputFileName = EditorGUILayout.TextField("Output File Name", _outputFileName); + + EditorGUILayout.Space(); + + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("Preview")) PreviewFiltering(); + + GUI.enabled = _sourceFile; + if (GUILayout.Button("Process & Save")) ProcessAndSave(); + GUI.enabled = true; + EditorGUILayout.EndHorizontal(); + + if (_originalWordCount > 0) + { + EditorGUILayout.Space(); + EditorGUILayout.LabelField($"Original: {_originalWordCount:N0} words"); + EditorGUILayout.LabelField( + $"Filtered: {_filteredWordCount:N0} words ({(float)_filteredWordCount / _originalWordCount * 100:F1}% kept)"); + } + + if (!string.IsNullOrEmpty(_previewText)) + { + EditorGUILayout.Space(); + GUILayout.Label("Preview (first 50 words):", EditorStyles.boldLabel); + _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, GUILayout.Height(200)); + EditorGUILayout.TextArea(_previewText, GUILayout.ExpandHeight(true)); + EditorGUILayout.EndScrollView(); + } + } + + [MenuItem("Tools/Dictionary Processor")] + public static void ShowWindow() + { + GetWindow("Dictionary Processor"); + } + + private void PreviewFiltering() + { + if (!_sourceFile) return; + + var filteredWords = ProcessWords(_sourceFile.text); + _originalWordCount = _sourceFile.text.Split('\n').Length; + _filteredWordCount = filteredWords.Count; + + _previewText = string.Join("\n", filteredWords.Take(50)); + if (filteredWords.Count > 50) + _previewText += $"\n... and {filteredWords.Count - 50} more words"; + } + + private void ProcessAndSave() + { + if (!_sourceFile) return; + + var filteredWords = ProcessWords(_sourceFile.text); + + var outputPath = Path.Combine(Application.dataPath, "StreamingAssets", $"{_outputFileName}.txt"); + + Directory.CreateDirectory(Path.GetDirectoryName(outputPath) ?? throw new NullReferenceException("Invalid path")); + + File.WriteAllText(outputPath, string.Join("\n", filteredWords)); + + AssetDatabase.Refresh(); + + Debug.Log($"Dictionary processed! {filteredWords.Count} words saved to: {outputPath}"); + + _originalWordCount = _sourceFile.text.Split('\n').Length; + _filteredWordCount = filteredWords.Count; + } + + private List ProcessWords(string text) + { + var words = text.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + var filteredWords = new List(); + + foreach (var rawWord in words) + { + var word = rawWord.Trim().ToLowerInvariant(); + + if (word.Length < _minWordLength || word.Length > _maxWordLength) + continue; + + if (!Regex.IsMatch(word, @"^[a-z]+$")) + continue; + + filteredWords.Add(word); + } + return filteredWords.Distinct().OrderBy(w => w).ToList(); + } +} \ No newline at end of file diff --git a/Editor/DictionaryProcessorWindow.cs.meta b/Editor/DictionaryProcessorWindow.cs.meta new file mode 100644 index 0000000..fa08c48 --- /dev/null +++ b/Editor/DictionaryProcessorWindow.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: a7ebd227f3b8fbb4b9723d3f17cc1c43 \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..3f2715f --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "com.danielcumbor.dictionaryprocessor", + "version": "1.0.0", + "displayName": "DC Dictionary Processor", + "description": "A custom Unity tool window for filtering dictionaries.", + "unity": "6000.0", + "unityRelease": "23f1", + "author": { + "name": "Daniel Cumbor", + "email": "danc@ultr.uk", + "url": "https://www.danielcumbor.uk" + } +} \ No newline at end of file diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..d2c8cdf --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 71f47fb424c5a4e45a5a8bdb452ac2fa +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: