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