Skip to content

Commit

Permalink
Properties are now set to default on ride or variant change.
Browse files Browse the repository at this point in the history
  • Loading branch information
Basssiiie committed Dec 5, 2020
1 parent 63a383a commit 0f01124
Showing 1 changed file with 54 additions and 3 deletions.
57 changes: 54 additions & 3 deletions src/services/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,13 @@ export default class VehicleEditor
this._selectedTypeIndex = rideTypeIndex;

const currentCar = this.getSelectedCar();
const rideType = this._rideTypes[rideTypeIndex];
const rideType = this.getSelectedRideType();

log(`(editor) Set vehicle ride type to: ${rideType.name} (index: ${rideTypeIndex})`);
currentCar.rideObject = rideType.rideIndex;
currentCar.vehicleObject = 0;

// Update properties
this.refreshProperties(currentCar);
this.setPropertiesToDefaultOfType(currentCar, rideType, 0);
}


Expand All @@ -124,6 +123,8 @@ export default class VehicleEditor

log(`(editor) Set vehicle variant index to: ${variantIndex}.`);
currentCar.vehicleObject = variantIndex;

this.setPropertiesToDefaultOfType(currentCar, this.getSelectedRideType(), variantIndex);
}


Expand Down Expand Up @@ -218,6 +219,56 @@ export default class VehicleEditor
}


/**
* Sets the properties of the specified car to the default properties of the
* specified ride type.
*
* @param car The car to modify the properties of.
* @param rideType The ride type.
* @param variant The vehicle variant to take the properties from.
*/
private setPropertiesToDefaultOfType(car: Car, rideType: RideType, variant: number)
{
log("(editor) All car properties have been reset to the default value.")

// Set all properties according to definition.
const rideObject = rideType.getDefinition();
const baseVehicle = rideObject.vehicles[variant];

car.numSeats = baseVehicle.numSeats;
car.poweredAcceleration = baseVehicle.poweredAcceleration;
car.poweredMaxSpeed = baseVehicle.poweredMaxSpeed;

// Recalculate mass with peeps.
let newTotalMass = baseVehicle.carMass;
for (let i = 0; i < car.peeps.length; i++)
{
const peepId = car.peeps[i];
if (peepId != null)
{
const peep = map.getEntity(peepId) as Guest;
if (peep)
{
newTotalMass += peep.mass;
}
}
}
car.mass = newTotalMass;

// Update properties
this.refreshProperties(car);
}


/**
* Gets the selected ride type.
*/
private getSelectedRideType(): RideType
{
return this._rideTypes[this._selectedTypeIndex];
}


/**
* Gets the selected car, or throws if none is selected.
*/
Expand Down

0 comments on commit 0f01124

Please sign in to comment.