Skip to content

Commit

Permalink
Fixed bug #25
Browse files Browse the repository at this point in the history
  • Loading branch information
DanStevens committed Aug 16, 2022
1 parent ceb4228 commit 7ccbc52
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import settings from "./settings";
import { clamp } from "./utils";

Expand Down Expand Up @@ -65,16 +64,27 @@ function onMonthBegins() {
settings.save();
}

/**
* Returns a value indicating whether the given RideRating is valid
* @param rating The ride stats to test
* @returns `true` if the ride stats are valid; otherwise false
*
* RideRating is valid if all of its metrics are greater than zero.
* Within the game, a ride's rating can be invalid if it is yet
* to be calculated or are in the process of being calculated.
*/
function isRideRatingValid(rating: RideRating) {
return rating.excitement > 0 && rating.intensity > 0 && rating.nausea;
}

/**
* Callback for 'ride.ratings.calculate' plugin API hook
*/
export function handleUpkeepCalculate(e: RideRatingsCalculateArgs): void {
if (settings.enabled) {
if (settings.enabled && isRideRatingValid(e)) {
const ride = map.getRide(e.rideId);
const multiplier = getMultiplierForRideClassification(ride.classification);
ride.runningCost = calcUpkeep(ride, multiplier);
} else {
console.log("Cost Inflator is disabled");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/registerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import main from './main';

registerPlugin({
name: 'CostInflator',
version: '0.1.0',
version: '0.1.1',
authors: ['DanStevens'],
type: 'local',
licence: 'MIT',
Expand Down
9 changes: 9 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ interface Settings {
}

type CostCategory = 'rideUpkeep' | 'stallUpkeep'

/**
* The rating metrics for a ride
*/
interface RideRating {
excitement: number,
intensity: number,
nausea: number,
}

0 comments on commit 7ccbc52

Please sign in to comment.