chore: minor stock generator improvements; code cleanup

This commit is contained in:
2025-03-09 16:20:58 +01:00
parent 862aebb158
commit 1eb5f3de9e
6 changed files with 56 additions and 47 deletions
+14
View File
@@ -23,6 +23,20 @@ export default defineComponent({
this.store.setupAPIData(); this.store.setupAPIData();
}, },
computed: {
currentStockString() {
return this.store.stockString;
},
},
watch: {
currentStockString(val: string) {
if (val != this.store.chosenStorageStockString) {
this.store.chosenStorageStockName = '';
}
},
},
methods: { methods: {
loadStockDataFromStorage() { loadStockDataFromStorage() {
const savedData = localStorage.getItem('savedStockData'); const savedData = localStorage.getItem('savedStockData');
+1 -28
View File
@@ -22,12 +22,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; 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 StockActions from './stock-list/StockActions.vue';
import StockSpecs from './stock-list/StockSpecs.vue'; import StockSpecs from './stock-list/StockSpecs.vue';
import StockSpawnSettings from './stock-list/StockSpawnSettings.vue'; import StockSpawnSettings from './stock-list/StockSpawnSettings.vue';
@@ -36,6 +30,7 @@ import StockList from './stock-list/StockList.vue';
export default defineComponent({ export default defineComponent({
name: 'stock-list', name: 'stock-list',
components: { components: {
StockActions, StockActions,
StockSpecs, StockSpecs,
@@ -43,28 +38,6 @@ export default defineComponent({
StockWarnings, StockWarnings,
StockList, 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> </script>
+3
View File
@@ -110,6 +110,7 @@ export default defineComponent({
delete this.store.storageStockData[stockName]; delete this.store.storageStockData[stockName];
this.store.chosenStorageStockName = ''; this.store.chosenStorageStockName = '';
this.store.chosenStorageStockString = '';
try { try {
localStorage.setItem('savedStockData', JSON.stringify(this.store.storageStockData)); localStorage.setItem('savedStockData', JSON.stringify(this.store.storageStockData));
@@ -122,6 +123,8 @@ export default defineComponent({
try { try {
this.loadStockFromString(this.store.storageStockData[stockName].stockString); this.loadStockFromString(this.store.storageStockData[stockName].stockString);
this.store.chosenStorageStockName = stockName; this.store.chosenStorageStockName = stockName;
this.store.chosenStorageStockString = this.store.storageStockData[stockName].stockString;
this.$router.push('/'); this.$router.push('/');
} catch (error) { } catch (error) {
console.log(error); console.log(error);
@@ -247,8 +247,6 @@ export default defineComponent({
if (!entryName) return; if (!entryName) return;
let updatedAt: number | undefined = undefined;
if (entryName in this.store.storageStockData) { if (entryName in this.store.storageStockData) {
const overwriteDataConfirm = confirm(this.$t('stocklist.prompt-bookmark-overwrite')); const overwriteDataConfirm = confirm(this.$t('stocklist.prompt-bookmark-overwrite'));
@@ -267,6 +265,7 @@ export default defineComponent({
try { try {
localStorage.setItem('savedStockData', JSON.stringify(this.store.storageStockData)); localStorage.setItem('savedStockData', JSON.stringify(this.store.storageStockData));
this.store.chosenStorageStockName = entryName; this.store.chosenStorageStockName = entryName;
this.store.chosenStorageStockString = this.store.stockString;
} catch (error) { } catch (error) {
console.error('Wystąpił błąd podczas zapisywania składu do localStorage!', error); console.error('Wystąpił błąd podczas zapisywania składu do localStorage!', error);
} }
+32 -14
View File
@@ -1,20 +1,25 @@
<template> <template>
<div class="stock_specs"> <div class="stock_specs">
<b class="real-stock-info" v-if="store.chosenStorageStockName"> <div v-if="store.chosenStorageStockName || chosenRealComposition">
<span class="text--accent"> <b class="bookmarked-stock-info" v-if="store.chosenStorageStockName">
<BookmarkIcon /> <span
{{ store.chosenStorageStockName }} class="text--accent"
</span> :title="store.chosenStorageStockName.length > 41 ? store.chosenStorageStockName : ''"
| >
</b> <BookmarkIcon />
{{ store.chosenStorageStockName.slice(0, 40) }}
{{ store.chosenStorageStockName.length > 41 ? '...' : '' }}
</span>
|
</b>
<!-- <b class="real-stock-info" v-if="store.chosenRealComposition"> <b class="real-stock-info" v-if="chosenRealComposition">
<span class="text--accent"> <span class="text--accent">
<img :src="getIconURL(chosenRealComposition.type)" :alt="chosenRealComposition.type" /> <img :src="getIconURL(chosenRealComposition.type)" :alt="chosenRealComposition.type" />
{{ chosenRealComposition.number }} {{ chosenRealComposition.name }} {{ chosenRealComposition.number }} {{ chosenRealComposition.name }}
</span> </span>
| </b>
</b> --> </div>
<span> <span>
{{ $t('stocklist.mass') }} {{ $t('stocklist.mass') }}
@@ -36,18 +41,31 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { useStore } from '../../../store'; import { useStore } from '../../../store';
import imageMixin from '../../../mixins/imageMixin'; import imageMixin from '../../../mixins/imageMixin';
import { BookmarkIcon } from '@heroicons/vue/20/solid';
export default defineComponent({ export default defineComponent({
components: { BookmarkIcon },
mixins: [imageMixin], mixins: [imageMixin],
data: () => ({ data: () => ({
store: useStore(), 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> </script>
<style scoped> <style scoped>
.bookmarked-stock-info,
.real-stock-info { .real-stock-info {
svg,
img { img {
height: 1.3ch; height: 1.3ch;
} }
+5 -3
View File
@@ -62,6 +62,7 @@ export const useStore = defineStore({
storageStockData: {} as Record<string, StorageStockEntry>, storageStockData: {} as Record<string, StorageStockEntry>,
chosenStorageStockName: '', chosenStorageStockName: '',
chosenStorageStockString: '',
compatibleSimulatorVersion: '2024.3.1', compatibleSimulatorVersion: '2024.3.1',
}), }),
@@ -85,8 +86,9 @@ export const useStore = defineStore({
stockString: (state) => { stockString: (state) => {
if (state.stockList.length == 0) return ''; if (state.stockList.length == 0) return '';
const coldStartActive = stockSupportsColdStart(state.stockList); const coldStartActive = state.isColdStart && stockSupportsColdStart(state.stockList);
const doubleManningActive = stockSupportsDoubleManning(state.stockList); const doubleManningActive =
state.isDoubleManned && stockSupportsDoubleManning(state.stockList);
return state.stockList return state.stockList
.map((stock, i) => { .map((stock, i) => {
@@ -95,7 +97,7 @@ export const useStore = defineStore({
? stock.vehicleRef.type ? stock.vehicleRef.type
: `${stock.vehicleRef.type}:${stock.cargo.id}`; : `${stock.vehicleRef.type}:${stock.cargo.id}`;
if (i == 0) if (i == 0 && (coldStartActive || doubleManningActive))
return `${stockTypeStr},${coldStartActive ? 'c' : ''}${doubleManningActive ? 'd' : ''}`; return `${stockTypeStr},${coldStartActive ? 'c' : ''}${doubleManningActive ? 'd' : ''}`;
return stockTypeStr; return stockTypeStr;