diff --git a/src/components/tabs/stock-list/StockActions.vue b/src/components/tabs/stock-list/StockActions.vue index c04123b..c21375d 100644 --- a/src/components/tabs/stock-list/StockActions.vue +++ b/src/components/tabs/stock-list/StockActions.vue @@ -110,7 +110,7 @@ import { isTractionUnit } from '../../../utils/vehicleUtils'; import stockMixin from '../../../mixins/stockMixin'; import { useStockListUtils } from '../../../utils/stockListUtils'; -import { getCurrentStockFileName, getStockStringOutput } from '../../../composables/file'; +import { getCurrentStockFileName } from '../../../composables/file'; import { Bookmark, @@ -166,7 +166,7 @@ export default defineComponent({ methods: { copyToClipboard() { - navigator.clipboard.writeText(getStockStringOutput()); + navigator.clipboard.writeText(this.store.stockString); setTimeout(() => { alert(this.$t('stocklist.alert-copied')); @@ -224,7 +224,7 @@ export default defineComponent({ if (!fileName) return; - const blob = new Blob([getStockStringOutput()]); + const blob = new Blob([this.store.stockString]); const file = fileName + '.con'; var e = document.createEvent('MouseEvents'), diff --git a/src/composables/file.ts b/src/composables/file.ts index f5fd35c..01201de 100644 --- a/src/composables/file.ts +++ b/src/composables/file.ts @@ -25,6 +25,7 @@ export function getCurrentStockFileName() { return fileName; } +// UNUSED - PARSES ADDITIONAL CARGO FOR INTERMODALS export function getStockStringOutput() { const store = useStore(); diff --git a/src/data/generatorData.json b/src/data/generatorData.json index edc4d6a..3682337 100644 --- a/src/data/generatorData.json +++ b/src/data/generatorData.json @@ -4,11 +4,14 @@ "food": ["412Z:tc_20_loaded", "627Z:tc_20_loaded"], "food-empty": ["412Z:tc_20_empty", "627Z:tc_20_empty"], "intermodal": [ - "627Z:627Z_mix1_sctc_loaded", - "627Z:627Z_mix2_sctc_loaded", - "627Z:627Z_mix3_sctc_loaded", - "412Z:412Z_mix1_sctc_loaded", - "412Z:412Z_mix1_sctc_empty" + "627Z:sc_20", + "627Z:sc_40", + "627Z:tc_20_empty", + "627Z:tc_20_loaded", + "412Z:sc_20", + "412Z:sc_40", + "412Z:tc_20_empty", + "412Z:tc_20_loaded" ], "biomass": ["412Z:wt_20_biomass", "627Z:wt_20_biomass"], "biomass-empty": [ diff --git a/src/mixins/stockMixin.ts b/src/mixins/stockMixin.ts index b8c061e..53eed73 100644 --- a/src/mixins/stockMixin.ts +++ b/src/mixins/stockMixin.ts @@ -1,7 +1,7 @@ import { defineComponent } from 'vue'; import { useStore } from '../store'; import { ICarWagon, ILocomotive, IStock, ICargo, IVehicle } from '../types/common.types'; -import { additionalCargoTypes, isTractionUnit } from '../utils/vehicleUtils'; +import { isTractionUnit } from '../utils/vehicleUtils'; export default defineComponent({ setup() { @@ -75,21 +75,22 @@ export default defineComponent({ this.store.isDoubleManned = spawnProps.includes('d'); } } else { - const [carType, ...cargo] = type.split(':'); + const [carType, cargo] = type.split(':'); vehicle = this.store.carDataList.find((car) => car.type == carType) || null; - if (vehicle && cargo.length > 0) { - if (/412Z|627Z/.test(vehicle.constructionType)) { - const additionalCargo = additionalCargoTypes.find( - (c) => c.groupType == vehicle!.constructionType && c.cargoStringVariations.includes(cargo.join(':')) - ); + if (cargo) { + vehicleCargo = vehicle?.cargoTypes.find((c) => c.id == cargo) || null; - if (additionalCargo) { - cargo[0] = additionalCargo.id; - } - } + // UNUSED - ADDITIONAL INTERMODAL CARGO TEST + // if (/412Z|627Z/.test(vehicle.constructionType)) { + // const additionalCargo = additionalCargoTypes.find( + // (c) => c.groupType == vehicle!.constructionType && c.cargoStringVariations.includes(cargo.join(':')) + // ); - vehicleCargo = vehicle?.cargoTypes.find((c) => c.id == cargo[0]) || null; + // if (additionalCargo) { + // cargo[0] = additionalCargo.id; + // } + // } } } diff --git a/src/store.ts b/src/store.ts index 95b81ce..b27798c 100644 --- a/src/store.ts +++ b/src/store.ts @@ -14,7 +14,6 @@ import { import { defineStore } from 'pinia'; import { acceptableWeight, - additionalCargoTypes, carDataList, getCargoWarnings, isTractionUnit, @@ -29,6 +28,7 @@ import { import realCompositionsJSON from './data/realCompositions.json'; import { HttpClient } from './http'; +import { API } from './types/api.types'; const baseURL = import.meta.env.VITE_API_DEV === '1' && import.meta.env.DEV ? 'http://localhost:3001' : 'https://stacjownik.spythere.eu'; @@ -129,8 +129,10 @@ export const useStore = defineStore('store', { actions: { async fetchVehiclesAPI() { try { - const vehiclesData = await this.httpClient.get('api/getVehicles'); - this.vehiclesData = vehiclesData; + const response = await this.httpClient.get('api/getVehiclesData'); + // this.vehiclesData = response.; + + console.log(response); } catch (error) { console.error(error); } diff --git a/src/types/api.types.ts b/src/types/api.types.ts index 8d474df..c2c1a7a 100644 --- a/src/types/api.types.ts +++ b/src/types/api.types.ts @@ -1,87 +1,49 @@ // API namespace export namespace API { - export interface ActiveData { - trains: Train[]; - activeSceneries: ActiveScenery[]; + export namespace VehiclesData { + export interface VehicleObject { + id: number; + name: string; + type: string; + cabinName: string | null; + restrictions: Record | 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 | null; + cargo: Record | null; + none: number | null; + } + + export interface VehicleCargo { + id: string; + weight: number; + } + + export interface Data { + vehicles: VehicleObject[]; + vehicleGroups: VehicleGroupObject[]; + } + + export type Response = Data; } } - -export interface ActiveScenery { - dispatcherId: number; - dispatcherName: string; - dispatcherIsSupporter: boolean; - stationName: string; - stationHash: string; - region: string; - maxUsers: number; - currentUsers: number; - spawn: number; - lastSeen: number; - dispatcherExp: number; - nameFromHeader: string; - spawnString?: string; - networkConnectionString: string; - isOnline: number; - dispatcherRate: number; - dispatcherStatus: number; -} - -export interface Train { - id: string; - trainNo: number; - mass: number; - speed: number; - length: number; - distance: number; - stockString: string; - driverName: string; - driverId: number; - driverIsSupporter: boolean; - driverLevel: number; - currentStationHash: string; - currentStationName: string; - signal: string; - connectedTrack: string; - online: number; - lastSeen: number; - region: string; - isTimeout: boolean; - timetable?: Timetable; -} - -export interface Timetable { - SKR: boolean; - TWR: boolean; - hasDangerousCargo: boolean; - hasExtraDeliveries: boolean; - warningNotes: string; - category: string; - stopList: TimetableStop[]; - route: string; - timetableId: number; - sceneries: string[]; - path: string; -} - -export interface TimetableStop { - stopName: string; - stopNameRAW: string; - stopType: string; - stopDistance: number; - pointId: string; - comments?: (null | string)[]; - mainStop: boolean; - arrivalLine?: string; - arrivalTimestamp: number; - arrivalRealTimestamp: number; - arrivalDelay: number; - departureLine?: string; - departureTimestamp: number; - departureRealTimestamp: number; - departureDelay: number; - beginsHere: boolean; - terminatesHere: boolean; - confirmed: number; - stopped: number; - stopTime?: number; -} diff --git a/src/utils/vehicleUtils.ts b/src/utils/vehicleUtils.ts index 23f9098..0d6e0e1 100644 --- a/src/utils/vehicleUtils.ts +++ b/src/utils/vehicleUtils.ts @@ -1,6 +1,7 @@ import { ICarWagon, ILocomotive, IStock, IVehicleData, LocoGroupType, WagonGroupType } from '../types/common.types'; import { MassLimitLocoType, calculateMassLimit, calculateSpeedLimit } from './vehicleLimitsUtils'; +// UNUSED - ADDITIONAL CARGO TYPES FOR INTERMODALS export const additionalCargoTypes = [ { groupType: '627Z', @@ -41,12 +42,12 @@ export const additionalCargoTypes = [ groupType: '412Z', id: '412Z_mix1_sctc_loaded', weight: 43500, - cargoStringVariations: ['sc_20:tc_20_loaded', 'tc_20_loaded:sc_20'], + cargoStringVariations: ['sc_20:tc_20_loaded:tc_20_loaded'], }, { groupType: '412Z', id: '412Z_mix1_sctc_empty', - weight: 33970, + weight: 37735, cargoStringVariations: ['sc_20:tc_20_empty:sc_20'], }, ];