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}
*/
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;
}
}
}