mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
refactor: moved speed limits from local to api
This commit is contained in:
@@ -192,7 +192,6 @@ import trainInfoMixin from '../../mixins/trainInfoMixin';
|
||||
import trainCategoryMixin from '../../mixins/trainCategoryMixin';
|
||||
import ProgressBar from '../Global/ProgressBar.vue';
|
||||
import StockList from '../Global/StockList.vue';
|
||||
import { speedLimits } from '../../data/speedLimits';
|
||||
|
||||
export default defineComponent({
|
||||
mixins: [trainInfoMixin, styleMixin, trainCategoryMixin],
|
||||
@@ -219,6 +218,7 @@ export default defineComponent({
|
||||
stockSpeedLimit() {
|
||||
let isPassenger = true;
|
||||
|
||||
// Check the whole consist speed limit
|
||||
const vehicleMaxSpeed = this.train.stockList.reduce((acc, stockName, i) => {
|
||||
const [vehicleName, vehicleCargo] = stockName.split(':');
|
||||
|
||||
@@ -239,22 +239,34 @@ export default defineComponent({
|
||||
return Math.min(vehicleSpeed, acc);
|
||||
}, Infinity);
|
||||
|
||||
const headLoco = this.train.stockList[0].slice(0, this.train.stockList[0].indexOf('-'));
|
||||
// Check the head vehicle speed limit
|
||||
const headLocoName = this.train.stockList[0];
|
||||
const headLocoVehicleData = this.apiStore.vehiclesData?.find((v) => v.name == headLocoName);
|
||||
|
||||
if (speedLimits[headLoco] === undefined) return vehicleMaxSpeed;
|
||||
console.log(headLocoName, headLocoVehicleData);
|
||||
|
||||
if (this.train.stockList.length == 1) return speedLimits[headLoco]['none'];
|
||||
// Omit speed check for head vehicle if there's no data for it
|
||||
if (!headLocoName || !headLocoVehicleData || !headLocoVehicleData.group.massSpeeds)
|
||||
return vehicleMaxSpeed;
|
||||
|
||||
const speedTable: Record<string, number> =
|
||||
speedLimits[headLoco][isPassenger ? 'passenger' : 'cargo'];
|
||||
const massSpeeds =
|
||||
headLocoVehicleData.group.massSpeeds[
|
||||
this.train.stockList.length == 1 ? 'none' : isPassenger ? 'passenger' : 'cargo'
|
||||
];
|
||||
|
||||
if (!speedTable) return vehicleMaxSpeed;
|
||||
// Omit speed check if there's no data on mass speeds
|
||||
if (!massSpeeds) return vehicleMaxSpeed;
|
||||
|
||||
const massKey = Object.keys(speedTable).findLast(
|
||||
// Number type for locomotives alone
|
||||
if (typeof massSpeeds === 'number') return massSpeeds;
|
||||
|
||||
// Record type for passenger or cargo, find the closest range
|
||||
const massKey = Object.keys(massSpeeds).findLast(
|
||||
(massKey) => this.train.mass >= Number(massKey)
|
||||
);
|
||||
|
||||
const massMaxSpeed = massKey ? speedTable[massKey] : Infinity;
|
||||
const massMaxSpeed = massKey ? massSpeeds[massKey] : Infinity;
|
||||
console.log(massMaxSpeed);
|
||||
|
||||
return Math.min(massMaxSpeed, vehicleMaxSpeed);
|
||||
},
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
export const speedLimits: Record<string, any> = {
|
||||
EU07: {
|
||||
passenger: {
|
||||
'650000': 125
|
||||
},
|
||||
cargo: {
|
||||
'750000': 100,
|
||||
'1000000': 90,
|
||||
'1500000': 80,
|
||||
'2000000': 70
|
||||
},
|
||||
none: 110
|
||||
},
|
||||
'4E': {
|
||||
passenger: {
|
||||
'650000': 125
|
||||
},
|
||||
cargo: {
|
||||
'750000': 100,
|
||||
'1000000': 90,
|
||||
'1500000': 80,
|
||||
'2000000': 70
|
||||
},
|
||||
none: 110
|
||||
},
|
||||
EU07E: {
|
||||
passenger: {
|
||||
'650000': 125
|
||||
},
|
||||
cargo: {
|
||||
'750000': 100,
|
||||
'1000000': 90,
|
||||
'1500000': 80,
|
||||
'2000000': 70
|
||||
},
|
||||
none: 110
|
||||
},
|
||||
EP07: {
|
||||
passenger: {
|
||||
'650000': 125
|
||||
},
|
||||
cargo: null,
|
||||
none: 110
|
||||
},
|
||||
EP08: {
|
||||
passenger: {
|
||||
'650000': 140
|
||||
},
|
||||
cargo: null,
|
||||
none: 110
|
||||
},
|
||||
EP09: {
|
||||
passenger: {
|
||||
'650000': 160
|
||||
},
|
||||
cargo: null,
|
||||
none: 160
|
||||
},
|
||||
ET22: {
|
||||
passenger: {
|
||||
'650000': 125
|
||||
},
|
||||
cargo: {
|
||||
'1200000': 100,
|
||||
'1800000': 90,
|
||||
'2500000': 80,
|
||||
'3100000': 70
|
||||
},
|
||||
none: 100
|
||||
},
|
||||
'201E': {
|
||||
passenger: {
|
||||
'650000': 125
|
||||
},
|
||||
cargo: {
|
||||
'1200000': 100,
|
||||
'2000000': 80,
|
||||
'3100000': 70
|
||||
},
|
||||
none: 125
|
||||
},
|
||||
ET41: {
|
||||
passenger: {
|
||||
'700000': 125
|
||||
},
|
||||
cargo: {
|
||||
'4000000': 70,
|
||||
'3500000': 80,
|
||||
'2500000': 90,
|
||||
'2000000': 100
|
||||
},
|
||||
none: 110
|
||||
},
|
||||
SM42: {
|
||||
passenger: {
|
||||
'95000': 90,
|
||||
'200000': 80,
|
||||
'300000': 70,
|
||||
'450000': 60,
|
||||
'750000': 50,
|
||||
'1130000': 40,
|
||||
'1720000': 30,
|
||||
'2400000': 20
|
||||
},
|
||||
cargo: {
|
||||
'95000': 90,
|
||||
'200000': 80,
|
||||
'300000': 70,
|
||||
'450000': 60,
|
||||
'750000': 50,
|
||||
'1130000': 40,
|
||||
'1720000': 30,
|
||||
'2400000': 20
|
||||
},
|
||||
none: 90
|
||||
},
|
||||
M62: {
|
||||
passenger: {
|
||||
'500000': 100,
|
||||
'800000': 80,
|
||||
'1200000': 60,
|
||||
'2000000': 40,
|
||||
'3000000': 20
|
||||
},
|
||||
cargo: {
|
||||
'500000': 100,
|
||||
'800000': 80,
|
||||
'1200000': 60,
|
||||
'2000000': 40,
|
||||
'3000000': 20
|
||||
},
|
||||
none: 100
|
||||
},
|
||||
ST44: {
|
||||
passenger: {
|
||||
'500000': 100,
|
||||
'800000': 80,
|
||||
'1200000': 60,
|
||||
'2000000': 40,
|
||||
'3000000': 20
|
||||
},
|
||||
cargo: {
|
||||
'500000': 100,
|
||||
'800000': 80,
|
||||
'1200000': 60,
|
||||
'2000000': 40,
|
||||
'3000000': 20
|
||||
},
|
||||
none: 100
|
||||
},
|
||||
CTLR4C: {
|
||||
passenger: {
|
||||
'500000': 100,
|
||||
'800000': 80,
|
||||
'1200000': 60,
|
||||
'2000000': 40,
|
||||
'3000000': 20
|
||||
},
|
||||
cargo: {
|
||||
'500000': 100,
|
||||
'800000': 80,
|
||||
'1200000': 60,
|
||||
'2000000': 40,
|
||||
'3000000': 20
|
||||
},
|
||||
none: 100
|
||||
}
|
||||
};
|
||||
@@ -234,10 +234,19 @@ export interface VehiclesGroup {
|
||||
length: number;
|
||||
weight: number;
|
||||
cargoTypes: VehicleCargo[] | null;
|
||||
|
||||
locoProps: {
|
||||
coldStart: boolean;
|
||||
doubleManned: boolean;
|
||||
} | null;
|
||||
|
||||
massSpeeds: VehicleGroupMassSpeeds | null;
|
||||
}
|
||||
|
||||
export interface VehicleGroupMassSpeeds {
|
||||
passenger: Record<string, number> | null;
|
||||
cargo: Record<string, number> | null;
|
||||
none: number | null;
|
||||
}
|
||||
|
||||
export interface VehicleCargo {
|
||||
|
||||
Reference in New Issue
Block a user