From 3080f3fae9dfaa02dd30b59f4495ae81623b6df8 Mon Sep 17 00:00:00 2001 From: guysv Date: Thu, 17 Oct 2024 00:10:38 +0300 Subject: [PATCH 1/3] Fix breaking changes for new openrct2.d.ts --- src/services/spacingEditor.ts | 4 ++-- src/services/vehiclePicker.ts | 2 +- tests/services/spacingEditor.tests.ts | 30 +++++++++++++-------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/services/spacingEditor.ts b/src/services/spacingEditor.ts index 6af5232..7ab26ef 100644 --- a/src/services/spacingEditor.ts +++ b/src/services/spacingEditor.ts @@ -44,7 +44,7 @@ export function getDistanceFromProgress(car: Car, trackProgress: number): number ? new ForwardIterator(trackProgress, currentProgress) : new BackwardIterator(abs(trackProgress), currentProgress); - let trackPosition = currentTrackLocation; + let trackPosition = currentTrackLocation as CoordsXYZD; let trackDistances = getTrackDistances(iteratorSegment, subposition, trackPosition.direction); subpositionIterator._setInitialDistanceFromCarRemainingDistance(car.remainingDistance); @@ -371,4 +371,4 @@ class BackwardIterator extends SubpositionIterator nextTile.z + nextTrack._endZ ); } -} \ No newline at end of file +} diff --git a/src/services/vehiclePicker.ts b/src/services/vehiclePicker.ts index b32fb5a..a7f5562 100644 --- a/src/services/vehiclePicker.ts +++ b/src/services/vehiclePicker.ts @@ -73,7 +73,7 @@ export function toggleVehiclePicker(isPressed: boolean, onPick: (car: Car) => vo /** * Finds a car within a certain range of the selected tile element. */ -function findCarNearbyTileElement(coords: CoordsXYZ, elementIdx: number): Car | undefined +function findCarNearbyTileElement(coords: CoordsXY, elementIdx: number): Car | undefined { const element = getTileElement(coords.x, coords.y, elementIdx); const entitiesOnTile = map.getAllEntitiesOnTile("car", coords); diff --git a/tests/services/spacingEditor.tests.ts b/tests/services/spacingEditor.tests.ts index 17c6913..b172768 100644 --- a/tests/services/spacingEditor.tests.ts +++ b/tests/services/spacingEditor.tests.ts @@ -326,7 +326,7 @@ const multiTurnTest = test.macro({ exec(t, startTrackPiece: number, startProgress: number, progress: number, expectedResult: number): void { const trackPieces = [ rightTurn1TrackPiece, rightTurn2TrackPiece, steepUpTrackPiece, steepTurnTrackPiece ]; - const trackLocation: CoordsXYZD = { ...trackPieces[startTrackPiece].position, direction: 0 }; + const trackLocation: CarTrackLocation = { ...trackPieces[startTrackPiece].position, direction: 0, trackType: 0 }; setupTrackIterator(trackPieces, startTrackPiece); const car = Mock.car({ trackProgress: startProgress, trackLocation, remainingDistance: (progress >= 0) ? ForwardRemainingDistance : 0 }); @@ -405,8 +405,8 @@ test("Flat track: get spacing to preceding vehicle 1 step away", t => { const mapMock = setupTrackIterator([ flatTrackPiece ]); const train = createTrain(mapMock, [ - { trackProgress: 17, trackLocation: flatTrackPiece.position }, // front car - { trackProgress: 16, trackLocation: flatTrackPiece.position } + { trackProgress: 17, trackLocation: {...flatTrackPiece.position, trackType: flatTrackPiece.type} }, // front car + { trackProgress: 16, trackLocation: {...flatTrackPiece.position, trackType: flatTrackPiece.type} } ]); const spacing = getSpacingToPrecedingVehicle(train, train._at(1)._car(), 1); @@ -419,8 +419,8 @@ test("Flat track: get spacing to preceding vehicle 10 step away", t => { const mapMock = setupTrackIterator([ flatTrackPiece ]); const train = createTrain(mapMock, [ - { trackProgress: 17, trackLocation: flatTrackPiece.position }, // front car - { trackProgress: 7, trackLocation: flatTrackPiece.position } + { trackProgress: 17, trackLocation: {...flatTrackPiece.position, trackType: flatTrackPiece.type} }, // front car + { trackProgress: 7, trackLocation: {...flatTrackPiece.position, trackType: flatTrackPiece.type} } ]); const spacing = getSpacingToPrecedingVehicle(train, train._at(1)._car(), 1); @@ -433,8 +433,8 @@ test("Flat track: get spacing to preceding vehicle 31 step away", t => { const mapMock = setupTrackIterator([ flatTrackPiece ]); const train = createTrain(mapMock, [ - { trackProgress: 31, trackLocation: flatTrackPiece.position }, // front car - { trackProgress: 0, trackLocation: flatTrackPiece.position } // back car + { trackProgress: 31, trackLocation: {...flatTrackPiece.position, trackType: flatTrackPiece.type} }, // front car + { trackProgress: 0, trackLocation: {...flatTrackPiece.position, trackType: flatTrackPiece.type} } // back car ]); const spacing = getSpacingToPrecedingVehicle(train, train._at(1)._car(), 1); @@ -447,8 +447,8 @@ test("Flat track: get spacing to preceding vehicle is too far away", t => { const mapMock = setupTrackIterator([ flatTrackPiece ]); const train = createTrain(mapMock, [ - { trackProgress: 15, trackLocation: { x: 10, y: 10, z: 10, direction: 0 } }, // front car - { trackProgress: 10, trackLocation: flatTrackPiece.position } + { trackProgress: 15, trackLocation: { x: 10, y: 10, z: 10, direction: 0, trackType: 0 } }, // front car + { trackProgress: 10, trackLocation: {...flatTrackPiece.position, trackType: 0}, } ]); const spacing = getSpacingToPrecedingVehicle(train, train._at(1)._car(), 1); @@ -462,8 +462,8 @@ test("Two flat tracks: get spacing to next track piece by 1", t => const pieces = [ flatTrackPiece.copyTo(32, 64), flatTrackPiece.copyTo(32, 32) ]; const mapMock = setupTrackIterator(pieces); const train = createTrain(mapMock, [ - { trackProgress: 0, trackLocation: pieces[1].position }, // front car - { trackProgress: 31, trackLocation: pieces[0].position } // back car + { trackProgress: 0, trackLocation: {...pieces[1].position, trackType: pieces[1].type} }, // front car + { trackProgress: 31, trackLocation: {...pieces[0].position, trackType: pieces[0].type} } // back car ]); const car = train._at(1)._car(); @@ -478,8 +478,8 @@ test("Two flat tracks: get spacing to next track piece by 10", t => const pieces = [ flatTrackPiece.copyTo(32, 64), flatTrackPiece.copyTo(32, 32) ]; const mapMock = setupTrackIterator(pieces); const train = createTrain(mapMock, [ - { trackProgress: 3, trackLocation: pieces[1].position }, // front car - { trackProgress: 25, trackLocation: pieces[0].position } // back car + { trackProgress: 3, trackLocation: {...pieces[1].position, trackType: pieces[1].type} }, // front car + { trackProgress: 25, trackLocation: {...pieces[0].position, trackType: pieces[0].type} } // back car ]); const car = train._at(1)._car(); @@ -494,8 +494,8 @@ test("Three flat tracks: get spacing to next track piece by 50", t => const pieces = [ flatTrackPiece.copyTo(32, 96), flatTrackPiece.copyTo(32, 64), flatTrackPiece.copyTo(32, 32) ]; const mapMock = setupTrackIterator(pieces); const train = createTrain(mapMock, [ - { trackProgress: 5, trackLocation: pieces[2].position }, // front car - { trackProgress: 19, trackLocation: pieces[0].position } // back car + { trackProgress: 5, trackLocation: {...pieces[2].position, trackType: pieces[2].type} }, // front car + { trackProgress: 19, trackLocation: {...pieces[0].position, trackType: pieces[0].type} } // back car ]); const car = train._at(1)._car(); From fbe10ed3278044ec1c15b305aa5b1bb28a4b13eb Mon Sep 17 00:00:00 2001 From: guysv Date: Sun, 20 Oct 2024 17:49:21 +0300 Subject: [PATCH 2/3] Add seat spin widget to control vehicle spin value --- src/services/vehicleEditor.ts | 21 +++++++++++++++++++-- src/ui/mainWindow.ts | 12 +++++++++++- src/viewmodels/vehicleViewModel.ts | 2 ++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/services/vehicleEditor.ts b/src/services/vehicleEditor.ts index cfb1902..390d138 100644 --- a/src/services/vehicleEditor.ts +++ b/src/services/vehicleEditor.ts @@ -12,7 +12,7 @@ const execute = register("rve-update-car", updateVehic type VehicleUpdateKeys = "rideObject" | "vehicleObject" | "isReversed" | "trackProgress" | "spacing" | "numSeats" | "mass" | "poweredAcceleration" | "poweredMaxSpeed" | "x" | "y" | "z" - | "body" | "trim" | "tertiary"; + | "spin" | "body" | "trim" | "tertiary"; const rideTypeKey = "rideObject", @@ -27,6 +27,7 @@ const xPosition = "x", yPosition = "y", zPosition = "z", + spinKey = "spin", primaryColour = "body", secondaryColour = "trim", tertiaryColour = "tertiary"; @@ -153,6 +154,14 @@ export function setPositionZ(vehicles: VehicleSpan[], z: number): void updateValue(vehicles, zPosition, z); } +/** + * Sets the z position for this vehicle. + */ +export function setSpin(vehicles: VehicleSpan[], spin: number): void +{ + updateValue(vehicles, spinKey, spin); +} + /** * Arguments for updating a single key in a vehicle object. @@ -240,6 +249,14 @@ function updateVehicleSetting(args: UpdateVehicleSettingArgs): void }; break; } + case spinKey: + { + callback = (car): void => + { + car.spin += value; + }; + break; + } case trackProgressKey: { callback = (car): void => @@ -278,4 +295,4 @@ function updateVehicleSetting(args: UpdateVehicleSettingArgs): void } forEachVehicle(targets, callback); -} \ No newline at end of file +} diff --git a/src/ui/mainWindow.ts b/src/ui/mainWindow.ts index d906ac9..11cdf0e 100644 --- a/src/ui/mainWindow.ts +++ b/src/ui/mainWindow.ts @@ -4,7 +4,7 @@ import { RideVehicleVariant, VehicleVisibility } from "../objects/rideVehicleVar import { invoke, refreshRide } from "../services/events"; import { applyToTargets, CopyFilter, getTargets, getVehicleSettings } from "../services/vehicleCopier"; import { dragToolId, toggleVehicleDragger } from "../services/vehicleDragger"; -import { changeSpacing, changeTrackProgress, setMass, setPositionX, setPositionY, setPositionZ, setPoweredAcceleration, setPoweredMaximumSpeed, setPrimaryColour, setReversed, setRideType, setSeatCount, setSecondaryColour, setTertiaryColour, setVariant } from "../services/vehicleEditor"; +import { changeSpacing, changeTrackProgress, setMass, setPositionX, setPositionY, setPositionZ, setPoweredAcceleration, setPoweredMaximumSpeed, setPrimaryColour, setReversed, setRideType, setSeatCount, setSecondaryColour, setSpin, setTertiaryColour, setVariant } from "../services/vehicleEditor"; import { locate } from "../services/vehicleLocater"; import { pickerToolId, toggleVehiclePicker } from "../services/vehiclePicker"; import { cancelTools } from "../utilities/tools"; @@ -375,6 +375,16 @@ export const mainWindow = window({ value: model._z, format: model._formatPosition, onChange: (_, incr) => model._modifyVehicle(setPositionZ, incr) + }), + positionSpinner({ + _label: { text: "Seat spin:" }, + minimum: 0, + maximum: 255, + disabled: model._isPositionDisabled, + step: model._multiplier, + value: model._spin, + format: model._formatPosition, + onChange: (_, incr) => model._modifyVehicle(setSpin, incr) }) ] }), diff --git a/src/viewmodels/vehicleViewModel.ts b/src/viewmodels/vehicleViewModel.ts index 85417fb..97ac132 100644 --- a/src/viewmodels/vehicleViewModel.ts +++ b/src/viewmodels/vehicleViewModel.ts @@ -41,6 +41,7 @@ export class VehicleViewModel readonly _x = store(0); readonly _y = store(0); readonly _z = store(0); + readonly _spin = store(0); readonly _primaryColour = store(0); readonly _secondaryColour = store(0); @@ -277,6 +278,7 @@ export class VehicleViewModel this._x.set(car.x); this._y.set(car.y); this._z.set(car.z); + this._spin.set(car.spin); const train = this._selectedTrain.get(); if (train) From 176f40c03e152f3e20519c818e3f074431cbb4a9 Mon Sep 17 00:00:00 2001 From: guysv Date: Mon, 21 Oct 2024 23:31:41 +0300 Subject: [PATCH 3/3] spin control review fixes --- src/services/spacingEditor.ts | 2 +- src/services/vehicleEditor.ts | 9 +-------- src/ui/mainWindow.ts | 8 ++++---- tests/services/spacingEditor.tests.ts | 17 +++++++++++------ 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/services/spacingEditor.ts b/src/services/spacingEditor.ts index 7ab26ef..149954b 100644 --- a/src/services/spacingEditor.ts +++ b/src/services/spacingEditor.ts @@ -44,7 +44,7 @@ export function getDistanceFromProgress(car: Car, trackProgress: number): number ? new ForwardIterator(trackProgress, currentProgress) : new BackwardIterator(abs(trackProgress), currentProgress); - let trackPosition = currentTrackLocation as CoordsXYZD; + let trackPosition: CoordsXYZD = currentTrackLocation; let trackDistances = getTrackDistances(iteratorSegment, subposition, trackPosition.direction); subpositionIterator._setInitialDistanceFromCarRemainingDistance(car.remainingDistance); diff --git a/src/services/vehicleEditor.ts b/src/services/vehicleEditor.ts index 390d138..8309fcd 100644 --- a/src/services/vehicleEditor.ts +++ b/src/services/vehicleEditor.ts @@ -232,6 +232,7 @@ function updateVehicleSetting(args: UpdateVehicleSettingArgs): void case massKey: case poweredAccelerationKey: case poweredMaxSpeedKey: + case spinKey: { callback = (car): void => { @@ -249,14 +250,6 @@ function updateVehicleSetting(args: UpdateVehicleSettingArgs): void }; break; } - case spinKey: - { - callback = (car): void => - { - car.spin += value; - }; - break; - } case trackProgressKey: { callback = (car): void => diff --git a/src/ui/mainWindow.ts b/src/ui/mainWindow.ts index 11cdf0e..5e2e0d0 100644 --- a/src/ui/mainWindow.ts +++ b/src/ui/mainWindow.ts @@ -376,15 +376,15 @@ export const mainWindow = window({ format: model._formatPosition, onChange: (_, incr) => model._modifyVehicle(setPositionZ, incr) }), - positionSpinner({ + labelSpinner({ _label: { text: "Seat spin:" }, minimum: 0, maximum: 255, - disabled: model._isPositionDisabled, + disabled: model._isEditDisabled, step: model._multiplier, value: model._spin, - format: model._formatPosition, - onChange: (_, incr) => model._modifyVehicle(setSpin, incr) + wrapMode: "clampThenWrap", + onChange: value => model._modifyVehicle(setSpin, value) }) ] }), diff --git a/tests/services/spacingEditor.tests.ts b/tests/services/spacingEditor.tests.ts index b172768..7f185c8 100644 --- a/tests/services/spacingEditor.tests.ts +++ b/tests/services/spacingEditor.tests.ts @@ -20,6 +20,11 @@ class TrackPiece { return new TrackPiece({ x, y, z, direction }, this.type, this.subpositions); } + + toLocation(): CarTrackLocation + { + return { ...this.position, trackType: this.type }; + } } const flatTrackPiece = new TrackPiece({ x: 0, y: 0, z: 0, direction: 0 }, 1, @@ -462,8 +467,8 @@ test("Two flat tracks: get spacing to next track piece by 1", t => const pieces = [ flatTrackPiece.copyTo(32, 64), flatTrackPiece.copyTo(32, 32) ]; const mapMock = setupTrackIterator(pieces); const train = createTrain(mapMock, [ - { trackProgress: 0, trackLocation: {...pieces[1].position, trackType: pieces[1].type} }, // front car - { trackProgress: 31, trackLocation: {...pieces[0].position, trackType: pieces[0].type} } // back car + { trackProgress: 0, trackLocation: pieces[1].toLocation() }, // front car + { trackProgress: 31, trackLocation: pieces[0].toLocation() } // back car ]); const car = train._at(1)._car(); @@ -478,8 +483,8 @@ test("Two flat tracks: get spacing to next track piece by 10", t => const pieces = [ flatTrackPiece.copyTo(32, 64), flatTrackPiece.copyTo(32, 32) ]; const mapMock = setupTrackIterator(pieces); const train = createTrain(mapMock, [ - { trackProgress: 3, trackLocation: {...pieces[1].position, trackType: pieces[1].type} }, // front car - { trackProgress: 25, trackLocation: {...pieces[0].position, trackType: pieces[0].type} } // back car + { trackProgress: 3, trackLocation: pieces[1].toLocation() }, // front car + { trackProgress: 25, trackLocation: pieces[0].toLocation() } // back car ]); const car = train._at(1)._car(); @@ -494,8 +499,8 @@ test("Three flat tracks: get spacing to next track piece by 50", t => const pieces = [ flatTrackPiece.copyTo(32, 96), flatTrackPiece.copyTo(32, 64), flatTrackPiece.copyTo(32, 32) ]; const mapMock = setupTrackIterator(pieces); const train = createTrain(mapMock, [ - { trackProgress: 5, trackLocation: {...pieces[2].position, trackType: pieces[2].type} }, // front car - { trackProgress: 19, trackLocation: {...pieces[0].position, trackType: pieces[0].type} } // back car + { trackProgress: 5, trackLocation: pieces[2].toLocation() }, // front car + { trackProgress: 19, trackLocation: pieces[0].toLocation() } // back car ]); const car = train._at(1)._car();