Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#81 Possible fix #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/LegalMumboJumbo/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# LegalMumboJumbo


## Categories


Expand Down
1 change: 1 addition & 0 deletions docs/ReleaseNotes/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ReleaseNotes


## Categories


Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#


## Categories
- [LegalMumboJumbo](./LegalMumboJumbo/index.md)
- [ReleaseNotes](./ReleaseNotes/index.md)
Expand Down
72 changes: 38 additions & 34 deletions source/ScrapYard/InventoryPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -137,6 +137,7 @@ public InventoryPart(Part originPart)
{
string name = module.moduleName;
bool isTracker = name.Equals("ModuleSYPartTracker");

if (isTracker)
{
ConfigNode saved = new ConfigNode("MODULE");
Expand All @@ -145,13 +146,14 @@ public InventoryPart(Part originPart)
if (isTracker)
{
TrackerModule = new TrackerModuleWrapper(saved);
ID = TrackerModule.ID ?? ID;
}
}
_cachedModules.Add(module);
}
}

ID = originPart.persistentId;

}

/// <summary>
Expand All @@ -160,33 +162,34 @@ public InventoryPart(Part originPart)
/// <param name="originPartSnapshot">The <see cref="ProtoPartSnapshot"/> to use as the basis of the <see cref="InventoryPart"/>.</param>
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;
}

}

/// <summary>
Expand All @@ -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"))
Expand All @@ -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);
}

}
}

Expand Down
16 changes: 9 additions & 7 deletions source/ScrapYard/Utilities/InventoryManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void SplitParts(IEnumerable<Part> input, out IList<InventoryPart>
/// <param name="input">The vessel as a list of parts</param>
public static void ApplyInventoryToVessel(IEnumerable<Part> input)
{
PartInventory copy = ScrapYard.Instance.TheInventory.Copy();
PartInventory copy = ScrapYard.Instance.TheInventory.Copy();
foreach (Part part in input)
{
//convert it to an inventorypart
Expand All @@ -57,19 +57,20 @@ public static void ApplyInventoryToVessel(IEnumerable<Part> 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);
}

Expand All @@ -94,7 +95,7 @@ public static void ApplyInventoryToVessel(IEnumerable<ConfigNode> 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)
Expand All @@ -105,11 +106,12 @@ public static void ApplyInventoryToVessel(IEnumerable<ConfigNode> 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);
}

Expand Down
Loading