Guard against undefined values in Shop purchases

This commit is contained in:
SpectralFlame 2023-01-22 20:58:57 -06:00 committed by cyip92
parent 906ec4082e
commit 68cf51e43a

View File

@ -124,11 +124,14 @@ class ShopPurchaseState extends RebuyableMechanicState {
return typeof cost === "function" ? cost() : cost;
}
// ShopPurchaseData for any particular key is undefined in between page load and STD load,
// so we need to guard against that causing NaNs to propagate through the save
get purchases() {
return ShopPurchaseData[this.config.key];
return ShopPurchaseData[this.config.key] ?? 0;
}
set purchases(value) {
if (!Number.isFinite(value)) return;
ShopPurchaseData[this.config.key] = value;
}