mirror of
https://github.com/Spythere/pojazdownik.git
synced 2026-05-03 19:48:11 +00:00
15 lines
500 B
TypeScript
15 lines
500 B
TypeScript
import speedLimitTable from '../constants/speedLimits.json';
|
|
export type LocoType = keyof typeof speedLimitTable;
|
|
|
|
export const calculateSpeedLimit = (locoType: LocoType, stockMass: number, isTrainPassenger: boolean) => {
|
|
const speedTable = speedLimitTable[locoType][isTrainPassenger ? 'passenger' : 'cargo'];
|
|
|
|
if (!speedTable) return undefined;
|
|
|
|
let speedLimit = 0;
|
|
for (let mass in speedTable) if (stockMass > Number(mass)) speedLimit = (speedTable as any)[mass];
|
|
|
|
return speedLimit;
|
|
};
|
|
|