chore: subtracting loco weight for "obc. lok." cell

This commit is contained in:
2025-06-22 13:39:29 +02:00
parent 87f173a645
commit 59d694b233
7 changed files with 109 additions and 10 deletions
@@ -285,7 +285,7 @@
<table class="h-full w-full border-collapse">
<tbody>
<tr class="border-b-[1px] border-b-black dark:border-b-white">
<td>{{ row.stockMass }}</td>
<td>{{ Math.floor(row.stockMass / 1000) }}</td>
</tr>
<tr>
<td>{{ row.stockLength }}</td>
@@ -328,7 +328,7 @@ const computedTimetableRows = computed(() => {
let timeFrom = Date.now();
const stockVmax = timetableData.trainMaxSpeed,
stockMass = Math.floor(timetableData.mass / 1000),
stockMass = timetableData.mass,
stockLength = timetableData.length;
const timetablePath = parseTimetablePath(timetableData.path);
+25
View File
@@ -0,0 +1,25 @@
import { useApiStore } from '../stores/api.store';
export function useVehicleMixin() {
const apiStore = useApiStore();
/**
* Gets loco load (obc. lok.) in tons - effectively train mass without locomotive or lone locomotive / unit mass
*/
function getLocoLoad(trainMass: number, stockString: string) {
if (!apiStore.vehiclesData) return trainMass;
const stockArray = stockString.split(';');
const headUnitsNames = stockArray.slice(0, 3).filter((v) => /-\d{3,}$/.test(v));
if (headUnitsNames.length == 1 && stockArray.length == 1) return trainMass;
const headVehicleData = apiStore.vehiclesData.find((v) => v.name == headUnitsNames[0]);
if (!headVehicleData) return trainMass;
return Math.min(trainMass, trainMass - headVehicleData.group.weight);
}
return { getLocoLoad };
}
+21 -2
View File
@@ -4,9 +4,15 @@ import { defineStore } from 'pinia';
import {
DataStatus,
type ActiveDataResponse,
type SceneriesDataResponse
type SceneriesDataResponse,
type VehiclesDataResponse
} from '../types/api.types';
import type { ActiveData, JournalTimetableShort, SceneryData } from '../types/common.types';
import type {
ActiveData,
JournalTimetableShort,
SceneryData,
VehicleData
} from '../types/common.types';
let activeDataInterval = -1;
@@ -17,6 +23,7 @@ export const useApiStore = defineStore('api', {
activeData: null as ActiveData | null,
sceneryData: null as SceneryData[] | null,
vehiclesData: null as VehicleData[] | null,
journalTimetablesData: null as JournalTimetableShort[] | null,
outdatedTimerId: -1,
@@ -57,6 +64,8 @@ export const useApiStore = defineStore('api', {
}, 25000);
this.fetchSceneriesData();
this.fetchVehiclesData();
await this.fetchActiveData();
},
@@ -86,6 +95,16 @@ export const useApiStore = defineStore('api', {
} catch (error) {
console.error(error);
}
},
async fetchVehiclesData() {
try {
const response = (await this.client!.get<VehiclesDataResponse>('/api/getVehicles')).data;
this.vehiclesData = response;
} catch (error) {
console.error(error);
}
}
}
});
+8 -2
View File
@@ -7,6 +7,7 @@ import type {
ViewMode
} from '../types/common.types';
import { getHeadUnits } from '../utils/trainUtils';
import { useVehicleMixin } from '../mixins/useVehicleMixin';
export const useGlobalStore = defineStore('global', {
state: () => ({
@@ -48,6 +49,8 @@ export const useGlobalStore = defineStore('global', {
},
currentTimetableData(): TimetableData | null {
const vehicleUtils = useVehicleMixin();
if (this.viewMode == 'active') {
const selectedTrain = this.selectedActiveTrain;
@@ -55,7 +58,7 @@ export const useGlobalStore = defineStore('global', {
return {
trainNo: selectedTrain.trainNo,
mass: selectedTrain.mass,
mass: vehicleUtils.getLocoLoad(selectedTrain.mass, selectedTrain.stockString),
length: selectedTrain.length,
driverId: selectedTrain.driverId,
driverName: selectedTrain.driverName,
@@ -88,7 +91,10 @@ export const useGlobalStore = defineStore('global', {
return {
journalCreatedAt: new Date(selectedTimetable.createdAt).getTime(),
trainNo: selectedTimetable.trainNo,
mass: selectedTimetable.stockMass,
mass: vehicleUtils.getLocoLoad(
selectedTimetable.stockMass,
selectedTimetable.stockString
),
length: selectedTimetable.stockLength,
driverId: selectedTimetable.driverId,
driverName: selectedTimetable.driverName,
+5 -3
View File
@@ -1,14 +1,16 @@
import type { ActiveData, JournalTimetableShort, SceneryData } from './common.types';
import type { ActiveData, JournalTimetableShort, SceneryData, VehicleData } from './common.types';
export type ActiveDataResponse = ActiveData;
export type SceneriesDataResponse = SceneryData[];
export type JournalTimetablesShortResponse = JournalTimetableShort[];
export type JournalTimetablesShortResponse = JournalTimetableShort[];
export type VehiclesDataResponse = VehicleData[];
export enum DataStatus {
'INIT' = -1,
'LOADING' = 0,
'SUCCESS' = 1,
'ERROR' = 2,
'ERROR' = 2
}
+44
View File
@@ -286,3 +286,47 @@ export interface TimetableData {
savedTimestamp?: number;
journalCreatedAt?: number;
}
export interface VehicleData {
id: number;
name: string;
type: string;
group: VehicleGroup;
cabinName?: string;
restrictions?: VehicleRestrictions;
simulatorVersion: string;
}
export interface VehicleRestrictions {
sponsorOnly?: number;
teamOnly?: boolean;
}
export interface VehicleGroup {
id: number;
name: string;
speed: number;
speedLoaded?: number;
speedLoco?: number;
length: number;
weight: number;
cargoTypes?: VehicleCargoType[];
locoProps?: VehicleLocoProps;
massSpeeds?: VehicleMassSpeeds;
}
export interface VehicleCargoType {
id: string;
weight: number;
}
export interface VehicleLocoProps {
coldStart: boolean;
doubleManned: boolean;
}
export interface VehicleMassSpeeds {
none: number;
cargo?: Record<string, number>;
passenger?: Record<string, number>;
}