From 1750744c8cb35de09617276c3fb94ddd0e6ce33d Mon Sep 17 00:00:00 2001 From: jalil <63772680+jalil49@users.noreply.github.com> Date: Fri, 5 Mar 2021 10:43:51 -0600 Subject: [PATCH] Update ClothingLoader.cs Fixing dictionary errors caused by missing mods by skipping associated key rather than overwriting it --- src/ClothingLoader.cs | 55 +++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/src/ClothingLoader.cs b/src/ClothingLoader.cs index a0b06e1..5157ef0 100644 --- a/src/ClothingLoader.cs +++ b/src/ClothingLoader.cs @@ -135,14 +135,18 @@ private static void Generalized(int outfitnum) //{ // ExpandedOutfit.Logger.LogDebug($"Overwriting Accessory (ID:{chaControl.chaFile.coordinate[outfitnum].accessory.parts[i].id}) at {i + 1} with default head accessory"); //} - chaControl.chaFile.coordinate[outfitnum].accessory.parts[ACCpostion] = import.Dequeue(); - if (Subimport.Peek() != null) - { - Temp.Add(ACCpostion, Subimport.Dequeue()); - } - else + if (!Temp.ContainsKey(ACCpostion)) { - Subimport.Dequeue(); + chaControl.chaFile.coordinate[outfitnum].accessory.parts[ACCpostion] = import.Dequeue(); + + if (Subimport.Peek() != null) + { + Temp.Add(ACCpostion, Subimport.Dequeue()); + } + else + { + Subimport.Dequeue(); + } } } } @@ -151,7 +155,31 @@ private static void Generalized(int outfitnum) Empty = data.nowAccessories[ACCpostion].type == 120; if (Empty) //120 is empty/default { - data.nowAccessories[ACCpostion] = import.Dequeue(); + if (!Temp.ContainsKey(ACCpostion)) + { + data.nowAccessories[ACCpostion] = import.Dequeue(); + if (Subimport.Peek() != null) + { + Temp.Add(ACCpostion, Subimport.Dequeue()); + } + else + { + Subimport.Dequeue(); + } + } + } + } + bool print = true; + while (import.Count != 0) + { + if (print) + { + print = false; + ExpandedOutfit.Logger.LogDebug(chaControl.fileParam.fullname + $" Ran out of space for accessories, Making {import.Count} space(s) at least (due to potential keys already existing just in case)"); + } + if (!Temp.ContainsKey(ACCpostion)) + { + data.nowAccessories.Add(import.Dequeue()); if (Subimport.Peek() != null) { Temp.Add(ACCpostion, Subimport.Dequeue()); @@ -161,18 +189,9 @@ private static void Generalized(int outfitnum) Subimport.Dequeue(); } } - } - while (import.Count != 0) - { - //ExpandedOutfit.Logger.logdebug(chaControl.fileParam.fullname + " Ran out of space for accessory, adding a space"); - data.nowAccessories.Add(import.Dequeue()); - if (Subimport.Peek() != null) - { - Temp.Add(ACCpostion, Subimport.Dequeue()); - } else { - Subimport.Dequeue(); + data.nowAccessories.Add(new ChaFileAccessory.PartsInfo()); } data.infoAccessory.Add(null); data.objAccessory.Add(null);