Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ FodyWeavers.xsd
# Jetbrains IDE projet settings folder
.idea/

# VSCode settings
.vscode/

# VSCode Markdown linting configuration
.markdownlint.json

Expand Down
2 changes: 1 addition & 1 deletion Controls/ModInfos.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Controls/ModSourceInfos.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
61 changes: 15 additions & 46 deletions ModShardLauncherTest/CodeUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> stringList = "".Split('\n');

// Act
IEnumerable<(Match, string)> stringList_matchFrom = stringList.MatchFrom(input);
Exception ex = Assert.Throws<Exception>(() => stringList.MatchFrom(input).ToList());

// Assert
Assert.Equal(matchStringListReference, stringList_matchFrom);
Assert.Contains("MatchFrom: No matching lines found", ex.Message);
}

[Theory]
Expand Down Expand Up @@ -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<string> stringList = input.Split('\n');

// Act
IEnumerable<(Match, string)> stringList_matchFrom = stringList.MatchFrom(stringToMatch);
Exception ex = Assert.Throws<Exception>(() => 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]
Expand Down Expand Up @@ -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<string> stringList = "".Split('\n');

// Act
IEnumerable<(Match, string)> stringList_matchBelow = stringList.MatchBelow(input, 0);
Exception ex = Assert.Throws<Exception>(() => stringList.MatchBelow(input, 0).ToList());

// Assert
Assert.Equal(matchStringListReference, stringList_matchBelow);
Assert.Contains("MatchBelow: No matching lines found", ex.Message);
}

[Theory]
Expand Down Expand Up @@ -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<string> stringList = input.Split('\n');

// Act
IEnumerable<(Match, string)> stringList_matchBelow = stringList.MatchBelow(stringToMatch, len);
Exception ex = Assert.Throws<Exception>(() => 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]
Expand Down Expand Up @@ -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<string> stringList = "".Split('\n');

// Act
IEnumerable<(Match, string)> stringList_matchFromUntil = stringList.MatchFromUntil(input, "");
Exception ex = Assert.Throws<Exception>(() => stringList.MatchFromUntil(input, "").ToList());

// Assert
Assert.Equal(matchStringListReference, stringList_matchFromUntil);
Assert.Contains("MatchFrom: No matching lines found", ex.Message);
}

[Theory]
Expand All @@ -651,10 +619,11 @@ public void MatchFromUntil_FromNoMatch_UntilEmptyString(string input, string fro
IEnumerable<string> stringList = input.Split('\n');

// Act
IEnumerable<(Match, string)> stringList_matchFromUntil = stringList.MatchFromUntil(from, "");
Exception ex = Assert.Throws<Exception>(() => 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]
Expand Down
2 changes: 1 addition & 1 deletion ModShardLauncherTest/LocalizationUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModLanguage, string> input = new()
{
{ModLanguage.Russian, "testRu"}, {ModLanguage.English, "testEn"}, {ModLanguage.Chinese, "testCh"}, {ModLanguage.German, "testGe"}, {ModLanguage.Spanish, "testSp"},
Expand Down
19 changes: 19 additions & 0 deletions ModUtils/CodeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ public static string Collect(this FileEnumerable<(Match, string)> fe)
/// </summary>
public static IEnumerable<(Match, string)> MatchFrom(this IEnumerable<string> ienumerable, IEnumerable<string> other)
{
bool foundMatch = false;
Match m = Match.Before;
string? otherString = null;
IEnumerator<string> otherEnumerator = other.GetEnumerator();
Expand All @@ -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;
Expand All @@ -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));
}
}

/// <summary>
Expand Down Expand Up @@ -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));
}
}
/// <summary>
/// Same behaviour as <see cref="MatchBelow"/> but using <paramref name="other"/>.Split('\n') for the comparison.
Expand Down Expand Up @@ -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));
}
*/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe removing comented code

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

}
/// <summary>
/// Same behaviour as <see cref="MatchFromUntil"/> but using <paramref name="otherfrom"/>.Split('\n') and <paramref name="otheruntil"/>.Split('\n') for the comparison.
Expand Down
17 changes: 9 additions & 8 deletions ModUtils/ModMenuUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -226,7 +227,7 @@ internal static void CreateMenu(List<Menu> 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}))";
Expand Down Expand Up @@ -282,7 +283,7 @@ internal static void CreateMenu(List<Menu> menus)
{{
event_user(1)
}}
with (o_music_slider)
with (o_slider)
{{
event_user(0)
}}
Expand Down
20 changes: 10 additions & 10 deletions ModUtils/TableUtils/LocalizationUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static public Dictionary<ModLanguage, string> SetDictionary(string source)
}
}
/// <summary>
/// Abstraction the localization of items found in gml_GlobalScript_table_consumables.
/// Abstraction the localization of items found in gml_GlobalScript_table_items.
/// </summary>
public class LocalizationItem
{
Expand Down Expand Up @@ -203,7 +203,7 @@ public LocalizationItem(string oName, string valuesName, string valuesID, string
/// CreateLine("testItem", new Dictionary &lt; ModLanguage, string &gt; () {{Russian, "testRu"}, {English, "testEn"}, {Chinese, "testCh"}, {German, "testGe"}, {Spanish, "testSp"},
/// {French, "testFr"}, {Italian, "testIt"}, {Portuguese, "testPr"}, {Polish, "testPl"}, {Turkish, "testTu"}, {Japanese, "testJp"}, {Korean, "testKr"}} );
/// </code>
/// 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;".
/// </example>
/// </summary>
/// <param name="oName"></param>
Expand All @@ -217,7 +217,7 @@ static private string CreateLine(string oName, Dictionary<ModLanguage, string> d
line += ";";
line += kp.Value;
}
return line + ";//;";
return line + ";";
}
/// <summary>
/// Browse a table with an iterator, and at special lines, yield a new line constructed by the dictionaries <see cref="ConsumableName"/>, <see cref="ConsumableID"/> and <see cref="ConsumableDescription"/>.
Expand Down Expand Up @@ -251,12 +251,12 @@ private IEnumerable<string> EditTable(IEnumerable<string> table)
/// <returns></returns>
public void InjectTable()
{
List<string> table = Msl.ThrowIfNull(ModLoader.GetTable("gml_GlobalScript_table_consumables"));
ModLoader.SetTable(EditTable(table).ToList(), "gml_GlobalScript_table_consumables");
List<string> table = Msl.ThrowIfNull(ModLoader.GetTable("gml_GlobalScript_table_items"));
ModLoader.SetTable(EditTable(table).ToList(), "gml_GlobalScript_table_items");
}
}
/// <summary>
/// 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.
/// </summary>
public class LocalizationSentence
{
Expand Down Expand Up @@ -387,7 +387,7 @@ private IEnumerable<string> EditTable(IEnumerable<string> table)
{
yield return line;

if (line.Contains("NPC - GREETINGS;"))
if (line.Contains("[NPC] GREETINGS;"))
{
foreach (LocalizationSentence sentence in Sentences)
{
Expand All @@ -398,14 +398,14 @@ private IEnumerable<string> EditTable(IEnumerable<string> table)
}
/// <summary>
/// Browse a table with an iterator, and at a special line, for each <see cref="LocalizationSentence"/>,
/// insert a new line constructed by the dictionary <see cref="Sentence"/> in the gml_GlobalScript_table_NPC_Lines table.
/// insert a new line constructed by the dictionary <see cref="Sentence"/> in the gml_GlobalScript_table_lines table.
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public void InjectTable()
{
List<string> table = Msl.ThrowIfNull(ModLoader.GetTable("gml_GlobalScript_table_NPC_Lines"));
ModLoader.SetTable(EditTable(table).ToList(), "gml_GlobalScript_table_NPC_Lines");
List<string> table = Msl.ThrowIfNull(ModLoader.GetTable("gml_GlobalScript_table_lines"));
ModLoader.SetTable(EditTable(table).ToList(), "gml_GlobalScript_table_lines");
}
}

Expand Down
Loading