diff --git a/src/js/game/hud/parts/building_placer_logic.js b/src/js/game/hud/parts/building_placer_logic.js index d73e4f6a..7a7a13a2 100644 --- a/src/js/game/hud/parts/building_placer_logic.js +++ b/src/js/game/hud/parts/building_placer_logic.js @@ -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 diff --git a/src/js/game/hud/parts/keybinding_overlay.js b/src/js/game/hud/parts/keybinding_overlay.js index 90d07c52..e469bcca 100644 --- a/src/js/game/hud/parts/keybinding_overlay.js +++ b/src/js/game/hud/parts/keybinding_overlay.js @@ -92,6 +92,11 @@ export class HUDKeybindingOverlay extends BaseHUDPart { )} + +
+ ${getKeycode(KEYMAPPINGS.placement.switchDirectionLockSide)} + +
` ); } diff --git a/src/js/game/key_action_mapper.js b/src/js/game/key_action_mapper.js index 04491d7f..6a1e265c 100644 --- a/src/js/game/key_action_mapper.js +++ b/src/js/game/key_action_mapper.js @@ -61,6 +61,7 @@ export const KEYMAPPINGS = { rotateInverseModifier: { keyCode: 16 }, // SHIFT cycleBuildingVariants: { keyCode: key("T") }, cycleBuildings: { keyCode: 9 }, // TAB + switchDirectionLockSide: { keyCode: key("R") }, }, massSelect: { diff --git a/translations/base-en.yaml b/translations/base-en.yaml index 13052fca..8321e20b 100644 --- a/translations/base-en.yaml +++ b/translations/base-en.yaml @@ -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