diff --git a/src/App.vue b/src/App.vue index 31277eb..32b5b25 100644 --- a/src/App.vue +++ b/src/App.vue @@ -70,7 +70,7 @@ export default defineComponent({ async created() { const stockData = await ( - await fetch(`https://spythere.github.io/api/td2/data/stockData.json?t=${Math.floor(Date.now() / 60000)}`) + await fetch(`https://spythere.github.io/api/td2/data/stockInfo.json?t=${Math.floor(Date.now() / 60000)}`) ).json(); this.store.stockData = stockData; diff --git a/src/components/cards/RealStockCard.vue b/src/components/cards/RealStockCard.vue index 7a79e53..cf8ff49 100644 --- a/src/components/cards/RealStockCard.vue +++ b/src/components/cards/RealStockCard.vue @@ -95,7 +95,7 @@ export default defineComponent({ async mounted() { const readyStockJSONData: ResponseJSONData = await ( - await fetch(`https://spythere.github.io/api/readyStock.json?t=${Math.floor(Date.now() / 60000)}`) + await fetch(`https://spythere.github.io/api/td2/data/readyStock.json?t=${Math.floor(Date.now() / 60000)}`) ).json(); if (!readyStockJSONData) { diff --git a/src/types.ts b/src/types.ts index e804184..9786c80 100644 --- a/src/types.ts +++ b/src/types.ts @@ -49,7 +49,12 @@ export interface IStockData { }; info: { - [key in TStockInfoKey]: any[]; + 'car-cargo': [string, string, boolean, boolean, string][]; + 'car-passenger': [string, string, boolean, boolean, string][]; + 'loco-e': [string, string, string, string, boolean][]; + 'loco-s': [string, string, string, string, boolean][]; + 'loco-szt': [string, string, string, string, boolean][]; + 'loco-ezt': [string, string, string, string, boolean][]; }; props: IStockProps[]; @@ -108,3 +113,7 @@ export interface IReadyStockList { [key: string]: { stockString: string; type: string; number: string; name: string }; } + + + + diff --git a/src/utils/vehicleUtils.ts b/src/utils/vehicleUtils.ts index d36099c..a3ff4fb 100644 --- a/src/utils/vehicleUtils.ts +++ b/src/utils/vehicleUtils.ts @@ -2,36 +2,6 @@ import { EVehicleUseType } from '../enums/EVehicleUseType'; import { ICarWagon, ILocomotive, IStore, TStockInfoKey } from '../types'; import { LocoType, calculateSpeedLimit } from './speedLimitUtils'; -// rodzaj: [tMaxPas, vMaxPas, tMaxTow, vMaxTow] | SM42: [tMax, vMax, ...] -// const maxAllowedSpeedTable = { -// EU07: [ -// [650, 125], -// [2000, 70], -// ], -// EP07: [ -// [650, 125], -// [0, 0], -// ], -// EP08: [ -// [650, 140], -// [0, 0], -// ], -// ET41: [ -// [700, 125], -// [4000, 70], -// ], -// SM42: [ -// [95, 90], -// [200, 80], -// [300, 70], -// [450, 60], -// [750, 50], -// [1130, 40], -// [1720, 30], -// [2400, 20], -// ], -// }; - export function isLocomotive(vehicle: ILocomotive | ICarWagon): vehicle is ILocomotive { return (vehicle as ILocomotive).power !== undefined; } @@ -41,84 +11,28 @@ export function locoDataList(state: IStore) { const stockData = state.stockData; - return Object.keys(stockData.info).reduce((acc, vehicleTypeKey) => { - if (!vehicleTypeKey.startsWith('loco')) return acc; + return Object.keys(stockData.info).reduce((acc, vehiclePower) => { + if (!vehiclePower.startsWith('loco')) return acc; - const locoVehiclesData = stockData.info[vehicleTypeKey as TStockInfoKey]; + const locoVehiclesData = stockData.info[vehiclePower as 'loco-e' | 'loco-s' | 'loco-ezt' | 'loco-szt']; locoVehiclesData.forEach((loco) => { if (state.showSupporter && !loco[4]) return; - const locoType = loco[0] as string; - - let length = 0, - mass = 0; - - // Elektrowozy - if (vehicleTypeKey.startsWith('loco-e')) { - // 32m dla ET41, reszta 16 - length = locoType.startsWith('ET') ? 32 : 16; - - // 80t dla wszystkich EU06, EP08 - mass = 80; - - // 83t dla: EU07 o nr większych niż 300 & dla wszystkich EP07 oprócz nr 135,242,1002,1048 - const locoNumber = Number(locoType.split('-')[1]); - - if ( - (locoType.startsWith('EU') && locoNumber > 300) || - (locoType.startsWith('EP') && ![242, 135, 1002, 1048].includes(locoNumber)) - ) { - mass = 83; - } - - if (locoType.startsWith('ET')) { - mass = 167; - } - } - - // Spalinowozy - if (vehicleTypeKey.startsWith('loco-s')) { - length = 14; - mass = 74; - } - - // EZT - if (vehicleTypeKey.startsWith('loco-ezt')) { - // EN57 - length = 65; - mass = 126; - - // EN71 - if (locoType.startsWith('EN71')) { - length = 86; - mass = 182; - } - - // 2xEN57 - if (locoType.startsWith('2EN57')) { - length = 130; - mass = 253; - } - } - - // SZT - if (vehicleTypeKey.startsWith('loco-szt')) { - length = 14; - mass = 23; - } + const [type, constructionType, cabinType, maxSpeed, supportersOnly] = loco; + const locoProps = stockData.props.find((prop) => constructionType == prop.type); acc.push({ - power: vehicleTypeKey, - type: loco[0] as string, - constructionType: loco[1] as string, - cabinType: loco[2] as string, - maxSpeed: Number(loco[3] as string), - supportersOnly: loco[4] as boolean, - imageSrc: loco[5] as string, + power: vehiclePower, + type, + constructionType, + cabinType, + maxSpeed: Number(maxSpeed), + supportersOnly, + imageSrc: '', - length, - mass, + length: locoProps?.length && type.startsWith('2EN') ? locoProps.length * 2 : locoProps?.length || 0, + mass: locoProps?.mass && type.startsWith('2EN') ? 253 : locoProps?.mass || 0, }); }); @@ -131,10 +45,10 @@ export function carDataList(state: IStore) { const stockData = state.stockData; - return Object.keys(stockData.info).reduce((acc, vehicleTypeKey) => { - if (!vehicleTypeKey.startsWith('car')) return acc; + return Object.keys(stockData.info).reduce((acc, vehicleUseType) => { + if (!vehicleUseType.startsWith('car')) return acc; - const carVehiclesData = stockData.info[vehicleTypeKey as TStockInfoKey]; + const carVehiclesData = stockData.info[vehicleUseType as 'car-passenger' | 'car-cargo']; carVehiclesData.forEach((car) => { if (state.showSupporter && !car[3]) return; @@ -142,19 +56,21 @@ export function carDataList(state: IStore) { const carPropsData = stockData.props.find((v) => car[0].toString().startsWith(v.type)); acc.push({ - useType: vehicleTypeKey as 'car-passenger' | 'car-cargo', - type: car[0] as string, - constructionType: car[1] as string, - loadable: car[2] as boolean, - supportersOnly: car[3] as boolean, - maxSpeed: Number(car[4] as string), - imageSrc: car[5] as string, - cargoList: carPropsData?.cargo.split(';').filter((s) => s.length > 0) - ? carPropsData.cargo.split(';').map((cargo) => ({ - id: cargo.split(':')[0], - totalMass: Number(cargo.split(':')[1]), - })) - : [], + useType: vehicleUseType as 'car-passenger' | 'car-cargo', + type: car[0], + constructionType: car[1], + loadable: car[2], + supportersOnly: car[3], + maxSpeed: Number(car[4]), + imageSrc: '', + cargoList: + !carPropsData || carPropsData.cargo === null + ? [] + : carPropsData.cargo.split(';').map((cargo) => ({ + id: cargo.split(':')[0], + totalMass: Number(cargo.split(':')[1]), + })), + mass: carPropsData?.mass || 0, length: carPropsData?.length || 0, });