mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Improve belt direction lock
This commit is contained in:
parent
84969a9205
commit
a95e69401d
@ -978,17 +978,3 @@ export function formatItemsPerSecond(speed, double = false) {
|
||||
: T.ingame.buildingPlacement.infoTexts.itemsPerSecond.replace("<x>", "" + round2Digits(speed)) +
|
||||
(double ? " " + T.ingame.buildingPlacement.infoTexts.itemsPerSecondDouble : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the corner point between two vectors
|
||||
* @param {Vector} a
|
||||
* @param {Vector} b
|
||||
*/
|
||||
export function findCornerBetweenPoints(a, b) {
|
||||
const delta = b.sub(a);
|
||||
if (Math_abs(delta.x) > Math_abs(delta.y)) {
|
||||
return new Vector(a.x, b.y);
|
||||
} else {
|
||||
return new Vector(b.x, a.y);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,13 @@ import { globalConfig } from "../../../core/config";
|
||||
import { DrawParameters } from "../../../core/draw_parameters";
|
||||
import { drawRotatedSprite } from "../../../core/draw_utils";
|
||||
import { Loader } from "../../../core/loader";
|
||||
import { findCornerBetweenPoints, makeDiv, removeAllChildren } from "../../../core/utils";
|
||||
import { enumDirectionToAngle, enumDirectionToVector, enumInvertedDirections } from "../../../core/vector";
|
||||
import { makeDiv, removeAllChildren } from "../../../core/utils";
|
||||
import {
|
||||
enumDirectionToAngle,
|
||||
enumDirectionToVector,
|
||||
enumInvertedDirections,
|
||||
Vector,
|
||||
} from "../../../core/vector";
|
||||
import { T } from "../../../translations";
|
||||
import { KEYMAPPINGS } from "../../key_action_mapper";
|
||||
import { defaultBuildingVariant } from "../../meta_building";
|
||||
@ -42,8 +47,9 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
||||
this.signals.variantChanged.add(this.rerenderVariants, this);
|
||||
|
||||
this.domAttach = new DynamicDomAttach(this.root, this.element, {});
|
||||
|
||||
this.variantsAttach = new DynamicDomAttach(this.root, this.variantsElement, {});
|
||||
|
||||
this.currentInterpolatedCornerTile = new Vector();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,6 @@ import { Math_abs, Math_degrees, Math_round } from "../../../core/builtins";
|
||||
import { globalConfig } from "../../../core/config";
|
||||
import { Signal, STOP_PROPAGATION } from "../../../core/signal";
|
||||
import { TrackedState } from "../../../core/tracked_state";
|
||||
import { findCornerBetweenPoints } from "../../../core/utils";
|
||||
import { Vector } from "../../../core/vector";
|
||||
import { enumMouseButton } from "../../camera";
|
||||
import { StaticMapEntityComponent } from "../../components/static_map_entity";
|
||||
@ -31,6 +30,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
||||
// Signals
|
||||
this.signals = {
|
||||
variantChanged: new Signal(),
|
||||
draggingStarted: new Signal(),
|
||||
};
|
||||
|
||||
/**
|
||||
@ -137,8 +137,14 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
||||
// Figure which points the line visits
|
||||
const worldPos = this.root.camera.screenToWorld(mousePosition);
|
||||
const mouseTile = worldPos.toTileSpace();
|
||||
const cornerTile = findCornerBetweenPoints(this.lastDragTile, mouseTile);
|
||||
return cornerTile;
|
||||
|
||||
const fractional = worldPos.sub(mouseTile.toWorldSpaceCenterOfTile());
|
||||
|
||||
if (fractional.x + fractional.y < 0) {
|
||||
return new Vector(this.lastDragTile.x, mouseTile.y);
|
||||
} else {
|
||||
return new Vector(mouseTile.x, this.lastDragTile.y);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user