mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
refactor(vehicles): replaced URL for fetching vehicles data; changed vehicle group finding
This commit is contained in:
@@ -205,7 +205,7 @@ const availableCategories = computed(() => {
|
||||
for (const stockName of stockList) {
|
||||
const [vehicleName, ...cargoList] = stockName.split(':');
|
||||
|
||||
const vehicleData = apiStore.vehiclesData?.find((v) => v.name == vehicleName);
|
||||
const vehicleData = apiStore.vehiclesData?.vehicles.find((v) => v.name == vehicleName);
|
||||
|
||||
if (!vehicleData) continue;
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
<span v-if="vehicleCargo">({{ vehicleCargo.id }})</span>
|
||||
</div>
|
||||
|
||||
<div class="vehicle-props" v-if="vehicleData">
|
||||
{{ vehicleData.group.speed }}km/h • {{ vehicleData.group.length }}m •
|
||||
{{ (vehicleData.group.weight / 1000).toFixed(1) }}t
|
||||
<div class="vehicle-props" v-if="vehicleGroup">
|
||||
{{ vehicleGroup.speed }}km/h • {{ vehicleGroup.length }}m •
|
||||
{{ (vehicleGroup.weight / 1000).toFixed(1) }}t
|
||||
<span v-if="vehicleCargo">(+{{ (vehicleCargo.weight / 1000).toFixed(1) }}t)</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -73,12 +73,18 @@ export default defineComponent({
|
||||
return this.tooltipStore.content.split(':')[0];
|
||||
},
|
||||
|
||||
vehicleData() {
|
||||
return this.apiStore.vehiclesData?.find((v) => v.name == this.vehicleName);
|
||||
vehicleGroup() {
|
||||
if (!this.apiStore.vehiclesData) return null;
|
||||
|
||||
const vehicle = this.apiStore.vehiclesData.vehicles.find((v) => v.name == this.vehicleName);
|
||||
|
||||
if (!vehicle) return null;
|
||||
|
||||
return this.apiStore.vehiclesData.vehicleGroups.find((g) => g.id == vehicle?.vehicleGroupsId);
|
||||
},
|
||||
|
||||
vehicleCargo() {
|
||||
const x = this.vehicleData?.group.cargoTypes?.find(
|
||||
const x = this.vehicleGroup?.cargoTypes?.find(
|
||||
(c) => c.id == this.tooltipStore.content.split(':')[1]
|
||||
);
|
||||
|
||||
|
||||
@@ -122,19 +122,27 @@ export default defineComponent({
|
||||
|
||||
// Check the whole consist speed limit
|
||||
const vehicleMaxSpeed = stockList.reduce((acc, stockName, i) => {
|
||||
if (!this.apiStore.vehiclesData) return acc;
|
||||
|
||||
const [vehicleName, vehicleCargo] = stockName.split(':');
|
||||
|
||||
const vehicleData = this.apiStore.vehiclesData?.find((v) => v.name == vehicleName);
|
||||
const vehicle = this.apiStore.vehiclesData.vehicles.find((v) => v.name == vehicleName);
|
||||
|
||||
if (!vehicleData) return acc;
|
||||
if (!vehicle) return acc;
|
||||
|
||||
let vehicleSpeed = vehicleData.group.speed;
|
||||
const vehicleGroup = this.apiStore.vehiclesData.vehicleGroups.find(
|
||||
(g) => g.id == vehicle.vehicleGroupsId
|
||||
);
|
||||
|
||||
if (vehicleData.type == 'wagon-freight') {
|
||||
if (!vehicleGroup) return acc;
|
||||
|
||||
let vehicleSpeed = vehicleGroup.speed;
|
||||
|
||||
if (vehicle.type == 'wagon-freight') {
|
||||
isPassenger = false;
|
||||
|
||||
if (vehicleCargo !== undefined && vehicleData.group.speedLoaded) {
|
||||
vehicleSpeed = vehicleData.group.speedLoaded;
|
||||
if (vehicleCargo !== undefined && vehicleGroup.speedLoaded) {
|
||||
vehicleSpeed = vehicleGroup.speedLoaded;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,14 +151,23 @@ export default defineComponent({
|
||||
|
||||
// Check the head vehicle speed limit
|
||||
const headLocoName = stockList[0];
|
||||
const headLocoVehicleData = this.apiStore.vehiclesData?.find((v) => v.name == headLocoName);
|
||||
|
||||
const headLocoVehicle = this.apiStore.vehiclesData!.vehicles.find(
|
||||
(v) => v.name == headLocoName
|
||||
);
|
||||
|
||||
const headLocoVehicleGroup = this.apiStore.vehiclesData!.vehicleGroups.find(
|
||||
(g) => g.id == headLocoVehicle?.vehicleGroupsId
|
||||
);
|
||||
|
||||
if (!headLocoVehicleGroup) return vehicleMaxSpeed;
|
||||
|
||||
// Omit speed check for head vehicle if there's no data for it
|
||||
if (!headLocoName || !headLocoVehicleData || !headLocoVehicleData.group.massSpeeds)
|
||||
if (!headLocoName || !headLocoVehicle || !headLocoVehicleGroup.massSpeeds)
|
||||
return vehicleMaxSpeed;
|
||||
|
||||
const massSpeeds =
|
||||
headLocoVehicleData.group.massSpeeds[
|
||||
headLocoVehicleGroup.massSpeeds[
|
||||
stockList.length == 1 ? 'none' : isPassenger ? 'passenger' : 'cargo'
|
||||
];
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export const useApiStore = defineStore('apiStore', {
|
||||
},
|
||||
|
||||
activeData: undefined as API.ActiveData.Response | undefined,
|
||||
vehiclesData: undefined as API.Vehicles.Response | undefined,
|
||||
vehiclesData: undefined as API.VehiclesData.Response | undefined,
|
||||
|
||||
donatorsData: [] as API.Donators.Response,
|
||||
sceneryData: [] as StationJSONData[],
|
||||
@@ -111,7 +111,7 @@ export const useApiStore = defineStore('apiStore', {
|
||||
|
||||
async fetchVehiclesInfo() {
|
||||
try {
|
||||
const response = await this.client!.get<API.Vehicles.Response>('api/getVehicles');
|
||||
const response = await this.client!.get<API.VehiclesData.Response>('api/getVehiclesData');
|
||||
|
||||
this.vehiclesData = response.data;
|
||||
this.dataStatuses.vehicles = response.data ? Status.Data.Loaded : Status.Data.Warning;
|
||||
|
||||
+46
-3
@@ -1,4 +1,4 @@
|
||||
import { Status, VehicleData } from './common';
|
||||
import { Status, Vehicle, VehicleGroup } from './common';
|
||||
|
||||
export enum APIDataStatus {
|
||||
OK = 'OK',
|
||||
@@ -329,8 +329,51 @@ export namespace API {
|
||||
export type Response = string[];
|
||||
}
|
||||
|
||||
export namespace Vehicles {
|
||||
export type Response = VehicleData[];
|
||||
export namespace VehiclesData {
|
||||
export interface VehicleObject {
|
||||
id: number;
|
||||
name: string;
|
||||
type: string;
|
||||
cabinName: string | null;
|
||||
restrictions: Record<string, any> | null;
|
||||
vehicleGroupsId: number;
|
||||
}
|
||||
|
||||
export interface VehicleGroupObject {
|
||||
id: number;
|
||||
name: string;
|
||||
speed: number;
|
||||
speedLoaded?: number;
|
||||
speedLoco?: number;
|
||||
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 {
|
||||
id: string;
|
||||
weight: number;
|
||||
}
|
||||
|
||||
export interface Data {
|
||||
vehicles: VehicleObject[];
|
||||
vehicleGroups: VehicleGroupObject[];
|
||||
}
|
||||
|
||||
export type Response = Data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-40
@@ -1,5 +1,6 @@
|
||||
import { RouteLocationRaw } from 'vue-router';
|
||||
import { StationJSONData } from '../store/typings';
|
||||
import { API } from './api';
|
||||
|
||||
export type Availability = 'default' | 'unavailable' | 'nonPublic' | 'abandoned' | 'nonDefault';
|
||||
export type ScenerySpawnType = 'passenger' | 'freight' | 'loco' | 'all';
|
||||
@@ -169,7 +170,7 @@ export interface ActiveScenery {
|
||||
confirmed: number;
|
||||
unconfirmed: number;
|
||||
};
|
||||
missingCheckpoints: string[];
|
||||
missingCheckpoints: string[];
|
||||
}
|
||||
|
||||
export interface ScenerySpawn {
|
||||
@@ -214,45 +215,8 @@ export interface CheckpointTrain {
|
||||
}
|
||||
|
||||
// Vehicles Data
|
||||
|
||||
export interface VehicleData {
|
||||
id: number;
|
||||
name: string;
|
||||
type: string;
|
||||
cabinName: string | null;
|
||||
restrictions: Record<string, any> | null;
|
||||
vehicleGroupsId: number;
|
||||
group: VehiclesGroup;
|
||||
}
|
||||
|
||||
export interface VehiclesGroup {
|
||||
id: number;
|
||||
name: string;
|
||||
speed: number;
|
||||
speedLoaded?: number;
|
||||
speedLoco?: number;
|
||||
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 {
|
||||
id: string;
|
||||
weight: number;
|
||||
}
|
||||
export type Vehicle = API.VehiclesData.VehicleObject;
|
||||
export type VehicleGroup = API.VehiclesData.VehicleGroupObject;
|
||||
|
||||
export interface TooltipUserTrain {
|
||||
driverName: string;
|
||||
|
||||
Reference in New Issue
Block a user