From ccc66fe967ce69316f4d39a0817c5584fcc61bbf Mon Sep 17 00:00:00 2001 From: Assistant Date: Sun, 24 Jan 2021 13:57:29 -0700 Subject: [PATCH] Sort mods for better detection (doesn't work) Will sort mods prioritizing approval status, game version matching, and version, in that order. Hasn't been tested because BeatMods is BeatMods. Doesn't work because BeatMods is BeatMods. Probably very slow, but it's "modular" and any "module" can be comment'd out for speed improvements. --- ModAssistant/Pages/Mods.xaml.cs | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/ModAssistant/Pages/Mods.xaml.cs b/ModAssistant/Pages/Mods.xaml.cs index 827dc3c..0d3ba66 100644 --- a/ModAssistant/Pages/Mods.xaml.cs +++ b/ModAssistant/Pages/Mods.xaml.cs @@ -164,6 +164,59 @@ namespace ModAssistant.Pages var resp = await HttpClient.GetAsync(Utils.Constants.BeatModsAPIUrl + "mod"); var body = await resp.Content.ReadAsStringAsync(); AllModsList = JsonSerializer.Deserialize(body); + Array.Sort(AllModsList, new ModSorter()); + } + + public class ModSorter : IComparer + { + int IComparer.Compare(Mod x, Mod y) + { + int xValue = GetStatusValue(x.status) * 10000; + int yValue = GetStatusValue(y.status) * 10000; + + xValue += GetGameVersionValue(x.gameVersion) * 1000; + yValue += GetGameVersionValue(y.gameVersion) * 1000; + + int[] versionValues = GetVersionValues(x.version, y.version); + xValue += versionValues[0]; + yValue += versionValues[1]; + + return yValue - xValue; + } + } + + static int GetStatusValue(string status) + { + if (status == "approved") return 3; + if (status == "pending") return 2; + if (status == "inactive") return 1; + return 0; + } + + static int GetGameVersionValue(string gameVersion) + { + if (gameVersion == MainWindow.GameVersion) return 1; + return 0; + } + + static int[] GetVersionValues(string xVersion, string yVersion) + { + int x = 0; + int y = 0; + string[] xVersions = xVersion.Split('.'); + string[] yVersions = yVersion.Split('.'); + int xMajor = int.Parse(xVersions[0]); + int xMinor = int.Parse(xVersions[1]); + int xPatch = int.Parse(xVersions[2]); + int yMajor = int.Parse(yVersions[0]); + int yMinor = int.Parse(yVersions[1]); + int yPatch = int.Parse(yVersions[2]); + + if (xMajor != yMajor) (xMajor > yMajor ? ref x : ref y) += 100; + if (xMinor != yMinor) (xMinor > yMinor ? ref x : ref y) += 10; + if (xPatch != yPatch) (xPatch > yPatch ? ref x : ref y) += 1; + + return new int[]{x, y}; } private void CheckInstallDir(string directory)