diff --git a/src/js/core/utils.js b/src/js/core/utils.js index 6c38ad98..fdf97880 100644 --- a/src/js/core/utils.js +++ b/src/js/core/utils.js @@ -978,17 +978,3 @@ export function formatItemsPerSecond(speed, double = false) { : T.ingame.buildingPlacement.infoTexts.itemsPerSecond.replace("", "" + 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); - } -} diff --git a/src/js/game/hud/parts/building_placer.js b/src/js/game/hud/parts/building_placer.js index 01b6b797..b9561dcd 100644 --- a/src/js/game/hud/parts/building_placer.js +++ b/src/js/game/hud/parts/building_placer.js @@ -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(); } /** diff --git a/src/js/game/hud/parts/building_placer_logic.js b/src/js/game/hud/parts/building_placer_logic.js index 8131bf68..05d2e48a 100644 --- a/src/js/game/hud/parts/building_placer_logic.js +++ b/src/js/game/hud/parts/building_placer_logic.js @@ -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); + } } /**