Set building rotation with arrow keys ⬆⬇⬅➡ (#1074)

* 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
This commit is contained in:
Garrow Bedrossian 2021-03-11 07:48:10 -05:00 committed by GitHub
parent d1ef3f834e
commit d887439966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 4 deletions

View File

@ -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
*/

View File

@ -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";

View File

@ -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