Skip to content

Commit

Permalink
Add seat spin widget to control vehicle spin value
Browse files Browse the repository at this point in the history
  • Loading branch information
guysv committed Oct 20, 2024
1 parent 3080f3f commit fbe10ed
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/services/vehicleEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const execute = register<UpdateVehicleSettingArgs>("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",
Expand All @@ -27,6 +27,7 @@ const
xPosition = "x",
yPosition = "y",
zPosition = "z",
spinKey = "spin",
primaryColour = "body",
secondaryColour = "trim",
tertiaryColour = "tertiary";
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -240,6 +249,14 @@ function updateVehicleSetting(args: UpdateVehicleSettingArgs): void
};
break;
}
case spinKey:
{
callback = (car): void =>
{
car.spin += value;
};
break;
}
case trackProgressKey:
{
callback = (car): void =>
Expand Down Expand Up @@ -278,4 +295,4 @@ function updateVehicleSetting(args: UpdateVehicleSettingArgs): void
}

forEachVehicle(targets, callback);
}
}
12 changes: 11 additions & 1 deletion src/ui/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
})
]
}),
Expand Down
2 changes: 2 additions & 0 deletions src/viewmodels/vehicleViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class VehicleViewModel
readonly _x = store<number>(0);
readonly _y = store<number>(0);
readonly _z = store<number>(0);
readonly _spin = store<number>(0);

readonly _primaryColour = store<Colour>(0);
readonly _secondaryColour = store<Colour>(0);
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fbe10ed

Please sign in to comment.