mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
chore: added a display of the timetable max speed in the active train info & tooltip
This commit is contained in:
@@ -135,7 +135,11 @@
|
||||
<img src="/images/icon-speed.svg" alt="speed icon" />
|
||||
{{ train.speed }} km/h
|
||||
|
||||
<span v-if="stockSpeedLimit != Infinity">
|
||||
<span v-if="train.timetableData">
|
||||
• vRJ: {{ train.timetableData.trainMaxSpeed }} km/h
|
||||
</span>
|
||||
|
||||
<span v-else-if="stockSpeedLimit != Infinity">
|
||||
•
|
||||
<em
|
||||
class="text--grayed"
|
||||
@@ -219,57 +223,9 @@ export default defineComponent({
|
||||
|
||||
computed: {
|
||||
stockSpeedLimit() {
|
||||
let isPassenger = true;
|
||||
|
||||
// Check the whole consist speed limit
|
||||
const vehicleMaxSpeed = this.train.stockList.reduce((acc, stockName, i) => {
|
||||
const [vehicleName, vehicleCargo] = stockName.split(':');
|
||||
|
||||
const vehicleData = this.apiStore.vehiclesData?.find((v) => v.name == vehicleName);
|
||||
|
||||
if (!vehicleData) return acc;
|
||||
|
||||
let vehicleSpeed = vehicleData.group.speed;
|
||||
|
||||
if (vehicleData.type == 'wagon-freight') {
|
||||
isPassenger = false;
|
||||
|
||||
if (vehicleCargo !== undefined && vehicleData.group.speedLoaded) {
|
||||
vehicleSpeed = vehicleData.group.speedLoaded;
|
||||
}
|
||||
}
|
||||
|
||||
return Math.min(vehicleSpeed, acc);
|
||||
}, Infinity);
|
||||
|
||||
// Check the head vehicle speed limit
|
||||
const headLocoName = this.train.stockList[0];
|
||||
const headLocoVehicleData = this.apiStore.vehiclesData?.find((v) => v.name == headLocoName);
|
||||
|
||||
// Omit speed check for head vehicle if there's no data for it
|
||||
if (!headLocoName || !headLocoVehicleData || !headLocoVehicleData.group.massSpeeds)
|
||||
return vehicleMaxSpeed;
|
||||
|
||||
const massSpeeds =
|
||||
headLocoVehicleData.group.massSpeeds[
|
||||
this.train.stockList.length == 1 ? 'none' : isPassenger ? 'passenger' : 'cargo'
|
||||
];
|
||||
|
||||
// Omit speed check if there's no data on mass speeds
|
||||
if (!massSpeeds) return vehicleMaxSpeed;
|
||||
|
||||
// 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 ? massSpeeds[massKey] : Infinity;
|
||||
|
||||
return Math.min(massMaxSpeed, vehicleMaxSpeed);
|
||||
return this.getStockSpeedLimit(this.train.stockList, this.train.mass);
|
||||
},
|
||||
|
||||
journalRouteLocation() {
|
||||
return {
|
||||
path: '/journal/timetables',
|
||||
|
||||
Reference in New Issue
Block a user