Do not choose direction lock side automatically, instead make it toggleable

pull/203/head
tobspr 4 years ago
parent 6f2578fab2
commit 4c20094878

@ -78,10 +78,10 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
this.lastDragTile = null;
/**
* Interpolate the side for direction lock slowly so it doesn't flicker
* @type {number}
* The side for direction lock
* @type {number} (0|1)
*/
this.interpolatedDirectionLockSide = 0;
this.currentDirectionLockSide = 0;
this.initializeBindings();
}
@ -94,6 +94,9 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
const keyActionMapper = this.root.keyMapper;
keyActionMapper.getBinding(KEYMAPPINGS.placement.rotateWhilePlacing).add(this.tryRotate, this);
keyActionMapper.getBinding(KEYMAPPINGS.placement.cycleBuildingVariants).add(this.cycleVariants, this);
keyActionMapper
.getBinding(KEYMAPPINGS.placement.switchDirectionLockSide)
.add(this.switchDirectionLockSide, this);
keyActionMapper
.getBinding(KEYMAPPINGS.placement.abortBuildingPlacement)
.add(this.abortPlacement, this);
@ -146,30 +149,13 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
const worldPos = this.root.camera.screenToWorld(mousePosition);
const mouseTile = worldPos.toTileSpace();
if (this.interpolatedDirectionLockSide <= 0) {
if (this.currentDirectionLockSide === 0) {
return new Vector(this.lastDragTile.x, mouseTile.y);
} else {
return new Vector(mouseTile.x, this.lastDragTile.y);
}
}
/**
* Computes on which side the direction lock should be active
* @returns {-1|0|1}
*/
get currentDirectionLockSide() {
const mousePosition = this.root.app.mousePosition;
if (!mousePosition) {
// Not on screen
return 0;
}
const worldPos = this.root.camera.screenToWorld(mousePosition);
const mouseTile = worldPos.toTileSpace();
const fractional = worldPos.sub(mouseTile.toWorldSpaceCenterOfTile());
return fractional.x + fractional.y < 0 ? -1 : 1;
}
/**
* Aborts the placement
*/
@ -199,13 +185,6 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
if (mousePos) {
this.onMouseMove(mousePos);
}
// Prevent flickering by interpolating the side
this.interpolatedDirectionLockSide = lerp(
this.interpolatedDirectionLockSide,
this.currentDirectionLockSide,
0.04
);
}
/**
@ -241,6 +220,10 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
}
}
switchDirectionLockSide() {
this.currentDirectionLockSide = 1 - this.currentDirectionLockSide;
}
/**
* Checks if the direction lock key got released and if such, resets the placement
* @param {any} args

@ -92,6 +92,11 @@ export class HUDKeybindingOverlay extends BaseHUDPart {
)}</code>
<label>${T.ingame.keybindingsOverlay.lockBeltDirection}</label>
</div>
<div class="binding placementOnly directionLock">
<code class="keybinding">${getKeycode(KEYMAPPINGS.placement.switchDirectionLockSide)}</code>
<label>${T.ingame.keybindingsOverlay.plannerSwitchSide}</label>
</div>
`
);
}

@ -61,6 +61,7 @@ export const KEYMAPPINGS = {
rotateInverseModifier: { keyCode: 16 }, // SHIFT
cycleBuildingVariants: { keyCode: key("T") },
cycleBuildings: { keyCode: 9 }, // TAB
switchDirectionLockSide: { keyCode: key("R") },
},
massSelect: {

@ -284,6 +284,7 @@ ingame:
delete: Destroy
pasteLastBlueprint: Paste last blueprint
lockBeltDirection: Enable belt planner
plannerSwitchSide: Flip planner side
# Everything related to placing buildings (I.e. as soon as you selected a building
# from the toolbar)
@ -743,6 +744,8 @@ keybindings:
pasteLastBlueprint: Paste last blueprint
cycleBuildings: Cycle Buildings
lockBeltDirection: Enable belt planner
switchDirectionLockSide: >-
Planner: Switch side
massSelectStart: Hold and drag to start
massSelectSelectMultiple: Select multiple areas

Loading…
Cancel
Save