From 8ec646a8f634d1bb4fb84c0a522e69878ef151d2 Mon Sep 17 00:00:00 2001 From: Magnus Grimstvedt Saltnes Date: Wed, 24 Jun 2020 14:20:16 +0200 Subject: [PATCH] Guards against undefined values/keys in base rotation logic. One-lines setting check per tobspr's recommendation. --- .../game/hud/parts/building_placer_logic.js | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/js/game/hud/parts/building_placer_logic.js b/src/js/game/hud/parts/building_placer_logic.js index 43abaf6a..106e642c 100644 --- a/src/js/game/hud/parts/building_placer_logic.js +++ b/src/js/game/hud/parts/building_placer_logic.js @@ -125,26 +125,30 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { * @returns {number} */ get currentBaseRotation() { - const rotationByBuilding = this.root.app.settings.getAllSettings().rotationByBuilding; - if (!rotationByBuilding) { + if (!this.root.app.settings.getAllSettings().rotationByBuilding) { + return this.currentBaseRotationGeneral; + } + const building = this.currentMetaBuilding.get(); + if (building != undefined && this.preferredBaseRotations.hasOwnProperty(building.getId())) { + return this.preferredBaseRotations[building.getId()]; + } else { return this.currentBaseRotationGeneral; } - const id = this.currentMetaBuilding.get().getId(); - return this.preferredBaseRotations[id] == null - ? this.currentBaseRotationGeneral - : this.preferredBaseRotations[id]; } /** * Sets the base rotation for the current meta-building. */ set currentBaseRotation(rotation) { - const rotationByBuilding = this.root.app.settings.getAllSettings().rotationByBuilding; - if (!rotationByBuilding) { + if (!this.root.app.settings.getAllSettings().rotationByBuilding) { this.currentBaseRotationGeneral = rotation; } else { - const id = this.currentMetaBuilding.get().getId(); - this.preferredBaseRotations[id] = rotation; + const building = this.currentMetaBuilding.get(); + if (building != undefined) { + this.preferredBaseRotations[building.getId()] = rotation; + } else { + this.currentBaseRotationGeneral = rotation; + } } }