Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b6ff651
add configurable selection of vehicles on train as a target
Manticore-007 May 22, 2025
c873fc2
changed `let` to `const`
Manticore-007 May 22, 2025
82367ec
fix: multiple `Opening curly brace appears on the same line as contro…
Manticore-007 May 22, 2025
337d15d
fix: edited expression to function call
Manticore-007 May 22, 2025
f250fc9
changed `Custom selection of vehicles` to `Specific vehicles`
Manticore-007 May 22, 2025
41de90e
fixed `setSequence` function
Manticore-007 May 23, 2025
3e41c69
fixed opening curly brace
Manticore-007 May 23, 2025
9742eb9
removed export from function
Manticore-007 May 23, 2025
d7eff63
fixed lastVehicle variable
Manticore-007 May 23, 2025
192f02e
changed "last vehicle" to "amount of vehicles"
Manticore-007 May 23, 2025
10e005e
Forgot an underscore
Manticore-007 May 23, 2025
ac9a50b
fixed values for "amount of vehicles" spinner
Manticore-007 May 23, 2025
bbeb56e
Menus for Specific vehicles on all trains
Manticore-007 May 23, 2025
aa5b16f
add configurable selection of vehicles on all trains as a target
Manticore-007 May 23, 2025
5d21d88
added all trains check
Manticore-007 May 23, 2025
650a717
renamed function
Manticore-007 May 24, 2025
7432047
Fixed the code so every key including `spacing` works
Manticore-007 May 24, 2025
c9cc11e
fixed amount of vehicles after closing and reopening plugin
Manticore-007 May 24, 2025
ab74f51
Menus for Specific vehicles on all trains
Manticore-007 May 23, 2025
6dd297f
add configurable selection of vehicles on all trains as a target
Manticore-007 May 23, 2025
f3c97c9
Merge branch 'Specific-vehicles-on-all-trains' of https://github.com/…
Manticore-007 May 24, 2025
2a14aa0
dropdowns visible for specific vehicles on all trains
Manticore-007 May 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/services/vehicleCopier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ export const enum CopyOptions
AllVehiclesOnTrain,
PrecedingVehiclesOnTrain,
FollowingVehiclesOnTrain,
SpecificVehiclesOnTrain,
AllVehiclesOnAllTrains,
PrecedingVehiclesOnAllTrains,
FollowingVehiclesOnAllTrains,
SameVehicleOnAllTrains
SameVehicleOnAllTrains,
SpecificVehiclesOnAllTrains
}

/**
Expand All @@ -31,10 +33,12 @@ export const copyOptions = <const>[
"All vehicles on this train",
"Preceding vehicles on this train",
"Following vehicles on this train",
"Specific vehicles on this train",
"All vehicles on all trains",
"Preceding vehicles on all trains",
"Following vehicles on all trains",
"Same vehicle number on all trains"
"Same vehicle number on all trains",
"Specific vehicles on all trains"
];


Expand Down Expand Up @@ -62,7 +66,7 @@ export const enum CopyFilter
* Gets the targeted vehicles based on the selected copy option, in the following
* format; [[ car id, amount of following cars (inclusive) ], ...].
*/
export function getTargets(copyOption: CopyOptions, ride: [ParkRide, number] | null, train: [RideTrain, number] | null, vehicle: [RideVehicle, number] | null): [number, number | null][]
export function getTargets(copyOption: CopyOptions, ride: [ParkRide, number] | null, train: [RideTrain, number] | null, vehicle: [RideVehicle, number] | null, amount: number): [number, number | null][]
{
if (ride && train && vehicle)
{
Expand All @@ -80,6 +84,10 @@ export function getTargets(copyOption: CopyOptions, ride: [ParkRide, number] | n
{
return [[ vehicle[0]._id, null ]];
}
case CopyOptions.SpecificVehiclesOnTrain:
{
return [[ vehicle[0]._id, amount ]];
}
case CopyOptions.AllVehiclesOnAllTrains:
{
return getTargetsOnAllTrains(ride, t => [ t._carId, null ]);
Expand All @@ -99,6 +107,11 @@ export function getTargets(copyOption: CopyOptions, ride: [ParkRide, number] | n
const index = vehicle[1];
return getTargetsOnAllTrains(ride, t => [ t._at(index)._id, 1 ]);
}
case CopyOptions.SpecificVehiclesOnAllTrains:
{
const index = vehicle[1];
return getTargetsOnAllTrains(ride, t => [ t._at(index)._id, amount ]);
}
}
}
Log.assert(true, "getTargets(), selected copy option out of range:", copyOption, ", or vehicle not selected:", vehicle);
Expand Down Expand Up @@ -157,9 +170,9 @@ export function getVehicleSettings(source: RideVehicle, filters: CopyFilter): Ve
/**
* Applies the set of vehicle settings to the specified targets.
*/
export function applyToTargets(settings: VehicleSettings, targets: [number, number | null][]): void
export function applyToTargets(settings: VehicleSettings, targets: [number, number | null][], sequence: number): void
{
execute({ settings, targets });
execute({ settings, targets, sequence });
}


Expand Down Expand Up @@ -192,6 +205,7 @@ interface PasteVehicleSettingsArgs
{
settings: VehicleSettings;
targets: VehicleSpan[];
sequence: number;
}


Expand All @@ -200,7 +214,7 @@ interface PasteVehicleSettingsArgs
*/
function pasteVehicleSettings(args: PasteVehicleSettingsArgs): void
{
forEachVehicle(args.targets, car => applyVehicleSettings(car, args.settings));
forEachVehicle(args.targets, args.sequence, car => applyVehicleSettings(car, args.settings));
}


Expand Down
71 changes: 36 additions & 35 deletions src/services/vehicleEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,129 +36,129 @@ const
* Sets the ride type for this vehicle. Resets all other properties
* to their default values for that type.
*/
export function setRideType(vehicles: VehicleSpan[], type: RideType): void
export function setRideType(vehicles: VehicleSpan[], type: RideType, sequence: number): void
{
updateValue(vehicles, rideTypeKey, type._id);
updateValue(vehicles, rideTypeKey, type._id, sequence);
}

/**
* Sets the vehicle sprite variant. (e.g. locomotive, tender or passenger car)
*/
export function setVariant(vehicles: VehicleSpan[], variant: number): void
export function setVariant(vehicles: VehicleSpan[], variant: number, sequence: number): void
{
updateValue(vehicles, variantKey, variant);
updateValue(vehicles, variantKey, variant, sequence);
}

/**
* Sets whether the vehicle should be reversed on the track or not.
*/
export function setReversed(vehicles: VehicleSpan[], reversed: boolean): void
export function setReversed(vehicles: VehicleSpan[], reversed: boolean, sequence: number): void
{
updateValue(vehicles, reversedKey, <number><unknown>reversed);
updateValue(vehicles, reversedKey, <number><unknown>reversed, sequence);
}

/**
* Moves the vehicle a relative distance along the track.
*/
export function changeTrackProgress(vehicles: VehicleSpan[], trackProgress: number): void
export function changeTrackProgress(vehicles: VehicleSpan[], trackProgress: number, sequence: number): void
{
updateValue(vehicles, trackProgressKey, trackProgress);
updateValue(vehicles, trackProgressKey, trackProgress, sequence);
}

/**
* Moves the vehicle a relative distance away from the vehicle before it.
*/
export function changeSpacing(vehicles: VehicleSpan[], trackProgress: number): void
export function changeSpacing(vehicles: VehicleSpan[], trackProgress: number, sequence: number): void
{
updateValue(vehicles, spacingKey, trackProgress);
updateValue(vehicles, spacingKey, trackProgress, sequence);
}

/**
* Sets the maximum number of seats for this vehicle.
*/
export function setSeatCount(vehicles: VehicleSpan[], seats: number): void
export function setSeatCount(vehicles: VehicleSpan[], seats: number, sequence: number): void
{
updateValue(vehicles, seatsKey, seats);
updateValue(vehicles, seatsKey, seats, sequence);
}

/**
* Sets the mass for this vehicle.
*/
export function setMass(vehicles: VehicleSpan[], mass: number): void
export function setMass(vehicles: VehicleSpan[], mass: number, sequence: number): void
{
updateValue(vehicles, massKey, mass);
updateValue(vehicles, massKey, mass, sequence);
}

/**
* Sets the powered acceleration for this vehicle.
*/
export function setPoweredAcceleration(vehicles: VehicleSpan[], power: number): void
export function setPoweredAcceleration(vehicles: VehicleSpan[], power: number, sequence: number): void
{
updateValue(vehicles, poweredAccelerationKey, power);
updateValue(vehicles, poweredAccelerationKey, power, sequence);
}

/**
* Sets the powered acceleration for this vehicle.
*/
export function setPoweredMaximumSpeed(vehicles: VehicleSpan[], maximumSpeed: number): void
export function setPoweredMaximumSpeed(vehicles: VehicleSpan[], maximumSpeed: number, sequence: number): void
{
updateValue(vehicles, poweredMaxSpeedKey, maximumSpeed);
updateValue(vehicles, poweredMaxSpeedKey, maximumSpeed, sequence);
}

/**
* Sets the primary colour for this vehicle.
*/
export function setPrimaryColour(vehicles: VehicleSpan[], colour: Colour): void
export function setPrimaryColour(vehicles: VehicleSpan[], colour: Colour, sequence: number): void
{
updateValue(vehicles, primaryColour, colour);
updateValue(vehicles, primaryColour, colour, sequence);
}

/**
* Sets the secondary colour for this vehicle.
*/
export function setSecondaryColour(vehicles: VehicleSpan[], colour: Colour): void
export function setSecondaryColour(vehicles: VehicleSpan[], colour: Colour, sequence: number): void
{
updateValue(vehicles, secondaryColour, colour);
updateValue(vehicles, secondaryColour, colour, sequence);
}

/**
* Sets the tertiary colour for this vehicle.
*/
export function setTertiaryColour(vehicles: VehicleSpan[], colour: Colour): void
export function setTertiaryColour(vehicles: VehicleSpan[], colour: Colour, sequence: number): void
{
updateValue(vehicles, tertiaryColour, colour);
updateValue(vehicles, tertiaryColour, colour, sequence);
}

/**
* Sets the x position for this vehicle.
*/
export function setPositionX(vehicles: VehicleSpan[], x: number): void
export function setPositionX(vehicles: VehicleSpan[], x: number, sequence: number): void
{
updateValue(vehicles, xPosition, x);
updateValue(vehicles, xPosition, x, sequence);
}

/**
* Sets the y position for this vehicle.
*/
export function setPositionY(vehicles: VehicleSpan[], y: number): void
export function setPositionY(vehicles: VehicleSpan[], y: number, sequence: number): void
{
updateValue(vehicles, yPosition, y);
updateValue(vehicles, yPosition, y, sequence);
}

/**
* Sets the z position for this vehicle.
*/
export function setPositionZ(vehicles: VehicleSpan[], z: number): void
export function setPositionZ(vehicles: VehicleSpan[], z: number, sequence: number): void
{
updateValue(vehicles, zPosition, z);
updateValue(vehicles, zPosition, z, sequence);
}

/**
* Sets the z position for this vehicle.
*/
export function setSpin(vehicles: VehicleSpan[], spin: number): void
export function setSpin(vehicles: VehicleSpan[], spin: number, sequence: number): void
{
updateValue(vehicles, spinKey, spin);
updateValue(vehicles, spinKey, spin, sequence);
}


Expand All @@ -170,14 +170,15 @@ interface UpdateVehicleSettingArgs
targets: VehicleSpan[];
key: VehicleUpdateKeys;
value: number;
sequence: number;
}

/**
* Dispatches an update game action to other clients to update the specified key.
*/
function updateValue(vehicles: VehicleSpan[], key: VehicleUpdateKeys, value: number): void
function updateValue(vehicles: VehicleSpan[], key: VehicleUpdateKeys, value: number, sequence: number): void
{
execute({ targets: vehicles, key, value });
execute({ targets: vehicles, key, value, sequence });
}

/**
Expand Down Expand Up @@ -293,7 +294,7 @@ function updateVehicleSetting(args: UpdateVehicleSettingArgs): void
}
}

forEachVehicle(targets, callback);
forEachVehicle(targets, args.sequence, callback);
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/services/vehicleSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type VehicleSpan = [number, number | null];
/**
* Applies a specific callback for each vehicle in the specified list of vehicle spans.
*/
export function forEachVehicle(vehicles: VehicleSpan[], action: (car: Car, index: number) => void): void
export function forEachVehicle(vehicles: VehicleSpan[], sequence: number, action: (car: Car, index: number) => void): void
{
for (let s = 0, sl = vehicles.length; s < sl; s++)
{
Expand All @@ -29,10 +29,11 @@ export function forEachVehicle(vehicles: VehicleSpan[], action: (car: Car, index
const car = getCarById(currentId);
if (!car)
break;

action(car, count);
if (count % sequence === 0)
{
action(car, count);
}
invoke(refreshVehicle, currentId);

const nextId = car.nextCarOnTrain;
if (isNull(nextId))
break;
Expand Down
Loading