Skip to content

Commit

Permalink
Fix saves with missing last dock
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Sep 7, 2024
1 parent f9a5f0a commit c02d7a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 0 additions & 4 deletions Winch/Data/ExtendedSaveData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ internal void ExtractModdedData()

internal void InsertModdedData()
{
if (baseSaveData.dockId == "exampleitems.dock") // TODO: make save data handle last dock
{
baseSaveData.dockId = "dock.pontoon-gc";
}
var gridsToRemove = new List<string>();
foreach (var gridByKey in saveData.grids)
{
Expand Down
1 change: 1 addition & 0 deletions Winch/Patches/API/GameSceneInitializerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void Prefix(GameSceneInitializer __instance)
HarvestZoneUtil.CreateModdedHarvestZones();
WorldEventUtil.CreateModdedStaticWorldEvents();
ItemUtil.Encyclopedia();
DockUtil.Fix();
DredgeEvent.TriggerOnGameLoading(__instance);
}
catch (Exception ex)
Expand Down
13 changes: 13 additions & 0 deletions Winch/Util/DockUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ public static Dock GetDock(string id)
if (ModdedDockDict.TryGetValue(id, out var moddedDock))
return moddedDock;

if (ModdedDockDict.Values.TryGetValue(dock => dock.Data.Id == id, out var moddedDock2))
return moddedDock2;

return null;
}

Expand Down Expand Up @@ -284,6 +287,16 @@ public static void Populate()
ResearchBottomlessLines = hceds.FirstOrDefault(hced => hced.name == "ResearchBottomlessLines");
}

public static void Fix()
{
var id = GameManager.Instance.SaveData.dockId;
if (!AllDockDict.ContainsKey(id) && !ModdedDockDict.Values.Any(dock => dock.Data.Id == id))
{
GameManager.Instance.SaveData.dockId = AllDockDataDict.Keys.FirstOrDefault();
GameManager.Instance.SaveData.dockSlotIndex = 0;
}
}

internal static void Clear()
{
AllDockDataDict.Clear();
Expand Down

0 comments on commit c02d7a5

Please sign in to comment.