api & naming changes

This commit is contained in:
2024-04-06 14:54:54 +02:00
parent 90824dc0e5
commit 27f02e2c2b
20 changed files with 168 additions and 175 deletions

Before

Width:  |  Height:  |  Size: 1020 B

After

Width:  |  Height:  |  Size: 1020 B

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before

Width:  |  Height:  |  Size: 932 B

After

Width:  |  Height:  |  Size: 932 B

Before

Width:  |  Height:  |  Size: 953 B

After

Width:  |  Height:  |  Size: 953 B

+18 -17
View File
@@ -9,7 +9,7 @@
v-for="locoType in locomotiveTypeList" v-for="locoType in locomotiveTypeList"
:key="locoType.id" :key="locoType.id"
class="btn btn--choice" class="btn btn--choice"
:data-selected="locoType.id == store.chosenLocoPower" :data-selected="locoType.id == store.chosenLocoGroup"
@click="selectLocoType(locoType.id)" @click="selectLocoType(locoType.id)"
> >
{{ $t(`inputs.${locoType.id}`) }} {{ $t(`inputs.${locoType.id}`) }}
@@ -39,7 +39,7 @@
v-for="carType in carTypeList" v-for="carType in carTypeList"
:key="carType.id" :key="carType.id"
class="btn btn--choice" class="btn btn--choice"
:data-selected="carType.id == store.chosenCarUseType" :data-selected="carType.id == store.chosenCarGroup"
@click="selectCarWagonType(carType.id)" @click="selectCarWagonType(carType.id)"
> >
{{ $t(`inputs.${carType.id}`) }} {{ $t(`inputs.${carType.id}`) }}
@@ -70,7 +70,7 @@
id="cargo-select" id="cargo-select"
:disabled=" :disabled="
(store.chosenCar && !store.chosenCar.loadable) || (store.chosenCar && !store.chosenCar.loadable) ||
(store.chosenCar && store.chosenCar.useType == 'car-passenger') || (store.chosenCar && store.chosenCar.group == 'wagon-passenger') ||
!store.chosenCar !store.chosenCar
" "
data-select="cargo" data-select="cargo"
@@ -123,6 +123,7 @@ import imageMixin from '../../mixins/imageMixin';
import { useStore } from '../../store'; import { useStore } from '../../store';
import stockPreviewMixin from '../../mixins/stockPreviewMixin'; import stockPreviewMixin from '../../mixins/stockPreviewMixin';
import stockMixin from '../../mixins/stockMixin'; import stockMixin from '../../mixins/stockMixin';
import { LocoGroupType, WagonGroupType } from '../../types';
export default defineComponent({ export default defineComponent({
mixins: [imageMixin, stockPreviewMixin, stockMixin], mixins: [imageMixin, stockPreviewMixin, stockMixin],
@@ -131,33 +132,33 @@ export default defineComponent({
store: useStore(), store: useStore(),
locomotiveTypeList: [ locomotiveTypeList: [
{ {
id: 'loco-e', id: 'loco-electric',
desc: 'ELEKTRYCZNE', desc: 'ELEKTRYCZNE',
}, },
{ {
id: 'loco-s', id: 'loco-diesel',
desc: 'SPALINOWE', desc: 'SPALINOWE',
}, },
{ {
id: 'loco-ezt', id: 'unit-electric',
desc: 'ELEKTR. ZESPOŁY TRAKCYJNE', desc: 'ELEKTR. ZESPOŁY TRAKCYJNE',
}, },
{ {
id: 'loco-szt', id: 'unit-diesel',
desc: 'SPAL. ZESPOŁY TRAKCYJNE', desc: 'SPAL. ZESPOŁY TRAKCYJNE',
}, },
], ] as { id: LocoGroupType; desc: string }[],
carTypeList: [ carTypeList: [
{ {
id: 'car-passenger', id: 'wagon-passenger',
desc: 'PASAŻERSKIE', desc: 'PASAŻERSKIE',
}, },
{ {
id: 'car-cargo', id: 'wagon-freight',
desc: 'TOWAROWE', desc: 'TOWAROWE',
}, },
], ] as { id: WagonGroupType; desc: string }[],
}), }),
computed: { computed: {
@@ -165,14 +166,14 @@ export default defineComponent({
return this.store.locoDataList return this.store.locoDataList
.slice() .slice()
.sort((a, b) => (a.type > b.type ? 1 : -1)) .sort((a, b) => (a.type > b.type ? 1 : -1))
.filter((loco) => loco.power == this.store.chosenLocoPower); .filter((loco) => loco.group == this.store.chosenLocoGroup);
}, },
carOptions() { carOptions() {
return this.store.carDataList return this.store.carDataList
.slice() .slice()
.sort((a, b) => (a.type > b.type ? 1 : -1)) .sort((a, b) => (a.type > b.type ? 1 : -1))
.filter((car) => car.useType == this.store.chosenCarUseType); .filter((car) => car.group == this.store.chosenCarGroup);
}, },
}, },
@@ -209,14 +210,14 @@ export default defineComponent({
this.store.stockList[this.store.chosenStockListIndex] = stockObject; this.store.stockList[this.store.chosenStockListIndex] = stockObject;
}, },
selectLocoType(locoTypeId: string) { selectLocoType(locoGroupType: LocoGroupType) {
this.store.chosenLocoPower = locoTypeId; this.store.chosenLocoGroup = locoGroupType;
this.store.chosenVehicle = this.locoOptions[0]; this.store.chosenVehicle = this.locoOptions[0];
this.store.chosenLoco = this.locoOptions[0]; this.store.chosenLoco = this.locoOptions[0];
}, },
selectCarWagonType(carWagonTypeId: string) { selectCarWagonType(wagonGroupType: WagonGroupType) {
this.store.chosenCarUseType = carWagonTypeId; this.store.chosenCarGroup = wagonGroupType;
this.store.chosenVehicle = this.carOptions[0]; this.store.chosenVehicle = this.carOptions[0];
this.store.chosenCar = this.carOptions[0]; this.store.chosenCar = this.carOptions[0];
this.store.chosenCargo = null; this.store.chosenCargo = null;
@@ -20,7 +20,7 @@
<b style="color: #ccc"> <b style="color: #ccc">
{{ {{
$t( $t(
`preview.${isLocomotive(store.chosenVehicle) ? store.chosenVehicle.power : store.chosenVehicle.useType}` `preview.${isLocomotive(store.chosenVehicle) ? store.chosenVehicle.group : store.chosenVehicle.group}`
) )
}} }}
</b> </b>
@@ -37,7 +37,7 @@
<div v-else> <div v-else>
{{ {{
store.chosenVehicle.useType == 'car-cargo' store.chosenVehicle.group == 'wagon-freight'
? $t(`usage.${store.chosenVehicle.constructionType}`) ? $t(`usage.${store.chosenVehicle.constructionType}`)
: `${$t('preview.construction')} ${store.chosenVehicle.constructionType}` : `${$t('preview.construction')} ${store.chosenVehicle.constructionType}`
}} }}
@@ -60,7 +60,7 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from 'vue'; import { computed, defineComponent } from 'vue';
import { useStore } from '../../store'; import { useStore } from '../../store';
import { isLocomotive } from '../../utils/vehicleUtils'; import { isTractionUnit } from '../../utils/vehicleUtils';
import { ILocomotive, IVehicle } from '../../types'; import { ILocomotive, IVehicle } from '../../types';
import imageMixin from '../../mixins/imageMixin'; import imageMixin from '../../mixins/imageMixin';
@@ -103,7 +103,7 @@ export default defineComponent({
}, },
isLocomotive(vehicle: IVehicle): vehicle is ILocomotive { isLocomotive(vehicle: IVehicle): vehicle is ILocomotive {
return isLocomotive(vehicle); return isTractionUnit(vehicle);
}, },
onImageClick(e: Event) { onImageClick(e: Event) {
+1 -1
View File
@@ -290,7 +290,7 @@ export default defineComponent({
this.store.chosenLoco = null; this.store.chosenLoco = null;
this.store.chosenCargo = null; this.store.chosenCargo = null;
if (c) this.store.chosenCarUseType = c?.useType; if (c) this.store.chosenCarGroup = c?.group;
}, },
toggleCargoChosen(cargoType: string, vehicles: string[]) { toggleCargoChosen(cargoType: string, vehicles: string[]) {
+1
View File
@@ -474,6 +474,7 @@ export default defineComponent({
.warning { .warning {
padding: 0.25em; padding: 0.25em;
margin: 0.25em 0;
background: $accentColor; background: $accentColor;
color: black; color: black;
+12 -10
View File
@@ -67,9 +67,9 @@
</td> </td>
<td v-if="isLocomotive(vehicle)"> <td v-if="isLocomotive(vehicle)">
{{ $t(`wiki.${vehicle.power}`) }} {{ $t(`wiki.${vehicle.group}`) }}
</td> </td>
<td v-else>{{ $t(`wiki.${vehicle.useType}`) }}</td> <td v-else>{{ $t(`wiki.${vehicle.group}`) }}</td>
<td>{{ vehicle.constructionType }}</td> <td>{{ vehicle.constructionType }}</td>
<td>{{ vehicle.length }}m</td> <td>{{ vehicle.length }}m</td>
@@ -97,7 +97,7 @@ import { defineComponent } from 'vue';
import { useStore } from '../../store'; import { useStore } from '../../store';
import stockPreviewMixin from '../../mixins/stockPreviewMixin'; import stockPreviewMixin from '../../mixins/stockPreviewMixin';
import { IVehicle } from '../../types'; import { IVehicle } from '../../types';
import { isLocomotive } from '../../utils/vehicleUtils'; import { isTractionUnit } from '../../utils/vehicleUtils';
import stockMixin from '../../mixins/stockMixin'; import stockMixin from '../../mixins/stockMixin';
import imageMixin from '../../mixins/imageMixin'; import imageMixin from '../../mixins/imageMixin';
@@ -165,7 +165,7 @@ export default defineComponent({
}, },
methods: { methods: {
isLocomotive, isLocomotive: isTractionUnit,
toggleFilter(name: typeof this.currentFilterMode) { toggleFilter(name: typeof this.currentFilterMode) {
this.currentFilterMode = this.currentFilterMode == name ? 'all' : name; this.currentFilterMode = this.currentFilterMode == name ? 'all' : name;
@@ -198,14 +198,16 @@ export default defineComponent({
case 'cargoCount': case 'cargoCount':
return ( return (
(!isLocomotive(row1.vehicle) ? Math.sign(row1.vehicle.cargoTypes.length || -1) : -1) - (!isTractionUnit(row1.vehicle) ? Math.sign(row1.vehicle.cargoTypes.length || -1) : -1) -
(!isLocomotive(row2.vehicle) ? (row2.vehicle.cargoTypes.length || -1) * direction : -1) (!isTractionUnit(row2.vehicle)
? (row2.vehicle.cargoTypes.length || -1) * direction
: -1)
); );
case 'coldStart': case 'coldStart':
return ( return (
((isLocomotive(row1.vehicle) && row1.vehicle.coldStart ? 1 : -1) - ((isTractionUnit(row1.vehicle) && row1.vehicle.coldStart ? 1 : -1) -
(isLocomotive(row2.vehicle) && row2.vehicle.coldStart ? 1 : -1)) * (isTractionUnit(row2.vehicle) && row2.vehicle.coldStart ? 1 : -1)) *
direction direction
); );
@@ -227,8 +229,8 @@ export default defineComponent({
show: show:
new RegExp(`${this.searchedVehicleTypeName.trim()}`, 'i').test(vehicle.type) && new RegExp(`${this.searchedVehicleTypeName.trim()}`, 'i').test(vehicle.type) &&
(this.currentFilterMode == 'all' || (this.currentFilterMode == 'all' ||
(this.currentFilterMode == 'tractions' && isLocomotive(vehicle)) || (this.currentFilterMode == 'tractions' && isTractionUnit(vehicle)) ||
(this.currentFilterMode == 'carriages' && !isLocomotive(vehicle))), (this.currentFilterMode == 'carriages' && !isTractionUnit(vehicle))),
})) }))
.sort((a, b) => this.sortTableRows(a, b)); .sort((a, b) => this.sortTableRows(a, b));
}, },
+1 -1
View File
@@ -43,7 +43,7 @@ const onListItemClick = (index: number) => {
}; };
const stockImageError = (e: Event, stock: IStock) => { const stockImageError = (e: Event, stock: IStock) => {
(e.target as HTMLImageElement).src = `images/${stock.useType}-unknown.png`; (e.target as HTMLImageElement).src = `images/${stock.group}-unknown.png`;
}; };
watch( watch(
-9
View File
@@ -1,9 +0,0 @@
export const enum EVehicleUseType {
LOCO_ELECTRICAL = 'loco-e',
LOCO_DIESEL = 'loco-s',
EMU = 'loco-ezt',
DMU = 'loco-szt',
CAR_PASSENGER = 'car-passenger',
CAR_CARGO = 'car-cargo',
}
+19 -19
View File
@@ -15,12 +15,12 @@
"cargo-title": "Cargo (only selected freight cars)", "cargo-title": "Cargo (only selected freight cars)",
"no-cargo-available": "no cargo available", "no-cargo-available": "no cargo available",
"cargo-empty": "empty", "cargo-empty": "empty",
"loco-e": "ELECTR.", "loco-electric": "ELECTR.",
"loco-s": "DIESEL", "loco-diesel": "DIESEL",
"loco-ezt": "EMU", "unit-electric": "EMU",
"loco-szt": "DMU", "unit-diesel": "DMU",
"car-passenger": "PASSENGER", "wagon-passenger": "PASSENGER",
"car-cargo": "FREIGHT", "wagon-freight": "FREIGHT",
"action-add": "ADD NEW", "action-add": "ADD NEW",
"action-swap": "SWAP WITH", "action-swap": "SWAP WITH",
"real-stock": "POLISH TRAIN COMPOSITIONS" "real-stock": "POLISH TRAIN COMPOSITIONS"
@@ -30,12 +30,12 @@
"loading": "IMAGE LOADING...", "loading": "IMAGE LOADING...",
"desc": "Choose a railway vehicle above to see its preview", "desc": "Choose a railway vehicle above to see its preview",
"sponsor-only": "* SPONSORS ONLY UNTIL {0}", "sponsor-only": "* SPONSORS ONLY UNTIL {0}",
"loco-e": "ELECTRIC LOCO", "loco-electric": "ELECTRIC LOCO",
"loco-s": "DIESEL LOCO", "loco-diesel": "DIESEL LOCO",
"loco-ezt": "ELECTRIC M.U.", "unit-electric": "ELECTRIC M.U.",
"loco-szt": "DIESEL M.U.", "unit-diesel": "DIESEL M.U.",
"car-passenger": "PASSENGER CARRIAGE", "wagon-passenger": "PASSENGER CARRIAGE",
"car-cargo": "FREIGHT CARRIAGE", "wagon-freight": "FREIGHT CARRIAGE",
"cabin": "Cabin type:", "cabin": "Cabin type:",
"construction": "Construction type:" "construction": "Construction type:"
}, },
@@ -68,7 +68,7 @@
"coldstart-info": "Locomotive cold start", "coldstart-info": "Locomotive cold start",
"doublemanning-info": "Double manning", "doublemanning-info": "Double manning",
"list-empty": "Stock list is empty!", "list-empty": "Stock list is empty!",
"warning-not-suitable": "EP07 & EP08 type locomotives are designed for passenger traffic only!", "warning-not-suitable": "EP series locomotives are designed for passenger traffic only!",
"warning-passenger-too-long": "Maximum length of a passenger train may not be greater than 350m!", "warning-passenger-too-long": "Maximum length of a passenger train may not be greater than 350m!",
"warning-freight-too-long": "Maximum length of a freight train may not be greater than 650m!", "warning-freight-too-long": "Maximum length of a freight train may not be greater than 650m!",
"warning-too-many-locos": "This train has too many traction units!", "warning-too-many-locos": "This train has too many traction units!",
@@ -173,12 +173,12 @@
"maxSpeed": "Speed", "maxSpeed": "Speed",
"cargoCount": "Cargo count" "cargoCount": "Cargo count"
}, },
"loco-ezt": "EMU", "unit-electric": "EMU",
"loco-szt": "DMU", "unit-diesel": "DMU",
"loco-s": "Diesel locomotive", "loco-diesel": "Diesel locomotive",
"loco-e": "Electric locomotive", "loco-electric": "Electric locomotive",
"car-passenger": "Passenger carriage", "wagon-passenger": "Passenger carriage",
"car-cargo": "Frieght carriage" "wagon-freight": "Frieght carriage"
}, },
"realstock": { "realstock": {
"title": "POLISH TRAIN COMPOSITIONS by", "title": "POLISH TRAIN COMPOSITIONS by",
+19 -19
View File
@@ -15,12 +15,12 @@
"cargo-title": "Ładunek (tylko wybrane towarowe)", "cargo-title": "Ładunek (tylko wybrane towarowe)",
"no-cargo-available": "brak dostępnych ładunków", "no-cargo-available": "brak dostępnych ładunków",
"cargo-empty": "próżny", "cargo-empty": "próżny",
"loco-e": "ELEKTR.", "loco-electric": "ELEKTR.",
"loco-s": "SPAL.", "loco-diesel": "SPAL.",
"loco-ezt": "EZT", "unit-electric": "EZT",
"loco-szt": "SZT", "unit-diesel": "SZT",
"car-passenger": "PASAŻERSKIE", "wagon-passenger": "PASAŻERSKIE",
"car-cargo": "TOWAROWE", "wagon-freight": "TOWAROWE",
"action-add": "DODAJ NOWY", "action-add": "DODAJ NOWY",
"action-swap": "ZAMIEŃ ZA", "action-swap": "ZAMIEŃ ZA",
"real-stock": "REALNE ZESTAWIENIA" "real-stock": "REALNE ZESTAWIENIA"
@@ -30,12 +30,12 @@
"loading": "ŁADOWANIE OBRAZU...", "loading": "ŁADOWANIE OBRAZU...",
"desc": "Wybierz pojazd lub wagon, aby zobaczyć jego podgląd powyżej", "desc": "Wybierz pojazd lub wagon, aby zobaczyć jego podgląd powyżej",
"sponsor-only": "* TYLKO DLA SPONSORÓW DO {0}", "sponsor-only": "* TYLKO DLA SPONSORÓW DO {0}",
"loco-e": "ELEKTROWÓZ", "loco-electric": "ELEKTROWÓZ",
"loco-s": "SPALINOWÓZ", "loco-diesel": "SPALINOWÓZ",
"loco-ezt": "EZT", "unit-electric": "EZT",
"loco-szt": "SZT", "unit-diesel": "SZT",
"car-passenger": "WAGON PASAŻERSKI", "wagon-passenger": "WAGON PASAŻERSKI",
"car-cargo": "WAGON TOWAROWY", "wagon-freight": "WAGON TOWAROWY",
"cabin": "Typ kabiny:", "cabin": "Typ kabiny:",
"construction": "Typ konstrukcji:" "construction": "Typ konstrukcji:"
}, },
@@ -68,7 +68,7 @@
"coldstart-info": "Zimny start", "coldstart-info": "Zimny start",
"doublemanning-info": "Podwójna obsada", "doublemanning-info": "Podwójna obsada",
"list-empty": "Lista pojazdów jest pusta!", "list-empty": "Lista pojazdów jest pusta!",
"warning-not-suitable": "Lokomotywy EP07 i EP08 są przeznaczone jedynie do ruchu pasażerskiego!", "warning-not-suitable": "Lokomotywy serii EP są przeznaczone jedynie do ruchu pasażerskiego!",
"warning-passenger-too-long": "Maksymalna długość składów pasażerskich nie może przekraczać 350m!", "warning-passenger-too-long": "Maksymalna długość składów pasażerskich nie może przekraczać 350m!",
"warning-freight-too-long": "Maksymalna długość składów innych niż pasażerskie nie może przekraczać 650m!", "warning-freight-too-long": "Maksymalna długość składów innych niż pasażerskie nie może przekraczać 650m!",
"warning-too-many-locos": "Ten skład posiada za dużo pojazdów trakcyjnych!", "warning-too-many-locos": "Ten skład posiada za dużo pojazdów trakcyjnych!",
@@ -173,12 +173,12 @@
"maxSpeed": "Prędkość", "maxSpeed": "Prędkość",
"cargoCount": "Ładunki" "cargoCount": "Ładunki"
}, },
"loco-ezt": "EZT", "loco-diesel": "Spalinowóz",
"loco-szt": "SZT", "loco-electric": "Elektrowóz",
"loco-s": "Spalinowóz", "unit-electric": "EZT",
"loco-e": "Elektrowóz", "unit-diesel": "SZT",
"car-passenger": "Wagon pasażerski", "wagon-passenger": "Wagon pasażerski",
"car-cargo": "Wagon towarowy" "wagon-freight": "Wagon towarowy"
}, },
"realstock": { "realstock": {
"title": "ZESTAWIENIA REALNE by", "title": "ZESTAWIENIA REALNE by",
+3 -4
View File
@@ -1,7 +1,7 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { useStore } from '../store'; import { useStore } from '../store';
import { ICarWagon, ILocomotive, IStock, ICargo, IVehicle } from '../types'; import { ICarWagon, ILocomotive, IStock, ICargo, IVehicle } from '../types';
import { isLocomotive } from '../utils/vehicleUtils'; import { isTractionUnit } from '../utils/vehicleUtils';
export default defineComponent({ export default defineComponent({
setup() { setup() {
@@ -16,7 +16,7 @@ export default defineComponent({
}, },
getStockObject(vehicle: IVehicle, cargo?: ICargo | null, count = 1): IStock { getStockObject(vehicle: IVehicle, cargo?: ICargo | null, count = 1): IStock {
const isLoco = isLocomotive(vehicle); const isLoco = isTractionUnit(vehicle);
return { return {
id: this.getStockId(), id: this.getStockId(),
@@ -27,8 +27,7 @@ export default defineComponent({
isLoco, isLoco,
cargo: !isLoco && vehicle.loadable && cargo ? cargo : undefined, cargo: !isLoco && vehicle.loadable && cargo ? cargo : undefined,
count, count,
imgSrc: vehicle.imageSrc, group: isLoco ? vehicle.group : vehicle.group,
useType: isLoco ? vehicle.power : vehicle.useType,
isSponsorsOnly: vehicle.isSponsorsOnly, isSponsorsOnly: vehicle.isSponsorsOnly,
constructionType: vehicle.constructionType, constructionType: vehicle.constructionType,
sponsorsOnlyTimestamp: vehicle.sponsorsOnlyTimestamp, sponsorsOnlyTimestamp: vehicle.sponsorsOnlyTimestamp,
+8 -8
View File
@@ -1,7 +1,7 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { useStore } from '../store'; import { useStore } from '../store';
import { ICarWagon, ILocomotive, IStock, IVehicle } from '../types'; import { ICarWagon, ILocomotive, IStock, IVehicle, LocoGroupType, WagonGroupType } from '../types';
import { isLocomotive } from '../utils/vehicleUtils'; import { isTractionUnit } from '../utils/vehicleUtils';
export default defineComponent({ export default defineComponent({
setup() { setup() {
@@ -14,40 +14,40 @@ export default defineComponent({
methods: { methods: {
previewStock(stock: IStock) { previewStock(stock: IStock) {
if (this.store.chosenVehicle?.imageSrc != stock.imgSrc) this.store.imageLoading = true; // if (this.store.chosenVehicle?.imageSrc != stock.imgSrc) this.store.imageLoading = true;
if (stock.isLoco) { if (stock.isLoco) {
const chosenLoco = this.store.locoDataList.find((v) => v.type == stock.type) || null; const chosenLoco = this.store.locoDataList.find((v) => v.type == stock.type) || null;
this.store.chosenVehicle = chosenLoco; this.store.chosenVehicle = chosenLoco;
this.store.chosenLoco = chosenLoco; this.store.chosenLoco = chosenLoco;
this.store.chosenCargo = null; this.store.chosenCargo = null;
this.store.chosenLocoPower = stock.useType; this.store.chosenLocoGroup = stock.group as LocoGroupType;
} else { } else {
const chosenCar = this.store.carDataList.find((v) => v.type == stock.type) || null; const chosenCar = this.store.carDataList.find((v) => v.type == stock.type) || null;
this.store.chosenVehicle = chosenCar; this.store.chosenVehicle = chosenCar;
this.store.chosenCar = chosenCar; this.store.chosenCar = chosenCar;
this.store.chosenCargo = stock.cargo || null; this.store.chosenCargo = stock.cargo || null;
this.store.chosenCarUseType = stock.useType; this.store.chosenCarGroup = stock.group as WagonGroupType;
} }
}, },
previewLocomotive(loco: ILocomotive) { previewLocomotive(loco: ILocomotive) {
this.store.chosenLoco = loco; this.store.chosenLoco = loco;
this.store.chosenVehicle = loco; this.store.chosenVehicle = loco;
this.store.chosenLocoPower = loco.power; this.store.chosenLocoGroup = loco.group;
}, },
previewCarWagon(carWagon: ICarWagon) { previewCarWagon(carWagon: ICarWagon) {
this.store.chosenCar = carWagon; this.store.chosenCar = carWagon;
this.store.chosenCarUseType = carWagon.useType; this.store.chosenCarGroup = carWagon.group;
this.store.chosenVehicle = carWagon; this.store.chosenVehicle = carWagon;
this.store.chosenCargo = null; this.store.chosenCargo = null;
}, },
previewVehicle(vehicle: IVehicle) { previewVehicle(vehicle: IVehicle) {
if (isLocomotive(vehicle)) this.previewLocomotive(vehicle); if (isTractionUnit(vehicle)) this.previewLocomotive(vehicle);
else this.previewCarWagon(vehicle); else this.previewCarWagon(vehicle);
}, },
+7 -3
View File
@@ -6,6 +6,8 @@ import {
IVehicle, IVehicle,
IStock, IStock,
IRealComposition, IRealComposition,
LocoGroupType,
WagonGroupType,
} from './types'; } from './types';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { import {
@@ -33,8 +35,8 @@ export const useStore = defineStore({
imageLoading: false, imageLoading: false,
chosenLocoPower: 'loco-e', chosenLocoGroup: 'loco-electric' as LocoGroupType,
chosenCarUseType: 'car-passenger', chosenCarGroup: 'wagon-passenger' as WagonGroupType,
stockList: [] as IStock[], stockList: [] as IStock[],
cargoOptions: [] as any[][], cargoOptions: [] as any[][],
@@ -123,8 +125,10 @@ export const useStore = defineStore({
actions: { actions: {
async fetchVehiclesAPI() { async fetchVehiclesAPI() {
try { try {
const vehiclesData = (await http.get<IVehiclesAPI>('/vehicles.json')).data; const vehiclesData = (await http.get<IVehiclesAPI>('/vehiclesData')).data;
this.vehiclesAPIData = vehiclesData; this.vehiclesAPIData = vehiclesData;
console.log(vehiclesData);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
+21 -24
View File
@@ -1,18 +1,19 @@
export type IVehicle = ILocomotive | ICarWagon; export type IVehicle = ILocomotive | ICarWagon;
export type StockSectionMode = 'STOCK_LIST' | 'STOCK_GENERATOR'; export type StockSectionMode = 'STOCK_LIST' | 'STOCK_GENERATOR';
export type TLocoGroup = 'loco-e' | 'loco-s' | 'loco-ezt' | 'loco-szt'; export type LocoGroupType = 'loco-electric' | 'loco-diesel' | 'unit-electric' | 'unit-diesel';
export type TCarWagonGroup = 'car-passenger' | 'car-cargo'; export type WagonGroupType = 'wagon-passenger' | 'wagon-freight';
export type VehicleGroupType = LocoGroupType & WagonGroupType;
export interface IStockProps { export interface IVehicleProps {
type: string; type: string;
speed: number;
length: number; length: number;
// mass: number;
weight: number; weight: number;
// cargo?: string | null; cargoTypes?: ICargo[];
cargoTypes: ICargo[] | null;
coldStart?: boolean; coldStart?: boolean;
doubleManned?: boolean; doubleManned?: boolean;
supporterTimestamp?: number;
} }
export interface ICargo { export interface ICargo {
@@ -29,16 +30,18 @@ export interface IVehiclesAPI {
}; };
}; };
vehicleInfo: { vehicleList: string[][];
'car-cargo': [string, string, boolean, number | null, string][];
'car-passenger': [string, string, boolean, number | null, string][];
'loco-e': [string, string, string, string, number | null][];
'loco-s': [string, string, string, string, number | null][];
'loco-szt': [string, string, string, string, number | null][];
'loco-ezt': [string, string, string, string, number | null][];
};
vehicleProps: IStockProps[]; // vehiclesList: {
// 'loco-electric': string[][];
// 'loco-diesel': string[][];
// 'unit-electric': string[][];
// 'unit-diesel': string[][];
// 'wagon-passenger': string[][];
// 'wagon-freight': string[][];
// };
vehicleProps: IVehicleProps[];
vehicleLocales: { vehicleLocales: {
pl: { pl: {
@@ -56,14 +59,12 @@ export interface IVehiclesAPI {
export interface ILocomotive { export interface ILocomotive {
type: string; type: string;
power: TLocoGroup; group: LocoGroupType;
group: TLocoGroup;
constructionType: string; constructionType: string;
cabinType: string; cabinType: string;
maxSpeed: number; maxSpeed: number;
isSponsorsOnly: boolean; isSponsorsOnly: boolean;
sponsorsOnlyTimestamp: number; sponsorsOnlyTimestamp: number;
imageSrc: string;
weight: number; weight: number;
length: number; length: number;
coldStart: boolean; coldStart: boolean;
@@ -72,14 +73,12 @@ export interface ILocomotive {
export interface ICarWagon { export interface ICarWagon {
type: string; type: string;
useType: TCarWagonGroup; group: WagonGroupType;
group: TCarWagonGroup;
constructionType: string; constructionType: string;
loadable: boolean; loadable: boolean;
isSponsorsOnly: boolean; isSponsorsOnly: boolean;
sponsorsOnlyTimestamp: number; sponsorsOnlyTimestamp: number;
maxSpeed: number; maxSpeed: number;
imageSrc: string;
weight: number; weight: number;
length: number; length: number;
cargoTypes: ICargo[]; cargoTypes: ICargo[];
@@ -88,10 +87,9 @@ export interface ICarWagon {
export interface IStock { export interface IStock {
id: string; id: string;
type: string; type: string;
useType: string; group: LocoGroupType | WagonGroupType;
constructionType: string; constructionType: string;
length: number; length: number;
// mass: number;
weight: number; weight: number;
maxSpeed: number; maxSpeed: number;
cargo?: ICargo; cargo?: ICargo;
@@ -99,7 +97,6 @@ export interface IStock {
isSponsorsOnly: boolean; isSponsorsOnly: boolean;
sponsorsOnlyTimestamp: number; sponsorsOnlyTimestamp: number;
count: number; count: number;
imgSrc?: string;
} }
export interface IRealComposition { export interface IRealComposition {
+53 -55
View File
@@ -1,5 +1,11 @@
import { EVehicleUseType } from '../enums/EVehicleUseType'; import {
import { ICarWagon, ILocomotive, IStock, IVehiclesAPI, TCarWagonGroup, TLocoGroup } from '../types'; ICarWagon,
ILocomotive,
IStock,
IVehiclesAPI,
LocoGroupType,
WagonGroupType,
} from '../types';
import { import {
MassLimitLocoType, MassLimitLocoType,
SpeedLimitLocoType, SpeedLimitLocoType,
@@ -7,44 +13,41 @@ import {
calculateSpeedLimit, calculateSpeedLimit,
} from './vehicleLimitsUtils'; } from './vehicleLimitsUtils';
export function isLocomotive(vehicle: ILocomotive | ICarWagon): vehicle is ILocomotive { export function isTractionUnit(vehicle: ILocomotive | ICarWagon): vehicle is ILocomotive {
return (vehicle as ILocomotive).power !== undefined; return (vehicle as ILocomotive).cabinType !== undefined;
} }
export function locoDataList(vehiclesData: IVehiclesAPI | undefined) { export function locoDataList(vehiclesData: IVehiclesAPI | undefined) {
if (!vehiclesData) return []; if (!vehiclesData) return [];
return Object.keys(vehiclesData.vehicleInfo).reduce((acc, vehiclePower) => { return vehiclesData.vehicleList.reduce((acc, vehicleInfoArray) => {
if (!vehiclePower.startsWith('loco')) return acc; // check if data array has 4 elements (locos & units only)
if (vehicleInfoArray.length != 4) return acc;
const locoVehiclesData = vehiclesData.vehicleInfo[vehiclePower as TLocoGroup]; const [type, constructionType, cabinType, group] = vehicleInfoArray;
const locoProps = vehiclesData.vehicleProps.find((prop) => constructionType == prop.type);
locoVehiclesData.forEach((loco) => { if (!locoProps) {
// if (!loco[4]) return; console.warn('No loco props', type);
return acc;
}
const [type, constructionType, cabinType, maxSpeed, sponsorsTimestamp] = loco; acc.push({
const locoProps = vehiclesData.vehicleProps.find((prop) => constructionType == prop.type); group: group as LocoGroupType,
acc.push({ type,
power: vehiclePower as TLocoGroup, constructionType,
group: vehiclePower as TLocoGroup, cabinType,
type,
constructionType,
cabinType,
maxSpeed: Number(maxSpeed),
isSponsorsOnly: Number(sponsorsTimestamp) > Date.now(),
sponsorsOnlyTimestamp: Number(sponsorsTimestamp),
imageSrc: '',
length: isSponsorsOnly: (locoProps.supporterTimestamp ?? 0) > Date.now(),
locoProps?.length && type.startsWith('2EN') sponsorsOnlyTimestamp: locoProps.supporterTimestamp ?? 0,
? locoProps.length * 2
: locoProps?.length ?? 0,
weight: locoProps?.weight && type.startsWith('2EN') ? 253000 : locoProps?.weight ?? 0,
coldStart: locoProps?.coldStart ?? false, maxSpeed: locoProps.speed,
doubleManned: locoProps?.doubleManned ?? false, length: locoProps.length,
}); weight: locoProps.weight,
coldStart: locoProps.coldStart ?? false,
doubleManned: locoProps.doubleManned ?? false,
}); });
return acc; return acc;
@@ -54,35 +57,30 @@ export function locoDataList(vehiclesData: IVehiclesAPI | undefined) {
export function carDataList(vehiclesData: IVehiclesAPI | undefined) { export function carDataList(vehiclesData: IVehiclesAPI | undefined) {
if (!vehiclesData) return []; if (!vehiclesData) return [];
return Object.keys(vehiclesData.vehicleInfo).reduce((acc, vehicleUseType) => { return vehiclesData.vehicleList.reduce((acc, vehicleInfoArray) => {
if (!vehicleUseType.startsWith('car')) return acc; // check if data array has 3 elements (wagons only)
if (vehicleInfoArray.length != 3) return acc;
const carVehiclesData = vehiclesData.vehicleInfo[vehicleUseType as TCarWagonGroup]; const [type, constructionType, group] = vehicleInfoArray;
const wagonProps = vehiclesData.vehicleProps.find((v) => type.toString().startsWith(v.type));
carVehiclesData.forEach((car) => { if (!wagonProps) {
const [type, constructionType, loadable, sponsorsOnlyTimestamp, maxSpeed] = car; console.warn('No wagon props', type);
return acc;
}
if (sponsorsOnlyTimestamp && Number(sponsorsOnlyTimestamp) <= Date.now()) return; acc.push({
group: group as WagonGroupType,
type,
constructionType,
loadable: wagonProps.cargoTypes ? wagonProps.cargoTypes.length > 0 : false,
isSponsorsOnly: (wagonProps.supporterTimestamp ?? 0) > Date.now(),
sponsorsOnlyTimestamp: wagonProps.supporterTimestamp ?? 0,
cargoTypes: wagonProps?.cargoTypes ?? [],
const carPropsData = vehiclesData.vehicleProps.find((v) => maxSpeed: wagonProps.speed,
type.toString().startsWith(v.type) weight: wagonProps?.weight || 0,
); length: wagonProps?.length || 0,
acc.push({
useType: vehicleUseType as TCarWagonGroup,
group: vehicleUseType as TCarWagonGroup,
type,
constructionType,
loadable,
isSponsorsOnly: Number(sponsorsOnlyTimestamp) > Date.now(),
sponsorsOnlyTimestamp: Number(sponsorsOnlyTimestamp),
maxSpeed: Number(maxSpeed),
imageSrc: '',
cargoTypes: carPropsData?.cargoTypes ?? [],
weight: carPropsData?.weight || 0,
length: carPropsData?.length || 0,
});
}); });
return acc; return acc;
@@ -142,5 +140,5 @@ export function isTrainPassenger(stockList: IStock[]) {
return stockList return stockList
.filter((stock) => !stock.isLoco) .filter((stock) => !stock.isLoco)
.every((stock) => stock.useType === EVehicleUseType.CAR_PASSENGER); .every((stock) => stock.group === 'wagon-passenger');
} }
+1 -1
View File
@@ -37,7 +37,7 @@ export default defineConfig({
}, },
}, },
{ {
urlPattern: /^https:\/\/static.spythere.eu\/.*/i, urlPattern: /^https:\/\/static.spythere.eu\/images\/.*/i,
handler: 'CacheFirst', handler: 'CacheFirst',
options: { options: {
cacheName: 'spythere-api-cache', cacheName: 'spythere-api-cache',