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 {