mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Allow continual building placement
To improve placing belts Wired onto the existing mouse down/up events, just simulating with the gamepad keybindings
This commit is contained in:
parent
08ee615c6c
commit
e7981d485e
@ -196,7 +196,8 @@ export class InputDistributor {
|
|||||||
const keyCode = 300 + index;
|
const keyCode = 300 + index;
|
||||||
const isInitial = !this.keysDown.has(keyCode);
|
const isInitial = !this.keysDown.has(keyCode);
|
||||||
|
|
||||||
if (button.pressed) {
|
// Limit to initial presses only, otherwise it generates event every frame
|
||||||
|
if (button.pressed && isInitial) {
|
||||||
logger.debug(`gamepad button [${index}]: ${button.pressed ? "pressed" : ""}`);
|
logger.debug(`gamepad button [${index}]: ${button.pressed ? "pressed" : ""}`);
|
||||||
this.keysDown.add(keyCode);
|
this.keysDown.add(keyCode);
|
||||||
|
|
||||||
|
|||||||
@ -117,10 +117,8 @@ 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
|
this.root.gameState.inputReciever.keydown.add(this.onKeyDown, this);
|
||||||
.getBinding(KEYMAPPINGS.placement.placeBuilding)
|
this.root.gameState.inputReciever.keyup.add(this.onKeyUp, this);
|
||||||
.add(this.tryPlaceCurrentBuildingAtCursor, this);
|
|
||||||
keyActionMapper.getBinding(KEYMAPPINGS.placement.delete).add(this.tryDeleteBelowCursor, 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);
|
||||||
@ -136,29 +134,44 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
this.root.camera.upPostHandler.add(this.onMouseUp, this);
|
this.root.camera.upPostHandler.add(this.onMouseUp, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
tryPlaceCurrentBuildingAtCursor() {
|
onKeyDown({ keyCode }) {
|
||||||
if (!this.currentMetaBuilding.get()) {
|
if (keyCode === this.root.keyMapper.getBinding(KEYMAPPINGS.placement.placeBuilding).keyCode) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mousePosition = this.root.app.mousePosition;
|
const mousePosition = this.root.app.mousePosition;
|
||||||
if (!mousePosition) {
|
if (!mousePosition) {
|
||||||
// Not on screen
|
// Not on screen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const worldPos = this.root.camera.screenToWorld(mousePosition);
|
this.onMouseDown(mousePosition, enumMouseButton.left);
|
||||||
const mouseTile = worldPos.toTileSpace();
|
return;
|
||||||
|
}
|
||||||
this.tryPlaceCurrentBuildingAt(mouseTile);
|
|
||||||
|
if (keyCode === this.root.keyMapper.getBinding(KEYMAPPINGS.placement.delete).keyCode) {
|
||||||
|
const mousePosition = this.root.app.mousePosition;
|
||||||
|
if (!mousePosition) {
|
||||||
|
// Not on screen
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tryDeleteBelowCursor() {
|
|
||||||
if (this.currentMetaBuilding.get()) {
|
if (this.currentMetaBuilding.get()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.deleteBelowCursor();
|
this.onMouseDown(mousePosition, enumMouseButton.right);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onKeyUp({ keyCode }) {
|
||||||
|
if (keyCode === this.root.keyMapper.getBinding(KEYMAPPINGS.placement.placeBuilding).keyCode) {
|
||||||
|
this.onMouseUp();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyCode === this.root.keyMapper.getBinding(KEYMAPPINGS.placement.delete).keyCode) {
|
||||||
|
this.onMouseUp();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user