Skip to content

Commit

Permalink
fix savedata oopsie
Browse files Browse the repository at this point in the history
  • Loading branch information
Govorunb committed Apr 18, 2024
1 parent d926fce commit 504aded
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions SCHIZO/Events/ErmfishDefenseForce/ErmfishDefenseForce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Nautilus.Handlers;
using Nautilus.Json;
using Nautilus.Json.Attributes;
using Unity.Collections;
Expand Down Expand Up @@ -58,13 +59,6 @@ private void Start()
SaveData.Instance.Load();
}

private new void OnDestroy()
{
SaveData.Instance.Save();
SaveData.Instance.Detach();
base.OnDestroy();
}

public void OnCook(TechType techType)
{
OnDrop(techType); // losing inventory items doesn't trigger OnDrop
Expand Down Expand Up @@ -262,29 +256,23 @@ public void OnPlayerKilledByDefender(GameObject defender)
private class SaveData : SaveDataCache
{
private static SaveData _instance;
public static SaveData Instance => _instance ??= new();
public static SaveData Instance => _instance ??= SaveDataHandler.RegisterSaveDataCache<SaveData>();

public float aggro;

private ErmfishDefenseForce _source;
public SaveData()
{
_instance = this;
OnStartedSaving += SaveAggro;
OnFinishedLoading += LoadAggro;
}
public void Attach(ErmfishDefenseForce source)
{
_source = source;
OnStartedSaving += SaveAggro;
OnFinishedLoading += LoadAggro;
}

private void SaveAggro(object sender, JsonFileEventArgs e) => aggro = _source ? _source.CurrentAggro : default;
private void LoadAggro(object sender, JsonFileEventArgs e) => _source!?.SetAggro(aggro);

public void Detach()
{
OnStartedSaving -= SaveAggro;
OnFinishedLoading -= LoadAggro;
}
}
}

0 comments on commit 504aded

Please sign in to comment.