mirror of
https://github.com/Spythere/pojazdownik.git
synced 2026-05-03 05:18:10 +00:00
chorse: changed api data to stored locally
This commit is contained in:
@@ -8,8 +8,8 @@
|
|||||||
</template>
|
</template>
|
||||||
</i18n-t>
|
</i18n-t>
|
||||||
|
|
||||||
<div class="text--grayed" v-if="store.vehiclesAPIData">
|
<div class="text--grayed" v-if="store.vehiclesData">
|
||||||
{{ $t('footer.version-check', { version: store.vehiclesAPIData.simulatorVersion }) }}
|
{{ $t('footer.version-check', { version: store.vehiclesData.simulatorVersion }) }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -149,9 +149,9 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
computedCargoData() {
|
computedCargoData() {
|
||||||
if (!this.store.vehiclesAPIData?.generator.cargo) return [];
|
if (!this.store.vehiclesData?.generator.cargo) return [];
|
||||||
|
|
||||||
const cargoGeneratorData = this.store.vehiclesAPIData.generator.cargo;
|
const cargoGeneratorData = this.store.vehiclesData.generator.cargo;
|
||||||
|
|
||||||
return Object.keys(cargoGeneratorData)
|
return Object.keys(cargoGeneratorData)
|
||||||
.sort((v1, v2) => this.$t(`cargo.${v1}`).localeCompare(this.$t(`cargo.${v2}`)))
|
.sort((v1, v2) => this.$t(`cargo.${v1}`).localeCompare(this.$t(`cargo.${v2}`)))
|
||||||
@@ -195,7 +195,7 @@ export default defineComponent({
|
|||||||
generateStock(empty = false) {
|
generateStock(empty = false) {
|
||||||
const generatedChosenStockList = this.chosenCargoTypes.reduce(
|
const generatedChosenStockList = this.chosenCargoTypes.reduce(
|
||||||
(acc, type) => {
|
(acc, type) => {
|
||||||
this.store.vehiclesAPIData?.generator.cargo[type]
|
this.store.vehiclesData?.generator.cargo[type]
|
||||||
.filter((c) => !this.excludedCarTypes.includes(c.split(':')[0]))
|
.filter((c) => !this.excludedCarTypes.includes(c.split(':')[0]))
|
||||||
.forEach((c) => {
|
.forEach((c) => {
|
||||||
const [type, cargoType] = c.split(':');
|
const [type, cargoType] = c.split(':');
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+20
-29
@@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
IVehiclesAPI,
|
IVehiclesData,
|
||||||
ICarWagon,
|
ICarWagon,
|
||||||
ILocomotive,
|
ILocomotive,
|
||||||
ICargo,
|
ICargo,
|
||||||
@@ -19,9 +19,11 @@ import {
|
|||||||
totalLength,
|
totalLength,
|
||||||
totalWeight,
|
totalWeight,
|
||||||
} from './utils/vehicleUtils';
|
} from './utils/vehicleUtils';
|
||||||
import http from './http';
|
|
||||||
import i18n from './i18n-setup';
|
import i18n from './i18n-setup';
|
||||||
|
|
||||||
|
import vehiclesData from './data/vehiclesData.json';
|
||||||
|
|
||||||
export const useStore = defineStore({
|
export const useStore = defineStore({
|
||||||
id: 'store',
|
id: 'store',
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -52,17 +54,17 @@ export const useStore = defineStore({
|
|||||||
isRandomizerCardOpen: false,
|
isRandomizerCardOpen: false,
|
||||||
isRealStockListCardOpen: false,
|
isRealStockListCardOpen: false,
|
||||||
|
|
||||||
vehiclesAPIData: undefined as IVehiclesAPI | undefined,
|
vehiclesData: undefined as IVehiclesData | undefined,
|
||||||
|
|
||||||
lastFocusedElement: null as HTMLElement | null,
|
lastFocusedElement: null as HTMLElement | null,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
locoDataList: (state) => locoDataList(state.vehiclesAPIData),
|
locoDataList: (state) => locoDataList(state.vehiclesData),
|
||||||
carDataList: (state) => carDataList(state.vehiclesAPIData),
|
carDataList: (state) => carDataList(state.vehiclesData),
|
||||||
vehicleDataList: (state) => [
|
vehicleDataList: (state) => [
|
||||||
...locoDataList(state.vehiclesAPIData),
|
...locoDataList(state.vehiclesData),
|
||||||
...carDataList(state.vehiclesAPIData),
|
...carDataList(state.vehiclesData),
|
||||||
],
|
],
|
||||||
totalWeight: (state) => totalWeight(state.stockList),
|
totalWeight: (state) => totalWeight(state.stockList),
|
||||||
totalLength: (state) => totalLength(state.stockList),
|
totalLength: (state) => totalLength(state.stockList),
|
||||||
@@ -71,16 +73,16 @@ export const useStore = defineStore({
|
|||||||
acceptableWeight: (state) => acceptableWeight(state.stockList),
|
acceptableWeight: (state) => acceptableWeight(state.stockList),
|
||||||
|
|
||||||
realCompositionList: (state) => {
|
realCompositionList: (state) => {
|
||||||
if (!state.vehiclesAPIData) return [];
|
if (!state.vehiclesData) return [];
|
||||||
|
|
||||||
return Object.keys(state.vehiclesAPIData.realCompositions).reduce<IRealComposition[]>(
|
return Object.keys(state.vehiclesData.realCompositions).reduce<IRealComposition[]>(
|
||||||
(acc, key) => {
|
(acc, key) => {
|
||||||
const [type, number, ...name] = key.split(' ');
|
const [type, number, ...name] = key.split(' ');
|
||||||
|
|
||||||
const obj = {
|
const obj = {
|
||||||
number: number.replace(/_/g, '/'),
|
number: number.replace(/_/g, '/'),
|
||||||
name: name.join(' '),
|
name: name.join(' '),
|
||||||
stockString: state.vehiclesAPIData!.realCompositions[key],
|
stockString: state.vehiclesData!.realCompositions[key],
|
||||||
type,
|
type,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -102,9 +104,8 @@ export const useStore = defineStore({
|
|||||||
const headingLoco = state.stockList[0];
|
const headingLoco = state.stockList[0];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
state.vehiclesAPIData?.vehicleProps.find(
|
state.vehiclesData?.vehicleProps.find((stock) => stock.type == headingLoco.constructionType)
|
||||||
(stock) => stock.type == headingLoco.constructionType
|
?.coldStart ?? false
|
||||||
)?.coldStart ?? false
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -115,33 +116,23 @@ export const useStore = defineStore({
|
|||||||
const headingLoco = state.stockList[0];
|
const headingLoco = state.stockList[0];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
state.vehiclesAPIData?.vehicleProps.find(
|
state.vehiclesData?.vehicleProps.find((stock) => stock.type == headingLoco.constructionType)
|
||||||
(stock) => stock.type == headingLoco.constructionType
|
?.doubleManned ?? false
|
||||||
)?.doubleManned ?? false
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
async fetchVehiclesAPI() {
|
|
||||||
try {
|
|
||||||
const vehiclesData = (await http.get<IVehiclesAPI>('/vehiclesData')).data;
|
|
||||||
this.vehiclesAPIData = vehiclesData;
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async setupAPIData() {
|
async setupAPIData() {
|
||||||
await this.fetchVehiclesAPI();
|
this.vehiclesData = vehiclesData;
|
||||||
this.mergeBackendTranslations();
|
this.mergeBackendTranslations();
|
||||||
},
|
},
|
||||||
|
|
||||||
async mergeBackendTranslations() {
|
async mergeBackendTranslations() {
|
||||||
if (!this.vehiclesAPIData) return;
|
if (!this.vehiclesData) return;
|
||||||
|
|
||||||
i18n.global.mergeLocaleMessage('pl', this.vehiclesAPIData.vehicleLocales.pl);
|
i18n.global.mergeLocaleMessage('pl', this.vehiclesData.vehicleLocales.pl);
|
||||||
i18n.global.mergeLocaleMessage('en', this.vehiclesAPIData.vehicleLocales.en);
|
i18n.global.mergeLocaleMessage('en', this.vehiclesData.vehicleLocales.en);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleRouting() {
|
handleRouting() {
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ export interface ICargo {
|
|||||||
weight: number;
|
weight: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IVehiclesAPI {
|
export interface IVehiclesData {
|
||||||
simulatorVersion: string;
|
simulatorVersion: string;
|
||||||
|
|
||||||
generator: {
|
generator: {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
ICarWagon,
|
ICarWagon,
|
||||||
ILocomotive,
|
ILocomotive,
|
||||||
IStock,
|
IStock,
|
||||||
IVehiclesAPI,
|
IVehiclesData,
|
||||||
LocoGroupType,
|
LocoGroupType,
|
||||||
WagonGroupType,
|
WagonGroupType,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
@@ -17,7 +17,7 @@ export function isTractionUnit(vehicle: ILocomotive | ICarWagon): vehicle is ILo
|
|||||||
return (vehicle as ILocomotive).cabinType !== undefined;
|
return (vehicle as ILocomotive).cabinType !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function locoDataList(vehiclesData: IVehiclesAPI | undefined) {
|
export function locoDataList(vehiclesData: IVehiclesData | undefined) {
|
||||||
if (!vehiclesData) return [];
|
if (!vehiclesData) return [];
|
||||||
|
|
||||||
return vehiclesData.vehicleList.reduce<ILocomotive[]>((acc, vehicleInfoArray) => {
|
return vehiclesData.vehicleList.reduce<ILocomotive[]>((acc, vehicleInfoArray) => {
|
||||||
@@ -53,7 +53,7 @@ export function locoDataList(vehiclesData: IVehiclesAPI | undefined) {
|
|||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function carDataList(vehiclesData: IVehiclesAPI | undefined) {
|
export function carDataList(vehiclesData: IVehiclesData | undefined) {
|
||||||
if (!vehiclesData) return [];
|
if (!vehiclesData) return [];
|
||||||
|
|
||||||
console.log(vehiclesData);
|
console.log(vehiclesData);
|
||||||
|
|||||||
Reference in New Issue
Block a user