Guards against undefined values/keys in base rotation logic.

One-lines setting check per tobspr's recommendation.
This commit is contained in:
Magnus Grimstvedt Saltnes 2020-06-24 14:20:16 +02:00
parent 553ebb5ef6
commit 8ec646a8f6
1 changed files with 14 additions and 10 deletions

View File

@ -125,26 +125,30 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
* @returns {number} * @returns {number}
*/ */
get currentBaseRotation() { get currentBaseRotation() {
const rotationByBuilding = this.root.app.settings.getAllSettings().rotationByBuilding; if (!this.root.app.settings.getAllSettings().rotationByBuilding) {
if (!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; 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. * Sets the base rotation for the current meta-building.
*/ */
set currentBaseRotation(rotation) { set currentBaseRotation(rotation) {
const rotationByBuilding = this.root.app.settings.getAllSettings().rotationByBuilding; if (!this.root.app.settings.getAllSettings().rotationByBuilding) {
if (!rotationByBuilding) {
this.currentBaseRotationGeneral = rotation; this.currentBaseRotationGeneral = rotation;
} else { } else {
const id = this.currentMetaBuilding.get().getId(); const building = this.currentMetaBuilding.get();
this.preferredBaseRotations[id] = rotation; if (building != undefined) {
this.preferredBaseRotations[building.getId()] = rotation;
} else {
this.currentBaseRotationGeneral = rotation;
}
} }
} }