Skip to content

Commit 61808b2

Browse files
committed
Small cleanups
1 parent a0f92f8 commit 61808b2

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

src/services/vehicleDragger.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { Store } from "openrct2-flexui";
22
import { isMultiplayer } from "../environment";
33
import { getCarById, RideVehicle } from "../objects/rideVehicle";
44
import * as Log from "../utilities/logger";
5-
import { getTileElement } from "../utilities/map";
6-
import { floor } from "../utilities/math";
5+
import { alignWithMap, getTileElement, toTileUnit } from "../utilities/map";
76
import { cancelCurrentTool, cancelTools } from "../utilities/tools";
87
import { isNumber, isUndefined } from "../utilities/type";
98
import { register } from "./actions";
@@ -209,8 +208,9 @@ function updateVehicleDrag(args: DragVehicleArgs): void
209208

210209
const position = args.position;
211210
const progress = position.progress;
212-
if (isNumber(position.trackElementIndex) && isNumber(progress)) {
213-
car.moveToTrack(tileCoordinate(position.x), tileCoordinate(position.y-16), position.trackElementIndex);
211+
if (isNumber(position.trackElementIndex) && isNumber(progress))
212+
{
213+
car.moveToTrack(toTileUnit(position.x), toTileUnit(position.y), position.trackElementIndex);
214214
car.travelBy(getDistanceFromProgress(car, progress - car.trackProgress));
215215
}
216216
else
@@ -222,19 +222,3 @@ function updateVehicleDrag(args: DragVehicleArgs): void
222222

223223
invoke(refreshVehicle, id);
224224
}
225-
226-
/**
227-
* Align the coordinate with the edge of a map tile.
228-
*/
229-
function alignWithMap(coordinate: number): number
230-
{
231-
return floor(coordinate / 32) * 32;
232-
}
233-
234-
/**
235-
* Align the coordinate with the edge of a map tile.
236-
*/
237-
function tileCoordinate(coordinate: number): number
238-
{
239-
return floor(coordinate / 32);
240-
}

src/utilities/map.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
import { floor } from "./math";
22

3-
43
const UnitsPerTile = 32;
54

5+
/**
6+
* Converts a entity coordinate unit to a tile coordinate unit.
7+
*/
8+
export function toTileUnit(coordinate: number): number
9+
{
10+
return floor(coordinate / UnitsPerTile);
11+
}
12+
13+
/**
14+
* Align the coordinate with the edge of a map tile.
15+
*/
16+
export function alignWithMap(coordinate: number): number
17+
{
18+
return toTileUnit(coordinate) * UnitsPerTile;
19+
}
620

721
/**
822
* Get a tile from non-tile coordinates (like entity coordinates).
923
*/
1024
export function getTileByCoords(x: number, y: number): Tile
1125
{
12-
return map.getTile(floor(x / UnitsPerTile), floor(y / UnitsPerTile));
26+
return map.getTile(toTileUnit(x), toTileUnit(y));
1327
}
1428

1529
/**
@@ -19,4 +33,4 @@ export function getTileElement<T extends TileElement = TileElement>(x: number, y
1933
{
2034
const tile = getTileByCoords(x, y);
2135
return tile.getElement<T>(elementIdx);
22-
}
36+
}

src/viewmodels/vehicleViewModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export class VehicleViewModel
302302
{
303303
if (this._isOpen)
304304
{
305-
toggleVehicleDragger(active, this._selectedVehicle, this._x, this._y, this._z, this._trackLocation, this._trackProgress, () => this._isDragging.set(false))
305+
toggleVehicleDragger(active, this._selectedVehicle, this._x, this._y, this._z, this._trackLocation, this._trackProgress, () => this._isDragging.set(false));
306306
}
307307
}
308308

0 commit comments

Comments
 (0)