Fix sandbox controller

This commit is contained in:
tobspr 2020-06-28 12:48:18 +02:00
parent 77440a68bc
commit b0cc9539d7
1 changed files with 17 additions and 4 deletions

View File

@ -3,6 +3,7 @@ import { makeDiv } from "../../../core/utils";
import { DynamicDomAttach } from "../dynamic_dom_attach";
import { blueprintShape, UPGRADES } from "../../upgrades";
import { enumNotificationType } from "./notifications";
import { tutorialGoals } from "../../tutorial_goals";
export class HUDSandboxController extends BaseHUDPart {
createElements(parent) {
@ -98,14 +99,26 @@ export class HUDSandboxController extends BaseHUDPart {
}
modifyLevel(amount) {
this.root.hubGoals.level = Math.max(1, this.root.hubGoals.level + amount);
this.root.hubGoals.createNextGoal();
const hubGoals = this.root.hubGoals;
hubGoals.level = Math.max(1, hubGoals.level + amount);
hubGoals.createNextGoal();
// Clear all shapes of this level
this.root.hubGoals.storedShapes[this.root.hubGoals.currentGoal.definition.getHash()] = 0;
hubGoals.storedShapes[hubGoals.currentGoal.definition.getHash()] = 0;
this.root.hud.parts.pinnedShapes.rerenderFull();
// Compute gained rewards
hubGoals.gainedRewards = {};
for (let i = 0; i < hubGoals.level - 1; ++i) {
if (i < tutorialGoals.length) {
const reward = tutorialGoals[i].reward;
hubGoals.gainedRewards[reward] = (hubGoals.gainedRewards[reward] || 0) + 1;
}
}
this.root.hud.signals.notification.dispatch(
"Changed level to " + this.root.hubGoals.level,
"Changed level to " + hubGoals.level,
enumNotificationType.upgrade
);
}