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:
+2
-2
@@ -15,8 +15,8 @@ app.get('/api/getSceneries', (_, res) => {
|
|||||||
res.sendFile(path.join(cwd(), 'endpoints', 'getSceneries.json'));
|
res.sendFile(path.join(cwd(), 'endpoints', 'getSceneries.json'));
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/getVehicles', (_, res) => {
|
app.get('/api/getVehiclesData', (_, res) => {
|
||||||
res.sendFile(path.join(cwd(), 'endpoints', 'getVehicles.json'));
|
res.sendFile(path.join(cwd(), 'endpoints', 'getVehiclesData.json'));
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/getDonators', (_, res) => {
|
app.get('/api/getDonators', (_, res) => {
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ const availableCategories = computed(() => {
|
|||||||
for (const stockName of stockList) {
|
for (const stockName of stockList) {
|
||||||
const [vehicleName, ...cargoList] = stockName.split(':');
|
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;
|
if (!vehicleData) continue;
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
<span v-if="vehicleCargo">({{ vehicleCargo.id }})</span>
|
<span v-if="vehicleCargo">({{ vehicleCargo.id }})</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="vehicle-props" v-if="vehicleData">
|
<div class="vehicle-props" v-if="vehicleGroup">
|
||||||
{{ vehicleData.group.speed }}km/h • {{ vehicleData.group.length }}m •
|
{{ vehicleGroup.speed }}km/h • {{ vehicleGroup.length }}m •
|
||||||
{{ (vehicleData.group.weight / 1000).toFixed(1) }}t
|
{{ (vehicleGroup.weight / 1000).toFixed(1) }}t
|
||||||
<span v-if="vehicleCargo">(+{{ (vehicleCargo.weight / 1000).toFixed(1) }}t)</span>
|
<span v-if="vehicleCargo">(+{{ (vehicleCargo.weight / 1000).toFixed(1) }}t)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -73,12 +73,18 @@ export default defineComponent({
|
|||||||
return this.tooltipStore.content.split(':')[0];
|
return this.tooltipStore.content.split(':')[0];
|
||||||
},
|
},
|
||||||
|
|
||||||
vehicleData() {
|
vehicleGroup() {
|
||||||
return this.apiStore.vehiclesData?.find((v) => v.name == this.vehicleName);
|
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() {
|
vehicleCargo() {
|
||||||
const x = this.vehicleData?.group.cargoTypes?.find(
|
const x = this.vehicleGroup?.cargoTypes?.find(
|
||||||
(c) => c.id == this.tooltipStore.content.split(':')[1]
|
(c) => c.id == this.tooltipStore.content.split(':')[1]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -122,19 +122,27 @@ export default defineComponent({
|
|||||||
|
|
||||||
// Check the whole consist speed limit
|
// Check the whole consist speed limit
|
||||||
const vehicleMaxSpeed = stockList.reduce((acc, stockName, i) => {
|
const vehicleMaxSpeed = stockList.reduce((acc, stockName, i) => {
|
||||||
|
if (!this.apiStore.vehiclesData) return acc;
|
||||||
|
|
||||||
const [vehicleName, vehicleCargo] = stockName.split(':');
|
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;
|
isPassenger = false;
|
||||||
|
|
||||||
if (vehicleCargo !== undefined && vehicleData.group.speedLoaded) {
|
if (vehicleCargo !== undefined && vehicleGroup.speedLoaded) {
|
||||||
vehicleSpeed = vehicleData.group.speedLoaded;
|
vehicleSpeed = vehicleGroup.speedLoaded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,14 +151,23 @@ export default defineComponent({
|
|||||||
|
|
||||||
// Check the head vehicle speed limit
|
// Check the head vehicle speed limit
|
||||||
const headLocoName = stockList[0];
|
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
|
// 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;
|
return vehicleMaxSpeed;
|
||||||
|
|
||||||
const massSpeeds =
|
const massSpeeds =
|
||||||
headLocoVehicleData.group.massSpeeds[
|
headLocoVehicleGroup.massSpeeds[
|
||||||
stockList.length == 1 ? 'none' : isPassenger ? 'passenger' : 'cargo'
|
stockList.length == 1 ? 'none' : isPassenger ? 'passenger' : 'cargo'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export const useApiStore = defineStore('apiStore', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
activeData: undefined as API.ActiveData.Response | undefined,
|
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,
|
donatorsData: [] as API.Donators.Response,
|
||||||
sceneryData: [] as StationJSONData[],
|
sceneryData: [] as StationJSONData[],
|
||||||
@@ -111,7 +111,7 @@ export const useApiStore = defineStore('apiStore', {
|
|||||||
|
|
||||||
async fetchVehiclesInfo() {
|
async fetchVehiclesInfo() {
|
||||||
try {
|
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.vehiclesData = response.data;
|
||||||
this.dataStatuses.vehicles = response.data ? Status.Data.Loaded : Status.Data.Warning;
|
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 {
|
export enum APIDataStatus {
|
||||||
OK = 'OK',
|
OK = 'OK',
|
||||||
@@ -329,8 +329,51 @@ export namespace API {
|
|||||||
export type Response = string[];
|
export type Response = string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace Vehicles {
|
export namespace VehiclesData {
|
||||||
export type Response = VehicleData[];
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-39
@@ -1,5 +1,6 @@
|
|||||||
import { RouteLocationRaw } from 'vue-router';
|
import { RouteLocationRaw } from 'vue-router';
|
||||||
import { StationJSONData } from '../store/typings';
|
import { StationJSONData } from '../store/typings';
|
||||||
|
import { API } from './api';
|
||||||
|
|
||||||
export type Availability = 'default' | 'unavailable' | 'nonPublic' | 'abandoned' | 'nonDefault';
|
export type Availability = 'default' | 'unavailable' | 'nonPublic' | 'abandoned' | 'nonDefault';
|
||||||
export type ScenerySpawnType = 'passenger' | 'freight' | 'loco' | 'all';
|
export type ScenerySpawnType = 'passenger' | 'freight' | 'loco' | 'all';
|
||||||
@@ -214,45 +215,8 @@ export interface CheckpointTrain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Vehicles Data
|
// Vehicles Data
|
||||||
|
export type Vehicle = API.VehiclesData.VehicleObject;
|
||||||
export interface VehicleData {
|
export type VehicleGroup = API.VehiclesData.VehicleGroupObject;
|
||||||
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 interface TooltipUserTrain {
|
export interface TooltipUserTrain {
|
||||||
driverName: string;
|
driverName: string;
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ export default defineConfig({
|
|||||||
runtimeCaching: [
|
runtimeCaching: [
|
||||||
{
|
{
|
||||||
urlPattern:
|
urlPattern:
|
||||||
/^https:\/\/stacjownik.spythere.eu\/api\/(getVehicles|getDonators|getSceneries)/i,
|
/^https:\/\/stacjownik.spythere.eu\/api\/(getVehiclesData|getDonators|getSceneries)/i,
|
||||||
handler: 'NetworkFirst',
|
handler: 'NetworkFirst',
|
||||||
options: {
|
options: {
|
||||||
cacheName: 'stacjownik-api-cache',
|
cacheName: 'stacjownik-api-cache',
|
||||||
|
|||||||
Reference in New Issue
Block a user