diff --git a/src/js/game/hud/parts/building_placer.js b/src/js/game/hud/parts/building_placer.js index 6ccf00ad..5faec6ab 100644 --- a/src/js/game/hud/parts/building_placer.js +++ b/src/js/game/hud/parts/building_placer.js @@ -201,7 +201,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic { } = metaBuilding.computeOptimalDirectionAndRotationVariantAtTile( this.root, mouseTile, - this.getBaseRotation(), + this.currentBaseRotation, this.currentVariant.get() ); diff --git a/src/js/game/hud/parts/building_placer_logic.js b/src/js/game/hud/parts/building_placer_logic.js index 5a462f47..43abaf6a 100644 --- a/src/js/game/hud/parts/building_placer_logic.js +++ b/src/js/game/hud/parts/building_placer_logic.js @@ -49,28 +49,9 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { /** * The current rotation preference for each building. - * @type {Object.} + * @type{Object.} */ - this.preferredRotations = {}; - - this.getBaseRotation = function () { - const rotationByBuilding = this.root.app.settings.getAllSettings().rotationByBuilding; - if (!rotationByBuilding) { - return this.currentBaseRotationGeneral; - } - const id = this.currentMetaBuilding.get().getId(); - return this.preferredRotations[id] || this.currentBaseRotationGeneral; - }; - - this.setBaseRotation = function (rotation) { - const rotationByBuilding = this.root.app.settings.getAllSettings().rotationByBuilding; - if (!rotationByBuilding) { - this.currentBaseRotationGeneral = rotation; - } else { - const id = this.currentMetaBuilding.get().getId(); - this.preferredRotations[id] = rotation; - } - }; + this.preferredBaseRotations = {}; /** * Whether we are currently dragging @@ -139,6 +120,34 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { this.root.camera.upPostHandler.add(this.onMouseUp, this); } + /** + * Returns the current base rotation for the current meta-building. + * @returns {number} + */ + get currentBaseRotation() { + const rotationByBuilding = this.root.app.settings.getAllSettings().rotationByBuilding; + if (!rotationByBuilding) { + 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) { + this.currentBaseRotationGeneral = rotation; + } else { + const id = this.currentMetaBuilding.get().getId(); + this.preferredBaseRotations[id] = rotation; + } + } + /** * Returns if the direction lock is currently active * @returns {boolean} @@ -225,12 +234,12 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { const selectedBuilding = this.currentMetaBuilding.get(); if (selectedBuilding) { if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateInverseModifier).pressed) { - this.setBaseRotation((this.getBaseRotation() + 270) % 360); + this.currentBaseRotation = (this.currentBaseRotation + 270) % 360; } else { - this.setBaseRotation((this.getBaseRotation() + 90) % 360); + this.currentBaseRotation = (this.currentBaseRotation + 90) % 360; } const staticComp = this.fakeEntity.components.StaticMapEntity; - staticComp.rotation = this.getBaseRotation(); + staticComp.rotation = this.currentBaseRotation; } } /** @@ -402,7 +411,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { const { rotation, rotationVariant } = metaBuilding.computeOptimalDirectionAndRotationVariantAtTile( this.root, tile, - this.getBaseRotation(), + this.currentBaseRotation, this.currentVariant.get() ); @@ -410,7 +419,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { origin: tile, rotation, rotationVariant, - originalRotation: this.getBaseRotation(), + originalRotation: this.currentBaseRotation, building: this.currentMetaBuilding.get(), variant: this.currentVariant.get(), }); @@ -426,7 +435,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { KEYMAPPINGS.placementModifiers.placementDisableAutoOrientation ).pressed ) { - this.setBaseRotation((180 + this.getBaseRotation()) % 360); + this.currentBaseRotation = (180 + this.currentBaseRotation) % 360; } // Check if we should stop placement @@ -476,7 +485,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { for (let i = 0; i < path.length; ++i) { const { rotation, tile } = path[i]; - this.setBaseRotation(rotation); + this.currentBaseRotation = rotation; this.tryPlaceCurrentBuildingAt(tile); } }); @@ -659,11 +668,11 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { ) { const delta = newPos.sub(oldPos); const angleDeg = Math_degrees(delta.angle()); - this.setBaseRotation((Math.round(angleDeg / 90) * 90 + 360) % 360); + this.currentBaseRotation = (Math.round(angleDeg / 90) * 90 + 360) % 360; // Holding alt inverts the placement if (this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.placeInverse).pressed) { - this.setBaseRotation((180 + this.getBaseRotation()) % 360); + this.currentBaseRotation = (180 + this.currentBaseRotation) % 360; } } diff --git a/src/js/profile/application_settings.js b/src/js/profile/application_settings.js index 92edf124..8fd80df0 100644 --- a/src/js/profile/application_settings.js +++ b/src/js/profile/application_settings.js @@ -248,7 +248,7 @@ export const allApplicationSettings = [ new BoolSetting("alwaysMultiplace", categoryGame, (app, value) => {}), new BoolSetting("enableTunnelSmartplace", categoryGame, (app, value) => {}), - new BoolSetting("vignette", categoryGame, (app, value) => {}),<<<<<<< HEAD + new BoolSetting("vignette", categoryGame, (app, value) => {}), new BoolSetting("compactBuildingInfo", categoryGame, (app, value) => {}), new BoolSetting("disableCutDeleteWarnings", categoryGame, (app, value) => {}), new BoolSetting("rotationByBuilding", categoryGame, (app, value) => {}), @@ -280,7 +280,6 @@ class SettingsStorage { this.disableCutDeleteWarnings = false; this.rotationByBuilding = true; - this.enableColorBlindHelper = false; /** @@ -554,7 +553,7 @@ export class ApplicationSettings extends ReadWriteProxy { data.settings.enableColorBlindHelper = false; data.version = 17; } - if(data.version < 18) { + if (data.version < 18) { data.settings.rotationByBuilding = true; data.version = 18; }