From d6b2cd933e8dcc4949d3298173c914c8a01fff01 Mon Sep 17 00:00:00 2001 From: SabreML <57483089+SabreML@users.noreply.github.com> Date: Thu, 9 Mar 2023 21:28:25 +0000 Subject: [PATCH] Name fix Considering it's the whole point of the mod, you'd think this should have worked properly to begin with. :sweat_smile: --- CollectionLabels/modinfo.json | 4 ++-- src/CollectionLabelsMod.cs | 42 ++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/CollectionLabels/modinfo.json b/CollectionLabels/modinfo.json index 40b265b..4eb45f1 100644 --- a/CollectionLabels/modinfo.json +++ b/CollectionLabels/modinfo.json @@ -1,10 +1,10 @@ { "id": "sabreml.collectionlabels", "name": "Collection Labels", - "version": "1.0.0", + "version": "1.0.1", "target_game_version": "v1.9.06", "authors": "SabreML", - "description": "Adds a name/location to each item in the Collections menu.(Warning: May contain light spoilers for region names and collectibles!)", + "description": "Adds a name/location to each item in the Collections menu, for spoiler-free collectible hunting!", "requirements": ["moreslugcats"], "requirements_names": ["More Slugcats Expansion"], "tags": ["Cosmetics"] diff --git a/src/CollectionLabelsMod.cs b/src/CollectionLabelsMod.cs index 219794c..f817a3c 100644 --- a/src/CollectionLabelsMod.cs +++ b/src/CollectionLabelsMod.cs @@ -12,7 +12,7 @@ namespace CollectionLabels { - [BepInPlugin("sabreml.collectionlabels", "CollectionLabels", "1.0.0")] + [BepInPlugin("sabreml.collectionlabels", "CollectionLabels", "1.0.1")] public class CollectionLabelsMod : BaseUnityPlugin { // A list of pearl names/locations. (E.g. "[Shoreline pearl 1]", "[Chimney Canopy pearl]", etc.) @@ -71,13 +71,14 @@ private void LoadPearlNames(CollectionsMenu self) foreach (DataPearl.AbstractDataPearl.DataPearlType pearlType in self.usedPearlTypes) { // The region this pearl is found in. ("SL_moon" > "SL" > "Shoreline") - // (Unless it's the music pearl or a scug starting pearl, then it gets set manually.) + // (Some like the music pearl or scug starting pearls are set manually.) string pearlName = pearlType.value switch { "RM" => "Music", "Red_stomach" => "Hunter", "Spearmasterpearl" => "Spearmaster", "Rivulet_stomach" => "Rivulet", + "MS" => "Garbage Wastes", // Interestingly, this one seems to be mislabeled in the game's code. (It appears in GW, not MS) _ => Region.GetRegionFullName(pearlType.value.Split('_')[0], null) }; @@ -112,23 +113,28 @@ private void LoadChatlogNames(CollectionsMenu self) private static List FormatListDuplicates(List inputList) { - return inputList - .GroupBy(x => x) // Create groups of each distinct name. - .SelectMany(g => g.Select((name, index) => - // Go through each item name in each group (and grab the index of the name too). + List outputList = new(); + foreach (string name in inputList) + { + // The number of times this entry name has occurs in `inputList`. + int inputListOccurrences = inputList.Count(x => x == name); + // The number of times an entry *containing* this name occurs in `outputList`. (The name is modified so just `==` won't work.) + int outputListOccurrences = outputList.Count(x => x.Contains(name)); + + // If there's more than 1 pearl/chatlog with this name, append a number onto the end. + // This changes ("[Shoreline pearl", "[Shoreline pearl") into ("[Shoreline pearl 1]", "[Shoreline pearl 2]") + if (inputListOccurrences > 1) + { + outputList.Add($"{name} {outputListOccurrences + 1}]"); + } + // Otherwise, just leave it as-is and add the closing bracket. + else { - if (g.Count() > 1) - { - // If there's more than one of the same name, append index+1 to the end of it. - // This changes "[Shoreline pearl", "[Shoreline pearl" into "[Shoreline pearl 1]", "[Shoreline pearl 2]" - return $"{name} {index + 1}]"; - } - else - { - // If there's only one instance of the name, just add the closing bracket. - return $"{name}]"; - } - })).ToList(); + outputList.Add($"{name}]"); + } + } + + return outputList; } private void SingalHK(On.MoreSlugcats.CollectionsMenu.orig_Singal orig, CollectionsMenu self, MenuObject sender, string message)