From 322e7fbcc93b29cfaaab3362eec866df40a9ea7e Mon Sep 17 00:00:00 2001 From: MizardX Date: Thu, 2 Jul 2020 01:13:49 +0200 Subject: [PATCH] Initial planner direction based on cursor movement --- src/js/game/hud/parts/building_placer_logic.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/js/game/hud/parts/building_placer_logic.js b/src/js/game/hud/parts/building_placer_logic.js index d0737df8..73fe40b4 100644 --- a/src/js/game/hud/parts/building_placer_logic.js +++ b/src/js/game/hud/parts/building_placer_logic.js @@ -92,6 +92,12 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { */ this.currentDirectionLockSide = 0; + /** + * Whether the side for direction lock has not yet been determined. + * @type {boolean} + */ + this.currentDirectionLockSideIndeterminate = true; + this.initializeBindings(); } @@ -204,6 +210,17 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { const worldPos = this.root.camera.screenToWorld(mousePosition); const mouseTile = worldPos.toTileSpace(); + // Figure initial direction + const dx = Math.abs(this.lastDragTile.x - mouseTile.x); + const dy = Math.abs(this.lastDragTile.y - mouseTile.y); + if (dx === 0 && dy === 0) { + // Back at the start. Try a new direction. + this.currentDirectionLockSideIndeterminate = true; + } else if (this.currentDirectionLockSideIndeterminate) { + this.currentDirectionLockSideIndeterminate = false; + this.currentDirectionLockSide = dx <= dy ? 0 : 1; + } + if (this.currentDirectionLockSide === 0) { return new Vector(this.lastDragTile.x, mouseTile.y); } else {