1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Keep Belt planner mode while dragging if release the shift key

This commit is contained in:
isaisstillalive 2020-06-22 23:33:00 +09:00
parent 1092975f08
commit ab24e1afae

View File

@ -92,6 +92,12 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
*/ */
this.currentDirectionLockSide = 0; this.currentDirectionLockSide = 0;
/**
* Keep holding direction lock while dragging
* @type {boolean}
*/
this.keepDirectionLock = false;
this.initializeBindings(); this.initializeBindings();
} }
@ -108,7 +114,6 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
.add(this.switchDirectionLockSide, this); .add(this.switchDirectionLockSide, this);
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);
// 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);
@ -177,9 +182,10 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
get isDirectionLockActive() { get isDirectionLockActive() {
const metaBuilding = this.currentMetaBuilding.get(); const metaBuilding = this.currentMetaBuilding.get();
return ( return (
metaBuilding && this.keepDirectionLock ||
metaBuilding.getHasDirectionLockAvailable() && (metaBuilding &&
this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.lockBeltDirection).pressed metaBuilding.getHasDirectionLockAvailable() &&
this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.lockBeltDirection).pressed)
); );
} }
@ -419,19 +425,6 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
this.currentDirectionLockSide = 1 - this.currentDirectionLockSide; this.currentDirectionLockSide = 1 - this.currentDirectionLockSide;
} }
/**
* Checks if the direction lock key got released and if such, resets the placement
* @param {any} args
*/
checkForDirectionLockSwitch({ keyCode }) {
if (
keyCode ===
this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.lockBeltDirection).keyCode
) {
this.abortDragging();
}
}
/** /**
* Tries to place the current building at the given tile * Tries to place the current building at the given tile
* @param {Vector} tile * @param {Vector} tile
@ -661,8 +654,10 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
this.currentlyDeleting = false; this.currentlyDeleting = false;
this.lastDragTile = this.root.camera.screenToWorld(pos).toTileSpace(); this.lastDragTile = this.root.camera.screenToWorld(pos).toTileSpace();
// Place initial building, but only if direction lock is not active if (this.isDirectionLockActive) {
if (!this.isDirectionLockActive) { this.keepDirectionLock = true;
} else {
// Place initial building, but only if direction lock is not active
if (this.tryPlaceCurrentBuildingAt(this.lastDragTile)) { if (this.tryPlaceCurrentBuildingAt(this.lastDragTile)) {
this.root.soundProxy.playUi(metaBuilding.getPlacementSound()); this.root.soundProxy.playUi(metaBuilding.getPlacementSound());
} }
@ -693,14 +688,14 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
if (this.root.camera.getIsMapOverlayActive()) { if (this.root.camera.getIsMapOverlayActive()) {
return; return;
} }
// Check for direction lock
if (this.isDirectionLockActive) {
return;
}
const metaBuilding = this.currentMetaBuilding.get(); const metaBuilding = this.currentMetaBuilding.get();
if ((metaBuilding || this.currentlyDeleting) && this.lastDragTile) { if ((metaBuilding || this.currentlyDeleting) && this.lastDragTile) {
// Check for direction lock
if (this.isDirectionLockActive) {
this.keepDirectionLock = true;
return;
}
const oldPos = this.lastDragTile; const oldPos = this.lastDragTile;
let newPos = this.root.camera.screenToWorld(pos).toTileSpace(); let newPos = this.root.camera.screenToWorld(pos).toTileSpace();
@ -798,6 +793,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
if (this.lastDragTile && this.currentlyDragging && this.isDirectionLockActive) { if (this.lastDragTile && this.currentlyDragging && this.isDirectionLockActive) {
this.executeDirectionLockedPlacement(); this.executeDirectionLockedPlacement();
} }
this.keepDirectionLock = false;
this.abortDragging(); this.abortDragging();
} }