Fixed switching saves causing some getters to not update

This commit is contained in:
thepaperpilot 2021-06-28 21:36:39 -05:00
parent 25e73c80da
commit 465d15df15

View file

@ -71,7 +71,7 @@ export function addLayer(layer, player = null) {
for (let id in layer.upgrades) { for (let id in layer.upgrades) {
if (isPlainObject(layer.upgrades[id])) { if (isPlainObject(layer.upgrades[id])) {
layer.upgrades[id].bought = function() { layer.upgrades[id].bought = function() {
return !layer.deactivated && player[layer.id].upgrades.some(upgrade => upgrade == id); return !layer.deactivated && playerProxy[layer.id].upgrades.some(upgrade => upgrade == id);
} }
if (layer.upgrades[id].canAfford == undefined) { if (layer.upgrades[id].canAfford == undefined) {
layer.upgrades[id].canAfford = function() { layer.upgrades[id].canAfford = function() {
@ -81,12 +81,12 @@ export function addLayer(layer, player = null) {
return !(this.currencyLocation[name].lt(this.cost)); return !(this.currencyLocation[name].lt(this.cost));
} else if (this.currencyLayer) { } else if (this.currencyLayer) {
let lr = this.currencyLayer; let lr = this.currencyLayer;
return !(player[lr][name].lt(this.cost)); return !(playerProxy[lr][name].lt(this.cost));
} else { } else {
return !(player[name].lt(this.cost)); return !(playerProxy[name].lt(this.cost));
} }
} else { } else {
return !(player[this.layer].points.lt(this.cost)) return !(playerProxy[this.layer].points.lt(this.cost))
} }
} }
} }
@ -104,21 +104,21 @@ export function addLayer(layer, player = null) {
this.currencyLocation[name] = this.currencyLocation[name].sub(this.cost); this.currencyLocation[name] = this.currencyLocation[name].sub(this.cost);
} else if (this.currencyLayer) { } else if (this.currencyLayer) {
let lr = this.currencyLayer; let lr = this.currencyLayer;
if (player[lr][name].lt(this.cost)) { if (playerProxy[lr][name].lt(this.cost)) {
return; return;
} }
player[lr][name] = player[lr][name].sub(this.cost); playerProxy[lr][name] = playerProxy[lr][name].sub(this.cost);
} else { } else {
if (player[name].lt(this.cost)) { if (playerProxy[name].lt(this.cost)) {
return; return;
} }
player[name] = player[name].sub(this.cost); playerProxy[name] = playerProxy[name].sub(this.cost);
} }
} else { } else {
if (player[this.layer].points.lt(this.cost)) { if (playerProxy[this.layer].points.lt(this.cost)) {
return; return;
} }
player[this.layer].points = player[this.layer].points.sub(this.cost); playerProxy[this.layer].points = playerProxy[this.layer].points.sub(this.cost);
} }
}); });
} else { } else {
@ -130,7 +130,7 @@ export function addLayer(layer, player = null) {
return; return;
} }
this.pay(); this.pay();
player[this.layer].upgrades.push(this.id); playerProxy[this.layer].upgrades.push(this.id);
this.onPurchase?.(); this.onPurchase?.();
}); });
} else { } else {
@ -143,7 +143,7 @@ export function addLayer(layer, player = null) {
for (let id in layer.achievements) { for (let id in layer.achievements) {
if (isPlainObject(layer.achievements[id])) { if (isPlainObject(layer.achievements[id])) {
layer.achievements[id].earned = function() { layer.achievements[id].earned = function() {
return !layer.deactivated && player[layer.id].achievements.some(achievement => achievement == id); return !layer.deactivated && playerProxy[layer.id].achievements.some(achievement => achievement == id);
} }
if (layer.achievements[id].onComplete != undefined) { if (layer.achievements[id].onComplete != undefined) {
layer.achievements[id].onComplete.forceCached = false; layer.achievements[id].onComplete.forceCached = false;
@ -164,16 +164,16 @@ export function addLayer(layer, player = null) {
layer.challenges[id].onExit.forceCached = false; layer.challenges[id].onExit.forceCached = false;
} }
layer.challenges[id].shown = function() { layer.challenges[id].shown = function() {
return this.unlocked !== false && (player.hideChallenges === false || !this.maxed); return this.unlocked !== false && (playerProxy.hideChallenges === false || !this.maxed);
} }
layer.challenges[id].completed = function() { layer.challenges[id].completed = function() {
return !layer.deactivated && player[layer.id].challenges[id]?.gt(0); return !layer.deactivated && playerProxy[layer.id].challenges[id]?.gt(0);
} }
layer.challenges[id].completions = function() { layer.challenges[id].completions = function() {
return player[layer.id].challenges[id]; return playerProxy[layer.id].challenges[id];
} }
layer.challenges[id].maxed = function() { layer.challenges[id].maxed = function() {
return !layer.deactivated && Decimal.gte(player[layer.id].challenges[id], this.completionLimit); return !layer.deactivated && Decimal.gte(playerProxy[layer.id].challenges[id], this.completionLimit);
} }
if (layer.challenges[id].mark == undefined) { if (layer.challenges[id].mark == undefined) {
layer.challenges[id].mark = function() { layer.challenges[id].mark = function() {
@ -181,7 +181,7 @@ export function addLayer(layer, player = null) {
} }
} }
layer.challenges[id].active = function() { layer.challenges[id].active = function() {
return !layer.deactivated && player[layer.id].activeChallenge === id; return !layer.deactivated && playerProxy[layer.id].activeChallenge === id;
} }
if (layer.challenges[id].canComplete == undefined) { if (layer.challenges[id].canComplete == undefined) {
layer.challenges[id].canComplete = function() { layer.challenges[id].canComplete = function() {
@ -195,12 +195,12 @@ export function addLayer(layer, player = null) {
return !(this.currencyLocation[name].lt(this.goal)); return !(this.currencyLocation[name].lt(this.goal));
} else if (this.currencyLayer) { } else if (this.currencyLayer) {
let lr = this.currencyLayer; let lr = this.currencyLayer;
return !(player[lr][name].lt(this.goal)); return !(playerProxy[lr][name].lt(this.goal));
} else { } else {
return !(player[name].lt(this.goal)); return !(playerProxy[name].lt(this.goal));
} }
} else { } else {
return !(player.points.lt(this.goal)); return !(playerProxy.points.lt(this.goal));
} }
} }
} }
@ -208,23 +208,23 @@ export function addLayer(layer, player = null) {
layer.challenges[id].completionLimit = new Decimal(1); layer.challenges[id].completionLimit = new Decimal(1);
} }
layer.challenges[id].toggle = noCache(function() { layer.challenges[id].toggle = noCache(function() {
let exiting = player[layer.id].activeChallenge === id; let exiting = playerProxy[layer.id].activeChallenge === id;
if (exiting) { if (exiting) {
if (this.canComplete && !this.maxed) { if (this.canComplete && !this.maxed) {
let completions = this.canComplete; let completions = this.canComplete;
if (completions === true) { if (completions === true) {
completions = 1; completions = 1;
} }
player[layer.id].challenges[id] = playerProxy[layer.id].challenges[id] =
Decimal.min(player[layer.id].challenges[id].add(completions), this.completionLimit); Decimal.min(playerProxy[layer.id].challenges[id].add(completions), this.completionLimit);
this.onComplete?.(); this.onComplete?.();
} }
player[layer.id].activeChallenge = null; playerProxy[layer.id].activeChallenge = null;
this.onExit?.(); this.onExit?.();
layer.reset(true); layer.reset(true);
} else if (!exiting && this.canStart) { } else if (!exiting && this.canStart) {
layer.reset(true); layer.reset(true);
player[layer.id].activeChallenge = id; playerProxy[layer.id].activeChallenge = id;
this.onEnter?.(); this.onEnter?.();
} }
}); });
@ -240,7 +240,7 @@ export function addLayer(layer, player = null) {
if (layer.buyables) { if (layer.buyables) {
if (layer.buyables.reset == undefined) { if (layer.buyables.reset == undefined) {
layer.buyables.reset = noCache(function() { layer.buyables.reset = noCache(function() {
player[this.layer].buyables = getStartingBuyables(layer); playerProxy[this.layer].buyables = getStartingBuyables(layer);
}); });
} else { } else {
layer.buyables.reset.forceCached = false; layer.buyables.reset.forceCached = false;
@ -251,21 +251,21 @@ export function addLayer(layer, player = null) {
for (let id in layer.buyables) { for (let id in layer.buyables) {
if (isPlainObject(layer.buyables[id])) { if (isPlainObject(layer.buyables[id])) {
layer.buyables[id].amount = function() { layer.buyables[id].amount = function() {
return player[layer.id].buyables[id]; return playerProxy[layer.id].buyables[id];
} }
layer.buyables[id].amountSet = function(amount) { layer.buyables[id].amountSet = function(amount) {
player[layer.id].buyables[id] = amount; playerProxy[layer.id].buyables[id] = amount;
} }
layer.buyables[id].canBuy = function() { layer.buyables[id].canBuy = function() {
return !layer.deactivated && this.unlocked !== false && this.canAfford !== false && return !layer.deactivated && this.unlocked !== false && this.canAfford !== false &&
Decimal.lt(player[layer.id].buyables[id], this.purchaseLimit); Decimal.lt(playerProxy[layer.id].buyables[id], this.purchaseLimit);
} }
if (layer.buyables[id].purchaseLimit == undefined) { if (layer.buyables[id].purchaseLimit == undefined) {
layer.buyables[id].purchaseLimit = new Decimal(Infinity); layer.buyables[id].purchaseLimit = new Decimal(Infinity);
} }
if (layer.buyables[id].cost != undefined && layer.buyables[id].buy == undefined) { if (layer.buyables[id].cost != undefined && layer.buyables[id].buy == undefined) {
layer.buyables[id].buy = noCache(function() { layer.buyables[id].buy = noCache(function() {
player[this.layer].points = player[this.layer].points.sub(this.cost()); playerProxy[this.layer].points = playerProxy[this.layer].points.sub(this.cost());
this.amount = this.amount.add(1); this.amount = this.amount.add(1);
}); });
} else { } else {
@ -284,10 +284,10 @@ export function addLayer(layer, player = null) {
for (let id in layer.clickables) { for (let id in layer.clickables) {
if (isPlainObject(layer.clickables[id])) { if (isPlainObject(layer.clickables[id])) {
layer.clickables[id].state = function() { layer.clickables[id].state = function() {
return player[layer.id].clickables[id]; return playerProxy[layer.id].clickables[id];
} }
layer.clickables[id].stateSet = function(state) { layer.clickables[id].stateSet = function(state) {
player[layer.id].clickables[id] = state; playerProxy[layer.id].clickables[id] = state;
} }
if (layer.clickables[id].click != undefined) { if (layer.clickables[id].click != undefined) {
layer.clickables[id].click.forceCached = false; layer.clickables[id].click.forceCached = false;
@ -313,13 +313,13 @@ export function addLayer(layer, player = null) {
return false; return false;
} }
switch (player.msDisplay) { switch (playerProxy.msDisplay) {
default: default:
case "all": case "all":
return true; return true;
case "last": case "last":
return this.optionsDisplay || !this.earned || return this.optionsDisplay || !this.earned ||
player[this.layer].milestones[player[this.layer].milestones.length - 1] === this.id; playerProxy[this.layer].milestones[playerProxy[this.layer].milestones.length - 1] === this.id;
case "configurable": case "configurable":
return this.optionsDisplay || !this.earned; return this.optionsDisplay || !this.earned;
case "incomplete": case "incomplete":
@ -329,7 +329,7 @@ export function addLayer(layer, player = null) {
} }
} }
layer.milestones[id].earned = function() { layer.milestones[id].earned = function() {
return !layer.deactivated && player[layer.id].milestones.some(milestone => milestone == id); return !layer.deactivated && playerProxy[layer.id].milestones.some(milestone => milestone == id);
} }
} }
} }
@ -374,8 +374,8 @@ export function addLayer(layer, player = null) {
layer.grids[id].getDisplay.forceCached = false; layer.grids[id].getDisplay.forceCached = false;
} }
layer.grids[id].getData = function(cell) { layer.grids[id].getData = function(cell) {
if (player[layer.id].grids[id][cell] != undefined) { if (playerProxy[layer.id].grids[id][cell] != undefined) {
return player[layer.id].grids[id][cell]; return playerProxy[layer.id].grids[id][cell];
} }
if (isFunction(this.getStartData)) { if (isFunction(this.getStartData)) {
return this.getStartData(cell); return this.getStartData(cell);
@ -383,7 +383,7 @@ export function addLayer(layer, player = null) {
return this.getStartData; return this.getStartData;
} }
layer.grids[id].dataSet = function(cell, data) { layer.grids[id].dataSet = function(cell, data) {
player[layer.id].grids[id][cell] = data; playerProxy[layer.id].grids[id][cell] = data;
} }
layer.grids[id] = createGridProxy(layer.grids[id], getters, `${layer.id}/grids-${id}-`); layer.grids[id] = createGridProxy(layer.grids[id], getters, `${layer.id}/grids-${id}-`);
} }
@ -399,7 +399,7 @@ export function addLayer(layer, player = null) {
for (let id in layer.subtabs) { for (let id in layer.subtabs) {
if (isPlainObject(layer.subtabs[id])) { if (isPlainObject(layer.subtabs[id])) {
layer.subtabs[id].active = function() { layer.subtabs[id].active = function() {
return player.subtabs[this.layer].mainTabs === this.id; return playerProxy.subtabs[this.layer].mainTabs === this.id;
} }
} }
} }