From 870a3a0fdd4b58ca9cfa79a4dfc57131837a49e5 Mon Sep 17 00:00:00 2001 From: zer0Kerbal <39887717+zer0Kerbal@users.noreply.github.com> Date: Tue, 2 Jan 2024 10:38:09 +0000 Subject: [PATCH 1/2] auto: Generated markdown indexes --- docs/LegalMumboJumbo/index.md | 1 + docs/ReleaseNotes/index.md | 1 + docs/index.md | 1 + 3 files changed, 3 insertions(+) diff --git a/docs/LegalMumboJumbo/index.md b/docs/LegalMumboJumbo/index.md index eaadc67..e7bd784 100644 --- a/docs/LegalMumboJumbo/index.md +++ b/docs/LegalMumboJumbo/index.md @@ -1,5 +1,6 @@ # LegalMumboJumbo + ## Categories diff --git a/docs/ReleaseNotes/index.md b/docs/ReleaseNotes/index.md index 60120d7..60bf075 100644 --- a/docs/ReleaseNotes/index.md +++ b/docs/ReleaseNotes/index.md @@ -1,5 +1,6 @@ # ReleaseNotes + ## Categories diff --git a/docs/index.md b/docs/index.md index 13d56de..776bf1d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,5 +1,6 @@ # + ## Categories - [LegalMumboJumbo](./LegalMumboJumbo/index.md) - [ReleaseNotes](./ReleaseNotes/index.md) From 73390bdcc7e8c8e341b4e04a53420b1206ea1a8e Mon Sep 17 00:00:00 2001 From: roxik0 Date: Tue, 2 Jan 2024 14:38:54 +0100 Subject: [PATCH 2/2] Possible #81 Fix of applying inventory --- source/ScrapYard/InventoryPart.cs | 72 ++++++++++--------- .../Utilities/InventoryManagement.cs | 16 +++-- 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/source/ScrapYard/InventoryPart.cs b/source/ScrapYard/InventoryPart.cs index 7d23f76..a211b68 100644 --- a/source/ScrapYard/InventoryPart.cs +++ b/source/ScrapYard/InventoryPart.cs @@ -128,7 +128,7 @@ public InventoryPart(Part originPart) { _dryCost -= (float)(resource.maxAmount * PartResourceLibrary.Instance.GetDefinition(resource.resourceName).unitCost); } - + ID = originPart.persistentId; //Save modules if (originPart.Modules != null) { @@ -137,6 +137,7 @@ public InventoryPart(Part originPart) { string name = module.moduleName; bool isTracker = name.Equals("ModuleSYPartTracker"); + if (isTracker) { ConfigNode saved = new ConfigNode("MODULE"); @@ -145,13 +146,14 @@ public InventoryPart(Part originPart) if (isTracker) { TrackerModule = new TrackerModuleWrapper(saved); + ID = TrackerModule.ID ?? ID; } } _cachedModules.Add(module); } } - - ID = originPart.persistentId; + + } /// @@ -160,33 +162,34 @@ public InventoryPart(Part originPart) /// The to use as the basis of the . public InventoryPart(ProtoPartSnapshot originPartSnapshot) { - _name = originPartSnapshot.partInfo.name; - if (ScrapYard.Instance.Settings.PartBlacklist.Contains(Name)) - { - DoNotStore = true; - } - float fuelCost; - ShipConstruction.GetPartCosts(originPartSnapshot, originPartSnapshot.partInfo, out _dryCost, out fuelCost); - - //Save modules - if (originPartSnapshot.modules != null) + _name = originPartSnapshot.partInfo.name; + if (ScrapYard.Instance.Settings.PartBlacklist.Contains(Name)) + { + DoNotStore = true; + } + float fuelCost; + ShipConstruction.GetPartCosts(originPartSnapshot, originPartSnapshot.partInfo, out _dryCost, out fuelCost); + ID = originPartSnapshot.persistentId; + //Save modules + if (originPartSnapshot.modules != null) + { + foreach (ProtoPartModuleSnapshot module in originPartSnapshot.modules) { - foreach (ProtoPartModuleSnapshot module in originPartSnapshot.modules) + string name = module.moduleName; + bool isTracker = name.Equals("ModuleSYPartTracker"); + if (isTracker || moduleNameMatchesAnything(name)) //only save if there is a potential match { - string name = module.moduleName; - bool isTracker = name.Equals("ModuleSYPartTracker"); - if (isTracker || moduleNameMatchesAnything(name)) //only save if there is a potential match + ConfigNode saved = module.moduleValues; + _allModules.Add(saved); + if (isTracker) { - ConfigNode saved = module.moduleValues; - _allModules.Add(saved); - if (isTracker) - { - TrackerModule = new TrackerModuleWrapper(saved); - } + TrackerModule = new TrackerModuleWrapper(saved); + ID = TrackerModule.ID ?? ID; } } } - ID = originPartSnapshot.persistentId; + } + } /// @@ -213,7 +216,15 @@ public InventoryPart(ConfigNode originPartConfigNode) float dryMass, fuelMass, fuelCost; ShipConstruction.GetPartCostsAndMass(originPartConfigNode, availablePartForNode, out _dryCost, out fuelCost, out dryMass, out fuelMass); } - + uint id = 0; + if (originPartConfigNode.TryGetValue("persistentId", ref id)) + { + ID = id; + } + else + { + Logging.Log($"Could not find a persistent ID for part {_name}", Logging.LogType.ERROR); + } if (originPartConfigNode.HasNode("MODULE")) { foreach (ConfigNode module in originPartConfigNode.GetNodes("MODULE")) @@ -224,19 +235,12 @@ public InventoryPart(ConfigNode originPartConfigNode) if (isTracker) { TrackerModule = new TrackerModuleWrapper(module); + ID = TrackerModule.ID ?? ID; } } } - uint id = 0; - if (originPartConfigNode.TryGetValue("persistentId", ref id)) - { - ID = id; - } - else - { - Logging.Log($"Could not find a persistent ID for part {_name}", Logging.LogType.ERROR); - } + } } diff --git a/source/ScrapYard/Utilities/InventoryManagement.cs b/source/ScrapYard/Utilities/InventoryManagement.cs index 4306c15..ce10177 100644 --- a/source/ScrapYard/Utilities/InventoryManagement.cs +++ b/source/ScrapYard/Utilities/InventoryManagement.cs @@ -41,7 +41,7 @@ public static void SplitParts(IEnumerable input, out IList /// The vessel as a list of parts public static void ApplyInventoryToVessel(IEnumerable input) { - PartInventory copy = ScrapYard.Instance.TheInventory.Copy(); + PartInventory copy = ScrapYard.Instance.TheInventory.Copy(); foreach (Part part in input) { //convert it to an inventorypart @@ -57,19 +57,20 @@ public static void ApplyInventoryToVessel(IEnumerable input) //if one was found... if (inInventory != null) { - Logging.DebugLog("Found a part in inventory for " + inInventory.Name); + Logging.DebugLog("A: Found a part in inventory for " + inInventory.Name); //copy it's part tracker over if (inInventory.TrackerModule != null && part.Modules?.Contains("ModuleSYPartTracker") == true) { ModuleSYPartTracker tracker = part.Modules["ModuleSYPartTracker"] as ModuleSYPartTracker; tracker.TimesRecovered = inInventory.TrackerModule.TimesRecovered; tracker.Inventoried = inInventory.TrackerModule.Inventoried; - Logging.Log($"Copied tracker. Recovered {tracker.TimesRecovered} times with id {inInventory.ID}"); + tracker.ID = inInventory.ID; + Logging.Log($"A: Copied tracker. Recovered {tracker.TimesRecovered} times with id {inInventory.ID}"); } } } - ScrapYardEvents.OnSYInventoryAppliedToVessel.Fire(); + ScrapYardEvents.OnSYInventoryAppliedToVessel.Fire(); GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); } @@ -94,7 +95,7 @@ public static void ApplyInventoryToVessel(IEnumerable input) //if one was found... if (inInventory != null) { - Logging.DebugLog("Found a part in inventory for " + inInventory.Name); + Logging.DebugLog("B:Found a part in inventory for " + inInventory.Name); //copy it's part tracker over ConfigNode trackerNode; if (inInventory.TrackerModule != null && (trackerNode = partNode.GetModuleNode("ModuleSYPartTracker")) != null) @@ -105,11 +106,12 @@ public static void ApplyInventoryToVessel(IEnumerable input) trackerNode.SetValue("ID", id); trackerNode.SetValue("TimesRecovered", recovered); trackerNode.SetValue("Inventoried", inventoried); - Logging.DebugLog($"Copied tracker. Recovered {recovered} times with id {id}"); + Logging.DebugLog($"B:Copied tracker. Recovered {recovered} times with id {id}"); + } } } - ScrapYardEvents.OnSYInventoryAppliedToVessel.Fire(); + ScrapYardEvents.OnSYInventoryAppliedToVessel.Fire(); GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); }