mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Place building keybinding
Allow to set keybinding for place building action This allows to set gamepad button TODO: Allow dragging for belt placement
This commit is contained in:
parent
45ecc0ad4e
commit
4e6017698a
@ -185,7 +185,7 @@ export class InputDistributor {
|
|||||||
const gamepad = navigator.getGamepads()[this.connectedGamepadIndex];
|
const gamepad = navigator.getGamepads()[this.connectedGamepadIndex];
|
||||||
|
|
||||||
for (const [index, button] of gamepad.buttons.entries()) {
|
for (const [index, button] of gamepad.buttons.entries()) {
|
||||||
const keyCode = 200 + index
|
const keyCode = 300 + index;
|
||||||
const isInitial = !this.keysDown.has(keyCode);
|
const isInitial = !this.keysDown.has(keyCode);
|
||||||
|
|
||||||
if (button.pressed) {
|
if (button.pressed) {
|
||||||
|
@ -117,6 +117,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
keyActionMapper.getBinding(KEYMAPPINGS.general.back).add(this.abortPlacement, this);
|
keyActionMapper.getBinding(KEYMAPPINGS.general.back).add(this.abortPlacement, this);
|
||||||
keyActionMapper.getBinding(KEYMAPPINGS.placement.pipette).add(this.startPipette, this);
|
keyActionMapper.getBinding(KEYMAPPINGS.placement.pipette).add(this.startPipette, this);
|
||||||
this.root.gameState.inputReciever.keyup.add(this.checkForDirectionLockSwitch, this);
|
this.root.gameState.inputReciever.keyup.add(this.checkForDirectionLockSwitch, this);
|
||||||
|
keyActionMapper.getBinding(KEYMAPPINGS.placement.placeBuilding).add(this.tryPlaceCurrentBuildingAtCursor, this)
|
||||||
|
|
||||||
// BINDINGS TO GAME EVENTS
|
// BINDINGS TO GAME EVENTS
|
||||||
this.root.hud.signals.buildingsSelectedForCopy.add(this.abortPlacement, this);
|
this.root.hud.signals.buildingsSelectedForCopy.add(this.abortPlacement, this);
|
||||||
@ -132,6 +133,23 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
this.root.camera.upPostHandler.add(this.onMouseUp, this);
|
this.root.camera.upPostHandler.add(this.onMouseUp, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tryPlaceCurrentBuildingAtCursor() {
|
||||||
|
if (!this.currentMetaBuilding.get()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mousePosition = this.root.app.mousePosition;
|
||||||
|
if (!mousePosition) {
|
||||||
|
// Not on screen
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const worldPos = this.root.camera.screenToWorld(mousePosition);
|
||||||
|
const mouseTile = worldPos.toTileSpace();
|
||||||
|
|
||||||
|
this.tryPlaceCurrentBuildingAt(mouseTile);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the edit mode got changed
|
* Called when the edit mode got changed
|
||||||
* @param {Layer} layer
|
* @param {Layer} layer
|
||||||
|
@ -195,7 +195,7 @@ export class HUDKeybindingOverlay extends BaseHUDPart {
|
|||||||
{
|
{
|
||||||
// Place building
|
// Place building
|
||||||
label: T.ingame.keybindingsOverlay.placeBuilding,
|
label: T.ingame.keybindingsOverlay.placeBuilding,
|
||||||
keys: [KEYCODE_LMB],
|
keys: [k.placement.placeBuilding],
|
||||||
condition: () => this.anyPlacementActive,
|
condition: () => this.anyPlacementActive,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -11,6 +11,10 @@ function key(str) {
|
|||||||
return str.toUpperCase().charCodeAt(0);
|
return str.toUpperCase().charCodeAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const KEYCODE_LMB = 1;
|
||||||
|
export const KEYCODE_MMB = 2;
|
||||||
|
export const KEYCODE_RMB = 3;
|
||||||
|
|
||||||
export const KEYMAPPINGS = {
|
export const KEYMAPPINGS = {
|
||||||
general: {
|
general: {
|
||||||
confirm: { keyCode: 13 }, // enter
|
confirm: { keyCode: 13 }, // enter
|
||||||
@ -78,6 +82,7 @@ export const KEYMAPPINGS = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
placement: {
|
placement: {
|
||||||
|
placeBuilding: { keyCode: KEYCODE_LMB },
|
||||||
pipette: { keyCode: key("Q") },
|
pipette: { keyCode: key("Q") },
|
||||||
rotateWhilePlacing: { keyCode: key("R") },
|
rotateWhilePlacing: { keyCode: key("R") },
|
||||||
rotateInverseModifier: { keyCode: 16 }, // SHIFT
|
rotateInverseModifier: { keyCode: 16 }, // SHIFT
|
||||||
@ -112,10 +117,6 @@ for (const categoryId in KEYMAPPINGS) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const KEYCODE_LMB = 1;
|
|
||||||
export const KEYCODE_MMB = 2;
|
|
||||||
export const KEYCODE_RMB = 3;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a keycode -> string
|
* Returns a keycode -> string
|
||||||
* @param {number} code
|
* @param {number} code
|
||||||
@ -261,6 +262,32 @@ export function getStringForKeyCode(code) {
|
|||||||
return "]";
|
return "]";
|
||||||
case 222:
|
case 222:
|
||||||
return "'";
|
return "'";
|
||||||
|
|
||||||
|
// Xbox Gamepad
|
||||||
|
case 300:
|
||||||
|
return "🎮 A";
|
||||||
|
case 301:
|
||||||
|
return "🎮 B";
|
||||||
|
case 302:
|
||||||
|
return "🎮 X";
|
||||||
|
case 303:
|
||||||
|
return "🎮 Y";
|
||||||
|
case 304:
|
||||||
|
return "🎮 LB";
|
||||||
|
case 305:
|
||||||
|
return "🎮 RB";
|
||||||
|
case 306:
|
||||||
|
return "🎮 LT";
|
||||||
|
case 307:
|
||||||
|
return "🎮 RT";
|
||||||
|
case 312:
|
||||||
|
return "🎮 ⬆";
|
||||||
|
case 313:
|
||||||
|
return "🎮 ⬇";
|
||||||
|
case 314:
|
||||||
|
return "🎮 ⬅";
|
||||||
|
case 315:
|
||||||
|
return "🎮 ➡";
|
||||||
}
|
}
|
||||||
|
|
||||||
return (48 <= code && code <= 57) || (65 <= code && code <= 90)
|
return (48 <= code && code <= 57) || (65 <= code && code <= 90)
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user