From a2830b2c7fdb6ada251f1ca6f632c50ab5f3b1a6 Mon Sep 17 00:00:00 2001 From: Anthony Purchase Date: Wed, 21 Feb 2018 12:18:51 +0000 Subject: [PATCH] Fix support for Aberration and species with the same name Removed previous workaround for duplicate species names. Attempts to cleanly handle all current and future cases where species are split into two classes, e.g. Coelacanth (ocean variety) and Nameless (surface variety). --- LarkatorGUI/ArkReader.cs | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/LarkatorGUI/ArkReader.cs b/LarkatorGUI/ArkReader.cs index ee7232a..ceb9112 100644 --- a/LarkatorGUI/ArkReader.cs +++ b/LarkatorGUI/ArkReader.cs @@ -114,15 +114,27 @@ private async Task LoadClassesJson() { string content = await ReadFileAsync(Path.Combine(outputDir, Properties.Resources.ClassesJson)); var classesOutput = JArray.Parse(content); - ClassMapping = classesOutput - .Select(mapping => new { Cls = mapping["cls"].Value(), Name = mapping["name"].Value() }) - .Where(m => !m.Cls.Contains("BP_Ocean_C")) - .ToDictionary(m => m.Name, m => m.Cls); - -#if WARN_ON_EMPTY_CLASSES - if (ClassMapping.Count <= 0) - throw new ExternalToolsException("ARK Tools produced no classes output"); -#endif + + ClassMapping = new Dictionary(); + foreach (var mapping in classesOutput.OrderBy(mapping => mapping["cls"].Value().Length)) + { + var cls = mapping["cls"].Value(); + var name = mapping["name"].Value(); + + if (ClassMapping.ContainsKey(name)) + name = GenerateNameVariant(name, cls); + + ClassMapping.Add(name, cls); + } + } + + private string GenerateNameVariant(string name, string cls) + { + var clsParts = cls.Split('_'); + if (clsParts.Length > 3 && clsParts.Last() == "C" && clsParts[clsParts.Length - 3] == "BP") + return $"{name} ({clsParts[clsParts.Length - 2]})"; + + return name + "*"; } private async Task LoadSpecies(string speciesName) @@ -136,6 +148,10 @@ private async Task LoadSpecies(string speciesName) { var contents = await ReadFileAsync(path); FoundDinos[speciesName] = JsonConvert.DeserializeObject>(contents); + if (FoundDinos[speciesName].Count > 0 && FoundDinos[speciesName].First().Type != speciesName) + { + FoundDinos[speciesName].ForEach(d => d.Type = speciesName); + } } else {