mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Merge pull request #367 from MizardX/planner-initial-direction
Initial planner direction based on cursor movement
This commit is contained in:
commit
f35558bb28
@ -92,6 +92,12 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
*/
|
*/
|
||||||
this.currentDirectionLockSide = 0;
|
this.currentDirectionLockSide = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the side for direction lock has not yet been determined.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.currentDirectionLockSideIndeterminate = true;
|
||||||
|
|
||||||
this.initializeBindings();
|
this.initializeBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,6 +210,17 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
const worldPos = this.root.camera.screenToWorld(mousePosition);
|
const worldPos = this.root.camera.screenToWorld(mousePosition);
|
||||||
const mouseTile = worldPos.toTileSpace();
|
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) {
|
if (this.currentDirectionLockSide === 0) {
|
||||||
return new Vector(this.lastDragTile.x, mouseTile.y);
|
return new Vector(this.lastDragTile.x, mouseTile.y);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user