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
+32 -116
View File
@@ -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,
});