mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
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:
parent
d1ef3f834e
commit
d887439966
@ -110,6 +110,12 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
// KEYBINDINGS
|
// KEYBINDINGS
|
||||||
const keyActionMapper = this.root.keyMapper;
|
const keyActionMapper = this.root.keyMapper;
|
||||||
keyActionMapper.getBinding(KEYMAPPINGS.placement.rotateWhilePlacing).add(this.tryRotate, this);
|
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.cycleBuildingVariants).add(this.cycleVariants, this);
|
||||||
keyActionMapper
|
keyActionMapper
|
||||||
.getBinding(KEYMAPPINGS.placement.switchDirectionLockSide)
|
.getBinding(KEYMAPPINGS.placement.switchDirectionLockSide)
|
||||||
@ -290,6 +296,28 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
staticComp.rotation = this.currentBaseRotation;
|
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
|
* Tries to delete the building under the mouse
|
||||||
*/
|
*/
|
||||||
|
@ -11,6 +11,11 @@ function key(str) {
|
|||||||
return str.toUpperCase().charCodeAt(0);
|
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 = {
|
export const KEYMAPPINGS = {
|
||||||
general: {
|
general: {
|
||||||
confirm: { keyCode: 13 }, // enter
|
confirm: { keyCode: 13 }, // enter
|
||||||
@ -81,6 +86,10 @@ export const KEYMAPPINGS = {
|
|||||||
pipette: { keyCode: key("Q") },
|
pipette: { keyCode: key("Q") },
|
||||||
rotateWhilePlacing: { keyCode: key("R") },
|
rotateWhilePlacing: { keyCode: key("R") },
|
||||||
rotateInverseModifier: { keyCode: 16 }, // SHIFT
|
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") },
|
cycleBuildingVariants: { keyCode: key("T") },
|
||||||
cycleBuildings: { keyCode: 9 }, // TAB
|
cycleBuildings: { keyCode: 9 }, // TAB
|
||||||
switchDirectionLockSide: { keyCode: key("R") },
|
switchDirectionLockSide: { keyCode: key("R") },
|
||||||
@ -162,13 +171,13 @@ export function getStringForKeyCode(code) {
|
|||||||
return "END";
|
return "END";
|
||||||
case 36:
|
case 36:
|
||||||
return "HOME";
|
return "HOME";
|
||||||
case 37:
|
case KEYCODE_LEFT_ARROW:
|
||||||
return "⬅";
|
return "⬅";
|
||||||
case 38:
|
case KEYCODE_UP_ARROW:
|
||||||
return "⬆";
|
return "⬆";
|
||||||
case 39:
|
case KEYCODE_RIGHT_ARROW:
|
||||||
return "➡";
|
return "➡";
|
||||||
case 40:
|
case KEYCODE_DOWN_ARROW:
|
||||||
return "⬇";
|
return "⬇";
|
||||||
case 44:
|
case 44:
|
||||||
return "PRNT";
|
return "PRNT";
|
||||||
|
@ -1134,6 +1134,10 @@ keybindings:
|
|||||||
rotateWhilePlacing: Rotate
|
rotateWhilePlacing: Rotate
|
||||||
rotateInverseModifier: >-
|
rotateInverseModifier: >-
|
||||||
Modifier: Rotate CCW instead
|
Modifier: Rotate CCW instead
|
||||||
|
rotateToUp: "Rotate: Point Up"
|
||||||
|
rotateToDown: "Rotate: Point Down"
|
||||||
|
rotateToRight: "Rotate: Point Right"
|
||||||
|
rotateToLeft: "Rotate: Point Left"
|
||||||
cycleBuildingVariants: Cycle Variants
|
cycleBuildingVariants: Cycle Variants
|
||||||
confirmMassDelete: Delete area
|
confirmMassDelete: Delete area
|
||||||
pasteLastBlueprint: Paste last blueprint
|
pasteLastBlueprint: Paste last blueprint
|
||||||
|
Loading…
Reference in New Issue
Block a user