From d887439966814405ca6207d6267597bab83aad50 Mon Sep 17 00:00:00 2001 From: Garrow Bedrossian Date: Thu, 11 Mar 2021 07:48:10 -0500 Subject: [PATCH] =?UTF-8?q?Set=20building=20rotation=20with=20arrow=20keys?= =?UTF-8?q?=20=E2=AC=86=E2=AC=87=E2=AC=85=E2=9E=A1=20(#1074)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Set building rotation with arrow keys ⬆⬇⬅➡ Adds 4 default keybinds to quickly set building rotation in each of the four cardinal directions - up, down, left, and right - using the arrow keys. * Address feedback, remove needless else --- .../game/hud/parts/building_placer_logic.js | 28 +++++++++++++++++++ src/js/game/key_action_mapper.js | 17 ++++++++--- translations/base-en.yaml | 4 +++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/js/game/hud/parts/building_placer_logic.js b/src/js/game/hud/parts/building_placer_logic.js index 9007511b..1e88abc7 100644 --- a/src/js/game/hud/parts/building_placer_logic.js +++ b/src/js/game/hud/parts/building_placer_logic.js @@ -110,6 +110,12 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { // KEYBINDINGS const keyActionMapper = this.root.keyMapper; keyActionMapper.getBinding(KEYMAPPINGS.placement.rotateWhilePlacing).add(this.tryRotate, this); + + keyActionMapper.getBinding(KEYMAPPINGS.placement.rotateToUp).add(this.trySetRotate, this); + keyActionMapper.getBinding(KEYMAPPINGS.placement.rotateToDown).add(this.trySetRotate, this); + keyActionMapper.getBinding(KEYMAPPINGS.placement.rotateToRight).add(this.trySetRotate, this); + keyActionMapper.getBinding(KEYMAPPINGS.placement.rotateToLeft).add(this.trySetRotate, this); + keyActionMapper.getBinding(KEYMAPPINGS.placement.cycleBuildingVariants).add(this.cycleVariants, this); keyActionMapper .getBinding(KEYMAPPINGS.placement.switchDirectionLockSide) @@ -290,6 +296,28 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { staticComp.rotation = this.currentBaseRotation; } } + + /** + * Rotates the current building to the specified direction. + */ + trySetRotate() { + const selectedBuilding = this.currentMetaBuilding.get(); + if (selectedBuilding) { + if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateToUp).pressed) { + this.currentBaseRotation = 0; + } else if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateToDown).pressed) { + this.currentBaseRotation = 180; + } else if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateToRight).pressed) { + this.currentBaseRotation = 90; + } else if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateToLeft).pressed) { + this.currentBaseRotation = 270; + } + + const staticComp = this.fakeEntity.components.StaticMapEntity; + staticComp.rotation = this.currentBaseRotation; + } + } + /** * Tries to delete the building under the mouse */ diff --git a/src/js/game/key_action_mapper.js b/src/js/game/key_action_mapper.js index 9fa4ffe1..13f33d66 100644 --- a/src/js/game/key_action_mapper.js +++ b/src/js/game/key_action_mapper.js @@ -11,6 +11,11 @@ function key(str) { return str.toUpperCase().charCodeAt(0); } +const KEYCODE_UP_ARROW = 38; +const KEYCODE_DOWN_ARROW = 40; +const KEYCODE_LEFT_ARROW = 37; +const KEYCODE_RIGHT_ARROW = 39; + export const KEYMAPPINGS = { general: { confirm: { keyCode: 13 }, // enter @@ -81,6 +86,10 @@ export const KEYMAPPINGS = { pipette: { keyCode: key("Q") }, rotateWhilePlacing: { keyCode: key("R") }, rotateInverseModifier: { keyCode: 16 }, // SHIFT + rotateToUp: { keyCode: KEYCODE_UP_ARROW }, + rotateToDown: { keyCode: KEYCODE_DOWN_ARROW }, + rotateToRight: { keyCode: KEYCODE_RIGHT_ARROW }, + rotateToLeft: { keyCode: KEYCODE_LEFT_ARROW }, cycleBuildingVariants: { keyCode: key("T") }, cycleBuildings: { keyCode: 9 }, // TAB switchDirectionLockSide: { keyCode: key("R") }, @@ -162,13 +171,13 @@ export function getStringForKeyCode(code) { return "END"; case 36: return "HOME"; - case 37: + case KEYCODE_LEFT_ARROW: return "⬅"; - case 38: + case KEYCODE_UP_ARROW: return "⬆"; - case 39: + case KEYCODE_RIGHT_ARROW: return "➡"; - case 40: + case KEYCODE_DOWN_ARROW: return "⬇"; case 44: return "PRNT"; diff --git a/translations/base-en.yaml b/translations/base-en.yaml index 17e981fd..59c077de 100644 --- a/translations/base-en.yaml +++ b/translations/base-en.yaml @@ -1134,6 +1134,10 @@ keybindings: rotateWhilePlacing: Rotate rotateInverseModifier: >- Modifier: Rotate CCW instead + rotateToUp: "Rotate: Point Up" + rotateToDown: "Rotate: Point Down" + rotateToRight: "Rotate: Point Right" + rotateToLeft: "Rotate: Point Left" cycleBuildingVariants: Cycle Variants confirmMassDelete: Delete area pasteLastBlueprint: Paste last blueprint