修了不少东西

This commit is contained in:
FloatGaming
2026-07-16 23:04:59 +08:00
parent 29972d0705
commit 73fe474cc6
134 changed files with 7673 additions and 741 deletions
@@ -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());
}