przystosowanie pod nowy format danych

This commit is contained in:
2023-02-15 19:05:30 +01:00
parent 132b5d5273
commit 30ce48bc02
4 changed files with 44 additions and 119 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ export default defineComponent({
async created() { async created() {
const stockData = await ( 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(); ).json();
this.store.stockData = stockData; this.store.stockData = stockData;
+1 -1
View File
@@ -95,7 +95,7 @@ export default defineComponent({
async mounted() { async mounted() {
const readyStockJSONData: ResponseJSONData = await ( 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(); ).json();
if (!readyStockJSONData) { if (!readyStockJSONData) {
+10 -1
View File
@@ -49,7 +49,12 @@ export interface IStockData {
}; };
info: { 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[]; props: IStockProps[];
@@ -108,3 +113,7 @@ export interface IReadyStockList {
[key: string]: { stockString: string; type: string; number: string; name: string }; [key: string]: { stockString: string; type: string; number: string; name: string };
} }
+32 -116
View File
@@ -2,36 +2,6 @@ import { EVehicleUseType } from '../enums/EVehicleUseType';
import { ICarWagon, ILocomotive, IStore, TStockInfoKey } from '../types'; import { ICarWagon, ILocomotive, IStore, TStockInfoKey } from '../types';
import { LocoType, calculateSpeedLimit } from './speedLimitUtils'; 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 { export function isLocomotive(vehicle: ILocomotive | ICarWagon): vehicle is ILocomotive {
return (vehicle as ILocomotive).power !== undefined; return (vehicle as ILocomotive).power !== undefined;
} }
@@ -41,84 +11,28 @@ export function locoDataList(state: IStore) {
const stockData = state.stockData; const stockData = state.stockData;
return Object.keys(stockData.info).reduce((acc, vehicleTypeKey) => { return Object.keys(stockData.info).reduce((acc, vehiclePower) => {
if (!vehicleTypeKey.startsWith('loco')) return acc; 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) => { locoVehiclesData.forEach((loco) => {
if (state.showSupporter && !loco[4]) return; if (state.showSupporter && !loco[4]) return;
const locoType = loco[0] as string; const [type, constructionType, cabinType, maxSpeed, supportersOnly] = loco;
const locoProps = stockData.props.find((prop) => constructionType == prop.type);
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;
}
acc.push({ acc.push({
power: vehicleTypeKey, power: vehiclePower,
type: loco[0] as string, type,
constructionType: loco[1] as string, constructionType,
cabinType: loco[2] as string, cabinType,
maxSpeed: Number(loco[3] as string), maxSpeed: Number(maxSpeed),
supportersOnly: loco[4] as boolean, supportersOnly,
imageSrc: loco[5] as string, imageSrc: '',
length, length: locoProps?.length && type.startsWith('2EN') ? locoProps.length * 2 : locoProps?.length || 0,
mass, mass: locoProps?.mass && type.startsWith('2EN') ? 253 : locoProps?.mass || 0,
}); });
}); });
@@ -131,10 +45,10 @@ export function carDataList(state: IStore) {
const stockData = state.stockData; const stockData = state.stockData;
return Object.keys(stockData.info).reduce((acc, vehicleTypeKey) => { return Object.keys(stockData.info).reduce((acc, vehicleUseType) => {
if (!vehicleTypeKey.startsWith('car')) return acc; 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) => { carVehiclesData.forEach((car) => {
if (state.showSupporter && !car[3]) return; 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)); const carPropsData = stockData.props.find((v) => car[0].toString().startsWith(v.type));
acc.push({ acc.push({
useType: vehicleTypeKey as 'car-passenger' | 'car-cargo', useType: vehicleUseType as 'car-passenger' | 'car-cargo',
type: car[0] as string, type: car[0],
constructionType: car[1] as string, constructionType: car[1],
loadable: car[2] as boolean, loadable: car[2],
supportersOnly: car[3] as boolean, supportersOnly: car[3],
maxSpeed: Number(car[4] as string), maxSpeed: Number(car[4]),
imageSrc: car[5] as string, imageSrc: '',
cargoList: carPropsData?.cargo.split(';').filter((s) => s.length > 0) cargoList:
? carPropsData.cargo.split(';').map((cargo) => ({ !carPropsData || carPropsData.cargo === null
id: cargo.split(':')[0], ? []
totalMass: Number(cargo.split(':')[1]), : carPropsData.cargo.split(';').map((cargo) => ({
})) id: cargo.split(':')[0],
: [], totalMass: Number(cargo.split(':')[1]),
})),
mass: carPropsData?.mass || 0, mass: carPropsData?.mass || 0,
length: carPropsData?.length || 0, length: carPropsData?.length || 0,
}); });