Skip to content

Commit

Permalink
Shorten
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Aug 31, 2024
1 parent 1d6adc5 commit 09785cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
18 changes: 2 additions & 16 deletions Winch/Data/ExtendedSaveData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,7 @@ internal void ExtractModdedData()
var moddedUnderlayItems = crabPotPOI.grid.spatialUnderlayItems.Where(WinchExtensions.IsModded).ToList();
crabPotPOI.grid.spatialItems.RemoveAll(WinchExtensions.IsModded);
crabPotPOI.grid.spatialUnderlayItems.RemoveAll(WinchExtensions.IsModded);
var partialCrabPot = (SerializedCrabPotPOIData)FormatterServices.GetUninitializedObject(typeof(SerializedCrabPotPOIData));
partialCrabPot.deployableItemId = crabPotPOI.deployableItemId;
partialCrabPot.x = crabPotPOI.x;
partialCrabPot.z = crabPotPOI.z;
partialCrabPot.lastUpdate = crabPotPOI.lastUpdate;
partialCrabPot.timeUntilNextCatchRoll = crabPotPOI.timeUntilNextCatchRoll;
partialCrabPot.durability = crabPotPOI.durability;
partialCrabPot.hadDurabilityRemaining = crabPotPOI.hadDurabilityRemaining;
partialCrabPot.grid = new SerializableGrid();
var partialCrabPot = crabPotPOI.MakeIdentical();
partialCrabPot.grid.spatialItems = moddedItems;
partialCrabPot.grid.spatialUnderlayItems = moddedUnderlayItems;
saveData.serializedCrabPotPOIs.Add(partialCrabPot);
Expand Down Expand Up @@ -164,13 +156,7 @@ internal void InsertModdedData()
foreach (var crabPotPOI in potsToRemove)
{
saveData.serializedCrabPotPOIs.Remove(crabPotPOI);
if (baseSaveData.serializedCrabPotPOIs.TryGetValue(pot =>
{
return pot.deployableItemId == crabPotPOI.deployableItemId
&& pot.x == crabPotPOI.x && pot.z == crabPotPOI.z
&& pot.lastUpdate == crabPotPOI.lastUpdate && pot.timeUntilNextCatchRoll == crabPotPOI.timeUntilNextCatchRoll
&& pot.durability == crabPotPOI.durability && pot.hadDurabilityRemaining == crabPotPOI.hadDurabilityRemaining;
}, out var baseCrabPotPOI))
if (baseSaveData.serializedCrabPotPOIs.TryGetValue(pot => pot.Identical(crabPotPOI), out var baseCrabPotPOI))
{
baseCrabPotPOI.grid.spatialItems.AddRange(crabPotPOI.grid.spatialItems);
baseCrabPotPOI.grid.spatialUnderlayItems.AddRange(crabPotPOI.grid.spatialUnderlayItems);
Expand Down
22 changes: 22 additions & 0 deletions Winch/Util/WinchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using UnityAsyncAwaitUtil;
using UnityEngine;
Expand Down Expand Up @@ -647,6 +648,27 @@ public static string ToPrintedString(this AchievementData achievement)
}
return printStr;
}

public static bool Identical(this SerializedCrabPotPOIData a, SerializedCrabPotPOIData b)
{
return a.deployableItemId == b.deployableItemId && a.x == b.x && a.z == b.z
&& a.lastUpdate == b.lastUpdate && a.timeUntilNextCatchRoll == b.timeUntilNextCatchRoll
&& a.durability == b.durability && a.hadDurabilityRemaining == b.hadDurabilityRemaining;
}

public static SerializedCrabPotPOIData MakeIdentical(this SerializedCrabPotPOIData crabPotPOI)
{
var partialCrabPot = (SerializedCrabPotPOIData)FormatterServices.GetUninitializedObject(typeof(SerializedCrabPotPOIData));
partialCrabPot.deployableItemId = crabPotPOI.deployableItemId;
partialCrabPot.x = crabPotPOI.x;
partialCrabPot.z = crabPotPOI.z;
partialCrabPot.lastUpdate = crabPotPOI.lastUpdate;
partialCrabPot.timeUntilNextCatchRoll = crabPotPOI.timeUntilNextCatchRoll;
partialCrabPot.durability = crabPotPOI.durability;
partialCrabPot.hadDurabilityRemaining = crabPotPOI.hadDurabilityRemaining;
partialCrabPot.grid = new SerializableGrid();
return partialCrabPot;
}
#endregion

#region Reflection
Expand Down

0 comments on commit 09785cd

Please sign in to comment.