mirror of
https://github.com/Spythere/pojazdownik.git
synced 2026-05-03 11:45:34 +00:00
chore: minor stock generator improvements; code cleanup
This commit is contained in:
+14
@@ -23,6 +23,20 @@ export default defineComponent({
|
||||
this.store.setupAPIData();
|
||||
},
|
||||
|
||||
computed: {
|
||||
currentStockString() {
|
||||
return this.store.stockString;
|
||||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
currentStockString(val: string) {
|
||||
if (val != this.store.chosenStorageStockString) {
|
||||
this.store.chosenStorageStockName = '';
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
loadStockDataFromStorage() {
|
||||
const savedData = localStorage.getItem('savedStockData');
|
||||
|
||||
@@ -22,12 +22,6 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
import { useStore } from '../../store';
|
||||
|
||||
import imageMixin from '../../mixins/imageMixin';
|
||||
import stockPreviewMixin from '../../mixins/stockPreviewMixin';
|
||||
import stockMixin from '../../mixins/stockMixin';
|
||||
|
||||
import StockActions from './stock-list/StockActions.vue';
|
||||
import StockSpecs from './stock-list/StockSpecs.vue';
|
||||
import StockSpawnSettings from './stock-list/StockSpawnSettings.vue';
|
||||
@@ -36,6 +30,7 @@ import StockList from './stock-list/StockList.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'stock-list',
|
||||
|
||||
components: {
|
||||
StockActions,
|
||||
StockSpecs,
|
||||
@@ -43,28 +38,6 @@ export default defineComponent({
|
||||
StockWarnings,
|
||||
StockList,
|
||||
},
|
||||
|
||||
mixins: [imageMixin, stockMixin, stockPreviewMixin],
|
||||
|
||||
setup() {
|
||||
const store = useStore();
|
||||
|
||||
return {
|
||||
store,
|
||||
};
|
||||
},
|
||||
|
||||
data: () => ({}),
|
||||
|
||||
// computed: {
|
||||
// chosenStockVehicle() {
|
||||
// return this.store.chosenStockListIndex == -1
|
||||
// ? undefined
|
||||
// : this.store.stockList[this.store.chosenStockListIndex];
|
||||
// },
|
||||
// },
|
||||
|
||||
methods: {},
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -110,6 +110,7 @@ export default defineComponent({
|
||||
|
||||
delete this.store.storageStockData[stockName];
|
||||
this.store.chosenStorageStockName = '';
|
||||
this.store.chosenStorageStockString = '';
|
||||
|
||||
try {
|
||||
localStorage.setItem('savedStockData', JSON.stringify(this.store.storageStockData));
|
||||
@@ -122,6 +123,8 @@ export default defineComponent({
|
||||
try {
|
||||
this.loadStockFromString(this.store.storageStockData[stockName].stockString);
|
||||
this.store.chosenStorageStockName = stockName;
|
||||
this.store.chosenStorageStockString = this.store.storageStockData[stockName].stockString;
|
||||
|
||||
this.$router.push('/');
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
@@ -247,8 +247,6 @@ export default defineComponent({
|
||||
|
||||
if (!entryName) return;
|
||||
|
||||
let updatedAt: number | undefined = undefined;
|
||||
|
||||
if (entryName in this.store.storageStockData) {
|
||||
const overwriteDataConfirm = confirm(this.$t('stocklist.prompt-bookmark-overwrite'));
|
||||
|
||||
@@ -267,6 +265,7 @@ export default defineComponent({
|
||||
try {
|
||||
localStorage.setItem('savedStockData', JSON.stringify(this.store.storageStockData));
|
||||
this.store.chosenStorageStockName = entryName;
|
||||
this.store.chosenStorageStockString = this.store.stockString;
|
||||
} catch (error) {
|
||||
console.error('Wystąpił błąd podczas zapisywania składu do localStorage!', error);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
<template>
|
||||
<div class="stock_specs">
|
||||
<b class="real-stock-info" v-if="store.chosenStorageStockName">
|
||||
<span class="text--accent">
|
||||
<BookmarkIcon />
|
||||
{{ store.chosenStorageStockName }}
|
||||
</span>
|
||||
|
|
||||
</b>
|
||||
<div v-if="store.chosenStorageStockName || chosenRealComposition">
|
||||
<b class="bookmarked-stock-info" v-if="store.chosenStorageStockName">
|
||||
<span
|
||||
class="text--accent"
|
||||
:title="store.chosenStorageStockName.length > 41 ? store.chosenStorageStockName : ''"
|
||||
>
|
||||
<BookmarkIcon />
|
||||
{{ store.chosenStorageStockName.slice(0, 40) }}
|
||||
{{ store.chosenStorageStockName.length > 41 ? '...' : '' }}
|
||||
</span>
|
||||
|
|
||||
</b>
|
||||
|
||||
<!-- <b class="real-stock-info" v-if="store.chosenRealComposition">
|
||||
<span class="text--accent">
|
||||
<img :src="getIconURL(chosenRealComposition.type)" :alt="chosenRealComposition.type" />
|
||||
{{ chosenRealComposition.number }} {{ chosenRealComposition.name }}
|
||||
</span>
|
||||
|
|
||||
</b> -->
|
||||
<b class="real-stock-info" v-if="chosenRealComposition">
|
||||
<span class="text--accent">
|
||||
<img :src="getIconURL(chosenRealComposition.type)" :alt="chosenRealComposition.type" />
|
||||
{{ chosenRealComposition.number }} {{ chosenRealComposition.name }}
|
||||
</span>
|
||||
</b>
|
||||
</div>
|
||||
|
||||
<span>
|
||||
{{ $t('stocklist.mass') }}
|
||||
@@ -36,18 +41,31 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { useStore } from '../../../store';
|
||||
import imageMixin from '../../../mixins/imageMixin';
|
||||
import { BookmarkIcon } from '@heroicons/vue/20/solid';
|
||||
|
||||
export default defineComponent({
|
||||
components: { BookmarkIcon },
|
||||
|
||||
mixins: [imageMixin],
|
||||
|
||||
data: () => ({
|
||||
store: useStore(),
|
||||
}),
|
||||
|
||||
computed: {
|
||||
chosenRealComposition() {
|
||||
const currentStockString = this.store.stockList.map((s) => s.vehicleRef.type).join(';');
|
||||
|
||||
return this.store.realCompositionList.find((rc) => rc.stockString == currentStockString);
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.bookmarked-stock-info,
|
||||
.real-stock-info {
|
||||
svg,
|
||||
img {
|
||||
height: 1.3ch;
|
||||
}
|
||||
|
||||
+5
-3
@@ -62,6 +62,7 @@ export const useStore = defineStore({
|
||||
|
||||
storageStockData: {} as Record<string, StorageStockEntry>,
|
||||
chosenStorageStockName: '',
|
||||
chosenStorageStockString: '',
|
||||
|
||||
compatibleSimulatorVersion: '2024.3.1',
|
||||
}),
|
||||
@@ -85,8 +86,9 @@ export const useStore = defineStore({
|
||||
stockString: (state) => {
|
||||
if (state.stockList.length == 0) return '';
|
||||
|
||||
const coldStartActive = stockSupportsColdStart(state.stockList);
|
||||
const doubleManningActive = stockSupportsDoubleManning(state.stockList);
|
||||
const coldStartActive = state.isColdStart && stockSupportsColdStart(state.stockList);
|
||||
const doubleManningActive =
|
||||
state.isDoubleManned && stockSupportsDoubleManning(state.stockList);
|
||||
|
||||
return state.stockList
|
||||
.map((stock, i) => {
|
||||
@@ -95,7 +97,7 @@ export const useStore = defineStore({
|
||||
? stock.vehicleRef.type
|
||||
: `${stock.vehicleRef.type}:${stock.cargo.id}`;
|
||||
|
||||
if (i == 0)
|
||||
if (i == 0 && (coldStartActive || doubleManningActive))
|
||||
return `${stockTypeStr},${coldStartActive ? 'c' : ''}${doubleManningActive ? 'd' : ''}`;
|
||||
|
||||
return stockTypeStr;
|
||||
|
||||
Reference in New Issue
Block a user