mirror of
https://github.com/Spythere/pojazdownik.git
synced 2026-05-03 05:18:10 +00:00
Pobieranie danych z API zamiast lokalnie
This commit is contained in:
+4
-5
@@ -65,14 +65,13 @@ export default defineComponent({
|
||||
|
||||
data: () => ({
|
||||
VERSION: packageInfo.version,
|
||||
store: useStore(),
|
||||
}),
|
||||
|
||||
setup() {
|
||||
const store = useStore();
|
||||
async created() {
|
||||
const stockData = await (await fetch('https://spythere.github.io/api/stockData.json')).json();
|
||||
|
||||
return {
|
||||
store,
|
||||
};
|
||||
this.store.stockData = stockData;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -31,9 +31,9 @@
|
||||
<div class="generator_cargo">
|
||||
<button
|
||||
class="btn"
|
||||
:data-chosen="chosenCargoTypes.includes(k)"
|
||||
v-for="(v, k) in generatorData.cargo"
|
||||
@click="toggleCargoChosen(k, v)"
|
||||
:data-chosen="chosenCargoTypes.includes(k as string)"
|
||||
v-for="(v, k) in store.stockData?.generator.cargo"
|
||||
@click="toggleCargoChosen(k as string, v)"
|
||||
>
|
||||
{{ k }}
|
||||
</button>
|
||||
@@ -91,24 +91,16 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { useStore } from '../store';
|
||||
|
||||
import generatorData from '../data/generatorData.json';
|
||||
import stockMixin from '../mixins/stockMixin';
|
||||
import { ICargo, ICarWagon } from '../types';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'stock-generator',
|
||||
|
||||
setup() {
|
||||
return {
|
||||
store: useStore(),
|
||||
};
|
||||
},
|
||||
|
||||
mixins: [stockMixin],
|
||||
|
||||
data() {
|
||||
return {
|
||||
generatorData,
|
||||
chosenCarTypes: [] as string[],
|
||||
excludedCarTypes: [] as string[],
|
||||
|
||||
@@ -119,6 +111,8 @@ export default defineComponent({
|
||||
maxMass: 3000,
|
||||
maxLength: 650,
|
||||
maxCarCount: 50,
|
||||
|
||||
store: useStore(),
|
||||
};
|
||||
},
|
||||
|
||||
@@ -149,7 +143,7 @@ export default defineComponent({
|
||||
|
||||
generateStock(empty = false) {
|
||||
const generatedChosenStockList = this.chosenCargoTypes.reduce((acc, type) => {
|
||||
this.generatorData.cargo[type as keyof typeof this.generatorData.cargo]
|
||||
this.store.stockData?.generator.cargo[type]
|
||||
.filter((c) => !this.excludedCarTypes.includes(c.split(':')[0]))
|
||||
.forEach((c) => {
|
||||
const [type, cargoType] = c.split(':');
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<div v-else>
|
||||
{{
|
||||
store.chosenVehicle.useType == 'car-cargo'
|
||||
? carUsage[store.chosenVehicle.constructionType]
|
||||
? store.stockData?.usage[store.chosenVehicle.constructionType]
|
||||
: 'Typ konstrukcji: ' + store.chosenVehicle.constructionType
|
||||
}}
|
||||
</div>
|
||||
@@ -49,11 +49,10 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import carUsage from '../data/carUsage.json';
|
||||
import { computed, defineComponent } from 'vue';
|
||||
import { useStore } from '../store';
|
||||
import { isLocomotive } from '../utils/vehicleUtils';
|
||||
import { ILocomotive, IVehicleData, Vehicle } from '../types';
|
||||
import { ILocomotive, Vehicle } from '../types';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
@@ -75,8 +74,6 @@ export default defineComponent({
|
||||
'car-passenger': 'WAGON PASAŻERSKI',
|
||||
'car-cargo': 'WAGON TOWAROWY',
|
||||
} as { [key: string]: string },
|
||||
|
||||
carUsage: carUsage as { [key: string]: string },
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
{
|
||||
"Gor89": "wagon pasażerski",
|
||||
"Gor77": "wagon pasażerski",
|
||||
"Bau84": "wagon pasażerski",
|
||||
"612a": "wagon pasażerski",
|
||||
"504a": "wagon pasażerski",
|
||||
"304c": "wagon pasażerski",
|
||||
"159a": "wagon pasażerski",
|
||||
"158a": "wagon pasażerski",
|
||||
"154a": "wagon pasażerski",
|
||||
"120a": "wagon pasażerski",
|
||||
"113a": "wagon pasażerski",
|
||||
"112a": "wagon pasażerski",
|
||||
"111a": "wagon pasażerski",
|
||||
"110a": "wagon pasażerski",
|
||||
"101a": "wagon pasażerski",
|
||||
"102a": "wagon pasażerski",
|
||||
"203V": "kruszywo, kamień wapienny, odpady kopalniane",
|
||||
"208Kf": "drobnica, ładunki sypkie, ładunki sztukowe",
|
||||
"209c": "wagon techniczny",
|
||||
"29R": "produkty naftowe",
|
||||
"29R_PLPOL": "melasa",
|
||||
"304Ca": "pojazd specjalny",
|
||||
"401Ka": "drobnica, ładunki sypkie, ładunki sztukowe",
|
||||
"401Zb": "ładunki sypkie o dużej masie usypowej",
|
||||
"408S": "cement, wapno, popioły lotne, żużel",
|
||||
"412W": "drobnica, kruszywo, węgiel",
|
||||
"412Z": "kontenery",
|
||||
"413S": "węgiel, kreda, piasek",
|
||||
"424Z": "ładunki skupione, pojazdy, dłużyca",
|
||||
"426S": "drobnica",
|
||||
"429W": "towary masowe odporne na warunki atmosferyczne (węgiel, ruda)",
|
||||
"441V": "węgiel kamienny, żwir",
|
||||
"627Z": "kontenery"
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
{
|
||||
"passenger": {
|
||||
"PKP_IC": [],
|
||||
"PKP_PR": [],
|
||||
"PKP_ALL": []
|
||||
},
|
||||
"cargo": {
|
||||
"kontenery": ["627Z:all", "412Z:all"],
|
||||
"drobnica": ["426S:all", "208Kf:all", "401Ka:all"],
|
||||
"węgiel": ["412W:coal_01", "413S:coal_Fas", "429W:coal_01"],
|
||||
"ruda": ["412W:ore_01", "401Zb:ore_35", "429W:ore_01"],
|
||||
"piasek": ["412W:sand_01", "412W:sand_02", "413S:sand_Fas", "401Zb:sand_30", "429W:sand_01", "429W:sand_02"],
|
||||
"kreda": ["413S:chalk_Fas"],
|
||||
"kamień": ["412W:stone_01", "412W:stone_50", "401Zb:stone_25", "429W:stone_01"],
|
||||
"złom": ["412W:scrap_01", "412W:scrap_02", "429W:scrap_01", "429W:scrap_02"],
|
||||
"paliwo": ["29R_CTLL:all", "29R_PKP:all"],
|
||||
"melasa": ["29R_PLPOL:all"],
|
||||
"żwir": ["441V"],
|
||||
"koła": ["424Z:wheels_01"],
|
||||
"drewno": ["424Z:woods_01", "424Z:woods_2"],
|
||||
"szyny": ["424Z:rails_01"],
|
||||
"kable": ["424Z:cables_01"],
|
||||
"cement": ["408S:all"],
|
||||
"kruszywo": ["203V"],
|
||||
"techniczne": ["209c", "304Ca"]
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,34 +0,0 @@
|
||||
[
|
||||
{ "type": "101a", "length": 25, "mass": 40, "cargo": ""},
|
||||
{ "type": "102a", "length": 25, "mass": 40, "cargo": ""},
|
||||
{ "type": "111a", "length": 25, "mass": 40, "cargo": ""},
|
||||
{ "type": "110a", "length": 25, "mass": 45, "cargo": ""},
|
||||
{ "type": "112a", "length": 25, "mass": 40, "cargo": ""},
|
||||
{ "type": "113a", "length": 25, "mass": 40, "cargo": ""},
|
||||
{ "type": "120a", "length": 25, "mass": 45, "cargo": ""},
|
||||
{ "type": "154a", "length": 26, "mass": 55, "cargo": ""},
|
||||
{ "type": "158a", "length": 26, "mass": 50, "cargo": ""},
|
||||
{ "type": "159a", "length": 26, "mass": 50, "cargo": ""},
|
||||
{ "type": "203V", "length": 9, "mass": 12, "cargo": "stone_Fll:35"},
|
||||
{ "type": "208Kf", "length": 14, "mass": 15, "cargo": "mass_20:35;mass_30:45;mass_40:55"},
|
||||
{ "type": "209c", "length": 25, "mass": 43, "cargo": ""},
|
||||
{ "type": "29R", "length": 13, "mass": 23, "cargo": "mass_20:43;mass_30:53;mass_40:63"},
|
||||
{ "type": "304C", "length": 25, "mass": 43, "cargo": ""},
|
||||
{ "type": "304Ca", "length": 25, "mass": 43, "cargo": ""},
|
||||
{ "type": "401Ka", "length": 16, "mass": 23, "cargo": "mass_20:43;mass_30:53;mass_40:63"},
|
||||
{ "type": "401Zb", "length": 12, "mass": 20, "cargo": "stone_25:45;sand_30:50;ore_35:55"},
|
||||
{ "type": "408S", "length": 14, "mass": 24, "cargo": "mass_20:44;mass_30:54;mass_40:64"},
|
||||
{ "type": "412W", "length": 14, "mass": 20, "cargo": "coal_01:74;ore_01:55;sand_01:50;sand_02:45;scrap_01:65;scrap_02:65;stone_01:78;stone_50:75"},
|
||||
{ "type": "412Z", "length": 20, "mass": 22, "cargo": "sc_1a_01:47;sc_1a_02:47;sc_1a_03:47;sc_1a_04:47;sc_1a_05:47;sc_1c_01:56;sc_1c_02:56;sc_1c_03:56;sc_1c_04:56;sc_1c_05:56"},
|
||||
{ "type": "413S", "length": 14, "mass": 25, "cargo": "coal_Fas:69;sand_Fas:79;chalk_Fas:79"},
|
||||
{ "type": "424Z", "length": 20, "mass": 23, "cargo": "wheels_01:39;woods_01:33;woods_2:43;rails_01:53;cables_01:36"},
|
||||
{ "type": "426S", "length": 20, "mass": 29, "cargo": "mass_20:49;mass_30:59;mass_40:69"},
|
||||
{ "type": "429W", "length": 14, "mass": 20, "cargo": "coal_01:74;ore_01:55;sand_01:50;sand_02:45;scrap_01:65;scrap_02:65;stone_01:78;stone_50:75"},
|
||||
{ "type": "441V", "length": 13, "mass": 26, "cargo": ""},
|
||||
{ "type": "504a", "length": 25, "mass": 45, "cargo": ""},
|
||||
{ "type": "612a", "length": 25, "mass": 43, "cargo": ""},
|
||||
{ "type": "627Z", "length": 30, "mass": 29, "cargo": "sc_1a_01:79;sc_1a_02:79;sc_1a_03:79;sc_1a_04:79;sc_1a_05:79;sc_1c_01:97;sc_1c_02:97;sc_1c_03:97;sc_1c_04:97;sc_1c_05:97"},
|
||||
{ "type": "Bau84", "length": 26, "mass": 40, "cargo": ""},
|
||||
{ "type": "Gor77", "length": 69, "mass": 132,"cargo": ""},
|
||||
{ "type": "Gor89", "length": 27, "mass": 42, "cargo": ""}
|
||||
]
|
||||
+11
-5
@@ -1,7 +1,14 @@
|
||||
import { IStore } from './types';
|
||||
import { defineStore } from 'pinia';
|
||||
import { carDataList, chosenRealStock, isTrainPassenger, locoDataList, maxStockSpeed, totalLength, totalMass } from './utils/vehicleUtils';
|
||||
|
||||
import {
|
||||
carDataList,
|
||||
chosenRealStock,
|
||||
isTrainPassenger,
|
||||
locoDataList,
|
||||
maxStockSpeed,
|
||||
totalLength,
|
||||
totalMass,
|
||||
} from './utils/vehicleUtils';
|
||||
|
||||
export const useStore = defineStore({
|
||||
id: 'store',
|
||||
@@ -35,7 +42,7 @@ export const useStore = defineStore({
|
||||
isRandomizerCardOpen: false,
|
||||
isRealStockListCardOpen: false,
|
||||
|
||||
|
||||
stockData: undefined,
|
||||
} as IStore),
|
||||
|
||||
getters: {
|
||||
@@ -45,8 +52,7 @@ export const useStore = defineStore({
|
||||
totalLength: (state) => totalLength(state),
|
||||
maxStockSpeed: (state) => maxStockSpeed(state),
|
||||
isTrainPassenger: (state) => isTrainPassenger(state),
|
||||
chosenRealStock: (state) => chosenRealStock(state)
|
||||
chosenRealStock: (state) => chosenRealStock(state),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
+27
-3
@@ -28,10 +28,33 @@ export interface IStore {
|
||||
isRealStockListCardOpen: boolean;
|
||||
|
||||
stockSectionMode: 'stock-list' | 'stock-generator';
|
||||
stockData?: IStockData;
|
||||
}
|
||||
|
||||
export interface IVehicleData {
|
||||
[key: string]: (string | boolean)[][];
|
||||
export type TStockInfoKey = 'loco-e' | 'loco-s' | 'loco-ezt' | 'loco-szt' | 'car-passenger' | 'car-cargo';
|
||||
|
||||
export interface IStockProps {
|
||||
type: string;
|
||||
length: number;
|
||||
mass: number;
|
||||
cargo: string;
|
||||
}
|
||||
|
||||
export interface IStockData {
|
||||
generator: {
|
||||
passenger: [];
|
||||
cargo: {
|
||||
[key: string]: string[];
|
||||
};
|
||||
};
|
||||
|
||||
info: {
|
||||
[key in TStockInfoKey]: any[];
|
||||
};
|
||||
|
||||
props: IStockProps[];
|
||||
|
||||
usage: { [key: string]: string };
|
||||
}
|
||||
|
||||
export interface ILocomotive {
|
||||
@@ -83,4 +106,5 @@ export interface IStock {
|
||||
|
||||
export interface IReadyStockList {
|
||||
[key: string]: { stockString: string; type: string; number: string; name: string };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { EVehicleUseType } from '../enums/EVehicleUseType';
|
||||
import { ICarWagon, ILocomotive, IStore, IVehicleData } from '../types';
|
||||
|
||||
import vehicleDataJSON from '../data/vehicleData.json';
|
||||
import vehiclePropsJSON from '../data/vehicleProps.json';
|
||||
import { ICarWagon, ILocomotive, IStore, TStockInfoKey } from '../types';
|
||||
|
||||
// rodzaj: [tMaxPas, vMaxPas, tMaxTow, vMaxTow] | SM42: [tMax, vMax, ...]
|
||||
const maxAllowedSpeedTable = {
|
||||
@@ -39,10 +36,14 @@ export function isLocomotive(vehicle: ILocomotive | ICarWagon): vehicle is ILoco
|
||||
}
|
||||
|
||||
export function locoDataList(state: IStore) {
|
||||
return Object.keys(vehicleDataJSON).reduce((acc, vehicleTypeKey) => {
|
||||
if (!state.stockData) return [];
|
||||
|
||||
const stockData = state.stockData;
|
||||
|
||||
return Object.keys(stockData.info).reduce((acc, vehicleTypeKey) => {
|
||||
if (!vehicleTypeKey.startsWith('loco')) return acc;
|
||||
|
||||
const locoVehiclesData = (vehicleDataJSON as IVehicleData)[vehicleTypeKey];
|
||||
const locoVehiclesData = stockData.info[vehicleTypeKey as TStockInfoKey];
|
||||
|
||||
locoVehiclesData.forEach((loco) => {
|
||||
if (state.showSupporter && !loco[4]) return;
|
||||
@@ -125,15 +126,19 @@ export function locoDataList(state: IStore) {
|
||||
}
|
||||
|
||||
export function carDataList(state: IStore) {
|
||||
return Object.keys(vehicleDataJSON).reduce((acc, vehicleTypeKey) => {
|
||||
if (!state.stockData) return [];
|
||||
|
||||
const stockData = state.stockData;
|
||||
|
||||
return Object.keys(stockData.info).reduce((acc, vehicleTypeKey) => {
|
||||
if (!vehicleTypeKey.startsWith('car')) return acc;
|
||||
|
||||
const carVehiclesData = (vehicleDataJSON as IVehicleData)[vehicleTypeKey];
|
||||
const carVehiclesData = (stockData.info)[vehicleTypeKey as TStockInfoKey];
|
||||
|
||||
carVehiclesData.forEach((car) => {
|
||||
if (state.showSupporter && !car[3]) return;
|
||||
|
||||
const carPropsData = vehiclePropsJSON.find((v) => car[0].toString().includes(v.type));
|
||||
const carPropsData = stockData.props.find((v) => car[0].toString().includes(v.type));
|
||||
|
||||
acc.push({
|
||||
useType: vehicleTypeKey as 'car-passenger' | 'car-cargo',
|
||||
@@ -322,3 +327,5 @@ export function chosenRealStock(state: IStore) {
|
||||
// }),
|
||||
// };
|
||||
|
||||
|
||||
|
||||
|
||||
+4
-23
@@ -1,7 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import { defineConfig } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
|
||||
import { VitePWA } from "vite-plugin-pwa";
|
||||
import { VitePWA } from 'vite-plugin-pwa';
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
@@ -13,22 +13,7 @@ export default defineConfig({
|
||||
globPatterns: ['**/*.{js,css,html,png,svg,img}'],
|
||||
runtimeCaching: [
|
||||
{
|
||||
urlPattern: new RegExp(`^https://wiki.td2.info.pl/images/thumb\/.*`),
|
||||
handler: 'NetworkFirst',
|
||||
options: {
|
||||
cacheName: 'td2-images-cache',
|
||||
expiration: {
|
||||
maxEntries: 400,
|
||||
maxAgeSeconds: 60 * 60 * 24 * 14, // <== 14 days
|
||||
},
|
||||
cacheableResponse: {
|
||||
statuses: [0, 200],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
urlPattern: new RegExp(`^https://spythere.github.io/api/readyStock.json`),
|
||||
urlPattern: new RegExp(`^https://spythere.github.io/api\/.*`),
|
||||
handler: 'NetworkFirst',
|
||||
options: {
|
||||
cacheName: 'github-api-cache',
|
||||
@@ -50,7 +35,3 @@ export default defineConfig({
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user