From fbe10ed3278044ec1c15b305aa5b1bb28a4b13eb Mon Sep 17 00:00:00 2001 From: guysv Date: Sun, 20 Oct 2024 17:49:21 +0300 Subject: [PATCH] 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)