From b0cc9539d7517a9d035eb26d283cf5af8e7f7c10 Mon Sep 17 00:00:00 2001 From: tobspr Date: Sun, 28 Jun 2020 12:48:18 +0200 Subject: [PATCH] Fix sandbox controller --- src/js/game/hud/parts/sandbox_controller.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/js/game/hud/parts/sandbox_controller.js b/src/js/game/hud/parts/sandbox_controller.js index e5158790..ba08a5fe 100644 --- a/src/js/game/hud/parts/sandbox_controller.js +++ b/src/js/game/hud/parts/sandbox_controller.js @@ -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 ); }