From 921ddaf052adc9db00e671c255a9d3fbabdb2b2f Mon Sep 17 00:00:00 2001 From: Altair Wei Date: Sun, 2 Mar 2025 19:16:28 +0800 Subject: [PATCH 1/5] [Minor] Fix InjectTableDialogLocalization --- .gitignore | 3 +++ ModUtils/TableUtils/LocalizationUtils.cs | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 427ec77..fd916ee 100644 --- a/.gitignore +++ b/.gitignore @@ -365,6 +365,9 @@ FodyWeavers.xsd # Jetbrains IDE projet settings folder .idea/ +# VSCode settings +.vscode/ + # VSCode Markdown linting configuration .markdownlint.json diff --git a/ModUtils/TableUtils/LocalizationUtils.cs b/ModUtils/TableUtils/LocalizationUtils.cs index 0586ec5..c17ea15 100644 --- a/ModUtils/TableUtils/LocalizationUtils.cs +++ b/ModUtils/TableUtils/LocalizationUtils.cs @@ -256,7 +256,7 @@ public void InjectTable() } } /// -/// Abstraction for the localization of sentences found in gml_GlobalScript_table_NPC_Lines. +/// Abstraction for the localization of sentences found in gml_GlobalScript_table_lines. /// public class LocalizationSentence { @@ -387,7 +387,7 @@ private IEnumerable EditTable(IEnumerable table) { yield return line; - if (line.Contains("NPC - GREETINGS;")) + if (line.Contains("[NPC] GREETINGS;")) { foreach (LocalizationSentence sentence in Sentences) { @@ -398,14 +398,14 @@ private IEnumerable EditTable(IEnumerable table) } /// /// Browse a table with an iterator, and at a special line, for each , - /// insert a new line constructed by the dictionary in the gml_GlobalScript_table_NPC_Lines table. + /// insert a new line constructed by the dictionary in the gml_GlobalScript_table_lines table. /// /// /// public void InjectTable() { - List table = Msl.ThrowIfNull(ModLoader.GetTable("gml_GlobalScript_table_NPC_Lines")); - ModLoader.SetTable(EditTable(table).ToList(), "gml_GlobalScript_table_NPC_Lines"); + List table = Msl.ThrowIfNull(ModLoader.GetTable("gml_GlobalScript_table_lines")); + ModLoader.SetTable(EditTable(table).ToList(), "gml_GlobalScript_table_lines"); } } From 0a94644bab71328df7074185f70a71fd786e7889 Mon Sep 17 00:00:00 2001 From: Altair Wei Date: Sat, 8 Mar 2025 18:26:00 +0800 Subject: [PATCH 2/5] [Minor] Throw error when there are no matches --- Controls/ModInfos.xaml.cs | 2 +- Controls/ModSourceInfos.xaml.cs | 2 +- ModShardLauncherTest/CodeUtilsTest.cs | 61 +++++++-------------------- ModUtils/CodeUtils.cs | 19 +++++++++ 4 files changed, 36 insertions(+), 48 deletions(-) diff --git a/Controls/ModInfos.xaml.cs b/Controls/ModInfos.xaml.cs index 4154c55..7ff1e38 100644 --- a/Controls/ModInfos.xaml.cs +++ b/Controls/ModInfos.xaml.cs @@ -48,7 +48,7 @@ private async void Save_Click(object sender, EventArgs e) Main.Instance.LogModList(); Log.Error(ex, "Something went wrong"); Log.Information("Failed patching vanilla"); - MessageBox.Show(Application.Current.FindResource("SaveDataWarning").ToString()); + MessageBox.Show(ex.ToString(), Application.Current.FindResource("SaveDataWarning").ToString()); } // attempt to save the patched data diff --git a/Controls/ModSourceInfos.xaml.cs b/Controls/ModSourceInfos.xaml.cs index 9200c8a..f354dc7 100644 --- a/Controls/ModSourceInfos.xaml.cs +++ b/Controls/ModSourceInfos.xaml.cs @@ -45,7 +45,7 @@ private async void Save_Click(object sender, EventArgs e) Main.Instance.LogModList(); Log.Error(ex, "Something went wrong"); Log.Information("Failed patching vanilla"); - MessageBox.Show(Application.Current.FindResource("SaveDataWarning").ToString()); + MessageBox.Show(ex.ToString(), Application.Current.FindResource("SaveDataWarning").ToString()); } if (patchSucess) await DataLoader.DoSaveDialog(); diff --git a/ModShardLauncherTest/CodeUtilsTest.cs b/ModShardLauncherTest/CodeUtilsTest.cs index f535ac3..52464a8 100644 --- a/ModShardLauncherTest/CodeUtilsTest.cs +++ b/ModShardLauncherTest/CodeUtilsTest.cs @@ -259,20 +259,14 @@ public void MatchFrom_EmptyString_WithEmptyString() [InlineData(StringDataForTest.randomBlock)] public void MatchFrom_EmptyString_WithNonEmptyString(string input) { - // Reference - List<(Match, string)> matchStringListReference = new() - { - (Match.Before, "") - }; - // Arrange IEnumerable stringList = "".Split('\n'); // Act - IEnumerable<(Match, string)> stringList_matchFrom = stringList.MatchFrom(input); + Exception ex = Assert.Throws(() => stringList.MatchFrom(input).ToList()); // Assert - Assert.Equal(matchStringListReference, stringList_matchFrom); + Assert.Contains("MatchFrom: No matching lines found", ex.Message); } [Theory] @@ -329,21 +323,15 @@ public void MatchFrom_NonEmptyString_WithItself(string input) [InlineData(StringDataForTest.randomBlock, "aaaaaaaaaaaaaaaaaaaaaa")] public void MatchFrom_NonEmptyString_NoMatch(string input, string stringToMatch) { - // Reference - List<(Match, string)> matchStringListReference = new(); - foreach(string s in input.Split('\n')) - { - matchStringListReference.Add((Match.Before, s)); - } - // Arrange IEnumerable stringList = input.Split('\n'); // Act - IEnumerable<(Match, string)> stringList_matchFrom = stringList.MatchFrom(stringToMatch); + Exception ex = Assert.Throws(() => stringList.MatchFrom(stringToMatch).ToList()); // Assert - Assert.Equal(matchStringListReference, stringList_matchFrom); + Assert.Contains("MatchFrom: No matching lines found", ex.Message); + Assert.Contains(stringToMatch, ex.Message); } [Theory] @@ -430,21 +418,14 @@ public void MatchBelow_EmptyString_WithEmptyString() [InlineData(StringDataForTest.randomBlock)] public void MatchBelow_EmptyString_WithNonEmptyString(string input) { - // Reference - - List<(Match, string)> matchStringListReference = new() - { - (Match.Before, "") - }; - // Arrange IEnumerable stringList = "".Split('\n'); // Act - IEnumerable<(Match, string)> stringList_matchBelow = stringList.MatchBelow(input, 0); + Exception ex = Assert.Throws(() => stringList.MatchBelow(input, 0).ToList()); // Assert - Assert.Equal(matchStringListReference, stringList_matchBelow); + Assert.Contains("MatchBelow: No matching lines found", ex.Message); } [Theory] @@ -517,21 +498,15 @@ public void MatchBelow_NonEmptyString_WithItself(string input, int len) [InlineData(StringDataForTest.randomBlock, "aaaaaaaaaaaaaaaaaaaaaa", 5)] public void MatchBelow_NonEmptyString_NoMatch(string input, string stringToMatch, int len) { - // Reference - List<(Match, string)> matchStringListReference = new(); - foreach(string s in input.Split('\n')) - { - matchStringListReference.Add((Match.Before, s)); - } - // Arrange IEnumerable stringList = input.Split('\n'); // Act - IEnumerable<(Match, string)> stringList_matchBelow = stringList.MatchBelow(stringToMatch, len); + Exception ex = Assert.Throws(() => stringList.MatchBelow(stringToMatch, len).ToList()); // Assert - Assert.Equal(matchStringListReference, stringList_matchBelow); + Assert.Contains("MatchBelow: No matching lines found", ex.Message); + Assert.Contains(stringToMatch, ex.Message); } [Theory] @@ -617,21 +592,14 @@ public void MatchFromUntil_EmptyString_FromEmptyStringUntilEmptyString() [InlineData(StringDataForTest.randomBlock)] public void MatchFromUntil_EmptyString_FromNonEmptyStringUntilEmptyString(string input) { - // Reference - - List<(Match, string)> matchStringListReference = new() - { - (Match.Before, "") - }; - // Arrange IEnumerable stringList = "".Split('\n'); // Act - IEnumerable<(Match, string)> stringList_matchFromUntil = stringList.MatchFromUntil(input, ""); + Exception ex = Assert.Throws(() => stringList.MatchFromUntil(input, "").ToList()); // Assert - Assert.Equal(matchStringListReference, stringList_matchFromUntil); + Assert.Contains("MatchFrom: No matching lines found", ex.Message); } [Theory] @@ -651,10 +619,11 @@ public void MatchFromUntil_FromNoMatch_UntilEmptyString(string input, string fro IEnumerable stringList = input.Split('\n'); // Act - IEnumerable<(Match, string)> stringList_matchFromUntil = stringList.MatchFromUntil(from, ""); + Exception ex = Assert.Throws(() => stringList.MatchFromUntil(from, "").ToList()); // Assert - Assert.Equal(matchStringListReference, stringList_matchFromUntil); + Assert.Contains("MatchFrom: No matching lines found", ex.Message); + Assert.Contains(from, ex.Message); } [Theory] diff --git a/ModUtils/CodeUtils.cs b/ModUtils/CodeUtils.cs index 256f3f1..689f7af 100644 --- a/ModUtils/CodeUtils.cs +++ b/ModUtils/CodeUtils.cs @@ -438,6 +438,7 @@ public static string Collect(this FileEnumerable<(Match, string)> fe) /// public static IEnumerable<(Match, string)> MatchFrom(this IEnumerable ienumerable, IEnumerable other) { + bool foundMatch = false; Match m = Match.Before; string? otherString = null; IEnumerator otherEnumerator = other.GetEnumerator(); @@ -449,6 +450,7 @@ public static string Collect(this FileEnumerable<(Match, string)> fe) if (m != Match.After && otherString != null && element.Contains(otherString)) { m = Match.Matching; + foundMatch = true; yield return (m, element); if (otherEnumerator.MoveNext()) otherString = otherEnumerator.Current; @@ -465,6 +467,11 @@ public static string Collect(this FileEnumerable<(Match, string)> fe) yield return (m, element); } } + + if (!foundMatch) + { + throw new Exception("MatchFrom: No matching lines found. Items to match: " + string.Join(", ", other)); + } } /// @@ -539,6 +546,11 @@ public static string Collect(this FileEnumerable<(Match, string)> fe) yield return (Match.After, element); } } + + if (!encounteredTheBlock) + { + throw new Exception("MatchBelow: No matching lines found. Items to match: " + string.Join("\r\n", other)); + } } /// /// Same behaviour as but using .Split('\n') for the comparison. @@ -641,6 +653,13 @@ public static string Collect(this FileEnumerable<(Match, string)> fe) yield return (Match.After, element); } } + + /* + if (!foundUntil) + { + throw new Exception("MatchFromUntil: No matching lines found. Items to match: " + string.Join(", ", otheruntil)); + } + */ } /// /// Same behaviour as but using .Split('\n') and .Split('\n') for the comparison. From af30e486d64813f3e48fc934b82b4d55ce2cc785 Mon Sep 17 00:00:00 2001 From: Altair Wei Date: Tue, 18 Mar 2025 15:20:11 +0800 Subject: [PATCH 3/5] [Minor] Fix UIComponentType.Slider --- ModUtils/ModMenuUtils.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ModUtils/ModMenuUtils.cs b/ModUtils/ModMenuUtils.cs index 27d2aec..ae5f6ab 100644 --- a/ModUtils/ModMenuUtils.cs +++ b/ModUtils/ModMenuUtils.cs @@ -133,26 +133,27 @@ private static void AddDropDown(string associatedGlobal, string[] dropDownValues } private static void AddSlider(string associatedGlobal, (int, int) sliderValues, int defaultValue, string sectionName, int index) { - UndertaleGameObject slider = Msl.AddObject($"o_msl_component_{index}", "s_music_slide", "o_music_slider", isVisible:true, isAwake:true); + UndertaleGameObject slider = Msl.AddObject($"o_msl_component_{index}", "s_music_slide", "o_slider", isVisible:true, isAwake:true); Msl.AddNewEvent( slider, @$"ini_open(""msl_menu_mod.ini""); global.{associatedGlobal} = math_round(ini_read_real(""{sectionName}"", ""{associatedGlobal}"", {defaultValue})) ini_close(); -target = scr_convertToNewRange(global.{associatedGlobal}, 0, 1, {sliderValues.Item1}, {sliderValues.Item2}) event_inherited() +positionPercent = scr_convertToNewRange(global.{associatedGlobal}, 0, 1, {sliderValues.Item1}, {sliderValues.Item2}) valueMin = {sliderValues.Item1} valueMax = {sliderValues.Item2} scr_guiInteractiveStateUpdate(id, 14, 25) -scr_guiPositionOffsetUpdate(id, scr_convertToNewRange(target, positionMin, positionMax, 0, 1)) +scr_guiPositionOffsetUpdate(id, scr_convertToNewRange(positionPercent, positionMin, positionMax, 0, 1)) scr_guiLayoutOffsetUpdate(id, 0, -2)", EventType.Create, 0 ); - Msl.AddNewEvent(slider, $"global.{associatedGlobal} = math_round(scr_convertToNewRange(target, valueMin, valueMax, 0, 1))", EventType.Other, 10); - Msl.AddNewEvent(slider, @"with (guiParent) + Msl.AddNewEvent(slider, $"global.{associatedGlobal} = math_round(scr_convertToNewRange(positionPercent, valueMin, valueMax, 0, 1))", EventType.Other, 10); + Msl.AddNewEvent(slider, @"event_inherited() +with (guiParent) { -valueLeft = math_round(scr_convertToNewRange(other.target, other.valueMin, other.valueMax, 0, 1)) + valueLeft = math_round(scr_convertToNewRange(other.positionPercent, other.valueMin, other.valueMax, 0, 1)) }", EventType.Other, 11); @@ -226,7 +227,7 @@ internal static void CreateMenu(List menus) {{ slider = scr_guiCreateInteractive(id, o_msl_component_{index}, (depth - 1)) valueRight = {component.SliderValues.Item2} - valueLeft = scr_convertToNewRange(slider.target, {component.SliderValues.Item1}, {component.SliderValues.Item2}, 0, 1) + valueLeft = scr_convertToNewRange(slider.positionPercent, {component.SliderValues.Item1}, {component.SliderValues.Item2}, 0, 1) }}"; injectedOther12 += $"\nini_write_real(\"{m.Name}\", \"{component.AssociatedGlobal}\", global.{component.AssociatedGlobal})"; injectedOther13 += $"\nglobal.{component.AssociatedGlobal} = math_round(ini_read_real(\"{m.Name}\", \"{component.AssociatedGlobal}\", {component.DefaultValue}))"; @@ -282,7 +283,7 @@ internal static void CreateMenu(List menus) {{ event_user(1) }} -with (o_music_slider) +with (o_slider) {{ event_user(0) }} From 9433dfc7e35d7f08f3e75b2ac87aac440b01e049 Mon Sep 17 00:00:00 2001 From: Altair Wei Date: Tue, 18 Mar 2025 15:22:18 +0800 Subject: [PATCH 4/5] [Minor] Fix InjectTableItemLocalization --- ModUtils/TableUtils/LocalizationUtils.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ModUtils/TableUtils/LocalizationUtils.cs b/ModUtils/TableUtils/LocalizationUtils.cs index c17ea15..8a07410 100644 --- a/ModUtils/TableUtils/LocalizationUtils.cs +++ b/ModUtils/TableUtils/LocalizationUtils.cs @@ -113,7 +113,7 @@ static public Dictionary SetDictionary(string source) } } /// -/// Abstraction the localization of items found in gml_GlobalScript_table_consumables. +/// Abstraction the localization of items found in gml_GlobalScript_table_items. /// public class LocalizationItem { @@ -217,7 +217,7 @@ static private string CreateLine(string oName, Dictionary d line += ";"; line += kp.Value; } - return line + ";//;"; + return line + ";"; } /// /// Browse a table with an iterator, and at special lines, yield a new line constructed by the dictionaries , and . @@ -251,8 +251,8 @@ private IEnumerable EditTable(IEnumerable table) /// public void InjectTable() { - List table = Msl.ThrowIfNull(ModLoader.GetTable("gml_GlobalScript_table_consumables")); - ModLoader.SetTable(EditTable(table).ToList(), "gml_GlobalScript_table_consumables"); + List table = Msl.ThrowIfNull(ModLoader.GetTable("gml_GlobalScript_table_items")); + ModLoader.SetTable(EditTable(table).ToList(), "gml_GlobalScript_table_items"); } } /// From e4907937f601c1359232f6b6a5c803ee654ccf96 Mon Sep 17 00:00:00 2001 From: Altair Wei Date: Wed, 19 Mar 2025 13:17:44 +0800 Subject: [PATCH 5/5] [Minor] Fix CreateLineLocalizationItemTest --- ModShardLauncherTest/LocalizationUtilsTest.cs | 2 +- ModUtils/TableUtils/LocalizationUtils.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ModShardLauncherTest/LocalizationUtilsTest.cs b/ModShardLauncherTest/LocalizationUtilsTest.cs index 861a406..3919ab5 100644 --- a/ModShardLauncherTest/LocalizationUtilsTest.cs +++ b/ModShardLauncherTest/LocalizationUtilsTest.cs @@ -161,7 +161,7 @@ public class CreateLineLocalizationItemTest public void CreateLine() { // Arrange - string expectedResult = "testItem;testRu;testEn;testCh;testGe;testSp;testFr;testIt;testPr;testPl;testTu;testJp;testKr;//;"; + string expectedResult = "testItem;testRu;testEn;testCh;testGe;testSp;testFr;testIt;testPr;testPl;testTu;testJp;testKr;"; Dictionary input = new() { {ModLanguage.Russian, "testRu"}, {ModLanguage.English, "testEn"}, {ModLanguage.Chinese, "testCh"}, {ModLanguage.German, "testGe"}, {ModLanguage.Spanish, "testSp"}, diff --git a/ModUtils/TableUtils/LocalizationUtils.cs b/ModUtils/TableUtils/LocalizationUtils.cs index 8a07410..785d94d 100644 --- a/ModUtils/TableUtils/LocalizationUtils.cs +++ b/ModUtils/TableUtils/LocalizationUtils.cs @@ -203,7 +203,7 @@ public LocalizationItem(string oName, string valuesName, string valuesID, string /// CreateLine("testItem", new Dictionary < ModLanguage, string > () {{Russian, "testRu"}, {English, "testEn"}, {Chinese, "testCh"}, {German, "testGe"}, {Spanish, "testSp"}, /// {French, "testFr"}, {Italian, "testIt"}, {Portuguese, "testPr"}, {Polish, "testPl"}, {Turkish, "testTu"}, {Japanese, "testJp"}, {Korean, "testKr"}} ); /// - /// returns the string "testItem;testRu;testEn;testCh;testGe;testSp;testFr;testIt;testPr;testPl;testTu;testJp;testKr;//;". + /// returns the string "testItem;testRu;testEn;testCh;testGe;testSp;testFr;testIt;testPr;testPl;testTu;testJp;testKr;". /// /// ///