From c7f8b50d1358127b777840721177bb64f9ade9cb Mon Sep 17 00:00:00 2001 From: Magnus Grimstvedt Saltnes Date: Thu, 18 Jun 2020 22:18:32 +0200 Subject: [PATCH] Adds tracking for rotation per building type. Adds a setting to go back to one global base rotation. --- src/js/game/hud/parts/building_placer.js | 16 +++---- .../game/hud/parts/building_placer_logic.js | 48 +++++++++++++++---- src/js/profile/application_settings.js | 11 ++++- 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/src/js/game/hud/parts/building_placer.js b/src/js/game/hud/parts/building_placer.js index 5faec6ab..e3a75400 100644 --- a/src/js/game/hud/parts/building_placer.js +++ b/src/js/game/hud/parts/building_placer.js @@ -82,9 +82,9 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic { this.buildingInfoElements.tutorialImage.setAttribute( "data-icon", "building_tutorials/" + - metaBuilding.getId() + - (variant === defaultBuildingVariant ? "" : "-" + variant) + - ".png" + metaBuilding.getId() + + (variant === defaultBuildingVariant ? "" : "-" + variant) + + ".png" ); removeAllChildren(this.buildingInfoElements.additionalInfo); @@ -122,10 +122,10 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic { T.ingame.buildingPlacement.cycleBuildingVariants.replace( "", "" + - this.root.keyMapper - .getBinding(KEYMAPPINGS.placement.cycleBuildingVariants) - .getKeyCodeString() + - "" + this.root.keyMapper + .getBinding(KEYMAPPINGS.placement.cycleBuildingVariants) + .getKeyCodeString() + + "" ) ); @@ -201,7 +201,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic { } = metaBuilding.computeOptimalDirectionAndRotationVariantAtTile( this.root, mouseTile, - this.currentBaseRotation, + this.getBaseRotation(), 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 6aee65b6..a58d2b64 100644 --- a/src/js/game/hud/parts/building_placer_logic.js +++ b/src/js/game/hud/parts/building_placer_logic.js @@ -1,3 +1,4 @@ + import { Math_abs, Math_degrees, Math_round } from "../../../core/builtins"; import { globalConfig } from "../../../core/config"; import { gMetaBuildingRegistry } from "../../../core/global_registries"; @@ -45,7 +46,34 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { * The current rotation * @type {number} */ - this.currentBaseRotation = 0; + this.currentBaseRotationGeneral = 0; + + /** + * The current rotation preference for each building. + * @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; + } + } + /** * Whether we are currently dragging @@ -200,12 +228,12 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { const selectedBuilding = this.currentMetaBuilding.get(); if (selectedBuilding) { if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateInverseModifier).pressed) { - this.currentBaseRotation = (this.currentBaseRotation + 270) % 360; + this.setBaseRotation((this.getBaseRotation() + 270) % 360); } else { - this.currentBaseRotation = (this.currentBaseRotation + 90) % 360; + this.setBaseRotation((this.getBaseRotation() + 90) % 360); } const staticComp = this.fakeEntity.components.StaticMapEntity; - staticComp.rotation = this.currentBaseRotation; + staticComp.rotation = this.getBaseRotation(); } } /** @@ -377,7 +405,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { const { rotation, rotationVariant } = metaBuilding.computeOptimalDirectionAndRotationVariantAtTile( this.root, tile, - this.currentBaseRotation, + this.getBaseRotation(), this.currentVariant.get() ); @@ -385,7 +413,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { origin: tile, rotation, rotationVariant, - originalRotation: this.currentBaseRotation, + originalRotation: this.getBaseRotation(), building: this.currentMetaBuilding.get(), variant: this.currentVariant.get(), }); @@ -401,7 +429,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { KEYMAPPINGS.placementModifiers.placementDisableAutoOrientation ).pressed ) { - this.currentBaseRotation = (180 + this.currentBaseRotation) % 360; + this.setBaseRotation((180 + this.getBaseRotation()) % 360); } // Check if we should stop placement @@ -451,7 +479,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { for (let i = 0; i < path.length; ++i) { const { rotation, tile } = path[i]; - this.currentBaseRotation = rotation; + this.setBaseRotation(rotation); this.tryPlaceCurrentBuildingAt(tile); } }); @@ -634,11 +662,11 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { ) { const delta = newPos.sub(oldPos); const angleDeg = Math_degrees(delta.angle()); - this.currentBaseRotation = (Math.round(angleDeg / 90) * 90 + 360) % 360; + this.setBaseRotation((Math.round(angleDeg / 90) * 90 + 360) % 360); // Holding alt inverts the placement if (this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.placeInverse).pressed) { - this.currentBaseRotation = (180 + this.currentBaseRotation) % 360; + this.setBaseRotation((180 + this.getBaseRotation()) % 360); } } diff --git a/src/js/profile/application_settings.js b/src/js/profile/application_settings.js index 16ec4cbd..0e03e902 100644 --- a/src/js/profile/application_settings.js +++ b/src/js/profile/application_settings.js @@ -248,9 +248,10 @@ export const allApplicationSettings = [ new BoolSetting("alwaysMultiplace", categoryGame, (app, value) => {}), new BoolSetting("enableTunnelSmartplace", categoryGame, (app, value) => {}), - new BoolSetting("vignette", categoryGame, (app, value) => {}), + new BoolSetting("vignette", categoryGame, (app, value) => {}),<<<<<<< HEAD new BoolSetting("compactBuildingInfo", categoryGame, (app, value) => {}), new BoolSetting("disableCutDeleteWarnings", categoryGame, (app, value) => {}), + new BoolSetting("rotationByBuilding", categoryGame, (app, value) => {}), ]; export function getApplicationSettingById(id) { @@ -277,6 +278,8 @@ class SettingsStorage { this.vignette = true; this.compactBuildingInfo = false; this.disableCutDeleteWarnings = false; + this.rotationByBuilding = true; + this.enableColorBlindHelper = false; @@ -527,6 +530,7 @@ export class ApplicationSettings extends ReadWriteProxy { } if (data.version < 13) { +<<<<<<< HEAD data.settings.compactBuildingInfo = false; data.version = 13; } @@ -550,6 +554,11 @@ export class ApplicationSettings extends ReadWriteProxy { if (data.version < 17) { data.settings.enableColorBlindHelper = false; data.version = 17; +======= + data.settings.rotationByBuilding = true; + data.version = 13; + +>>>>>>> 655c356... Adds tracking for rotation per building type. } return ExplainedResult.good();