修了不少东西
This commit is contained in:
@@ -10,6 +10,8 @@ public sealed class EquipmentConsumableLedger : MonoBehaviour
|
||||
|
||||
private readonly Dictionary<string, int> countsByKey = new Dictionary<string, int>(StringComparer.Ordinal);
|
||||
private bool initialized;
|
||||
private bool loadedFromSave;
|
||||
private bool hasAnyRecoverableLocalState;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||
private static void Bootstrap()
|
||||
@@ -65,11 +67,18 @@ public sealed class EquipmentConsumableLedger : MonoBehaviour
|
||||
}
|
||||
|
||||
EquipmentConsumableLedgerPayload payload;
|
||||
EquipmentConsumableLedgerStorage.TryLoad(out payload);
|
||||
loadedFromSave = EquipmentConsumableLedgerStorage.TryLoad(out payload);
|
||||
hasAnyRecoverableLocalState = loadedFromSave || EquipmentConsumableLedgerStorage.HasAnyRecoverableState();
|
||||
RebuildFromPayload(payload);
|
||||
initialized = true;
|
||||
SyncMirrorCounts();
|
||||
SaveNow();
|
||||
|
||||
// If an older save exists but cannot be read right now, do not overwrite it
|
||||
// with an empty default payload during startup.
|
||||
if (loadedFromSave || !hasAnyRecoverableLocalState)
|
||||
{
|
||||
SaveNow();
|
||||
}
|
||||
}
|
||||
|
||||
public int GetCount(EquipmentConsumableKind kind)
|
||||
@@ -126,6 +135,12 @@ public sealed class EquipmentConsumableLedger : MonoBehaviour
|
||||
InitializeIfNeeded();
|
||||
}
|
||||
|
||||
if (!loadedFromSave && hasAnyRecoverableLocalState)
|
||||
{
|
||||
Debug.LogWarning("[EquipmentConsumableLedger] Recoverable save state exists but could not be loaded; skip saving to avoid overwriting older material data.");
|
||||
return;
|
||||
}
|
||||
|
||||
SyncMirrorCounts();
|
||||
EquipmentConsumableLedgerStorage.TrySave(BuildPayload());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user