diff --git a/src/components/tabs/stock-list/StockActions.vue b/src/components/tabs/stock-list/StockActions.vue index c21375d..c04123b 100644 --- a/src/components/tabs/stock-list/StockActions.vue +++ b/src/components/tabs/stock-list/StockActions.vue @@ -110,7 +110,7 @@ import { isTractionUnit } from '../../../utils/vehicleUtils'; import stockMixin from '../../../mixins/stockMixin'; import { useStockListUtils } from '../../../utils/stockListUtils'; -import { getCurrentStockFileName } from '../../../composables/file'; +import { getCurrentStockFileName, getStockStringOutput } from '../../../composables/file'; import { Bookmark, @@ -166,7 +166,7 @@ export default defineComponent({ methods: { copyToClipboard() { - navigator.clipboard.writeText(this.store.stockString); + navigator.clipboard.writeText(getStockStringOutput()); setTimeout(() => { alert(this.$t('stocklist.alert-copied')); @@ -224,7 +224,7 @@ export default defineComponent({ if (!fileName) return; - const blob = new Blob([this.store.stockString]); + const blob = new Blob([getStockStringOutput()]); const file = fileName + '.con'; var e = document.createEvent('MouseEvents'), diff --git a/src/composables/file.ts b/src/composables/file.ts index 75a5e09..f5fd35c 100644 --- a/src/composables/file.ts +++ b/src/composables/file.ts @@ -1,4 +1,5 @@ import { useStore } from '../store'; +import { additionalCargoTypes } from '../utils/vehicleUtils'; export function getCurrentStockFileName() { const store = useStore(); @@ -23,3 +24,27 @@ export function getCurrentStockFileName() { return fileName; } + +export function getStockStringOutput() { + const store = useStore(); + + const stockEntries = store.stockString.split(';'); + + const parsedEntries = store.stockList.map((stockVehicle, i) => { + if (stockVehicle.cargo && /412Z|627Z/.test(stockVehicle.vehicleRef.constructionType)) { + const additionalCargo = additionalCargoTypes.find( + (c) => c.groupType == stockVehicle.vehicleRef.constructionType && c.id == stockVehicle.cargo!.id + ); + + if (additionalCargo) { + let cargoString = additionalCargo.cargoStringVariations[Math.floor(Math.random() * additionalCargo.cargoStringVariations.length)]; + + return stockEntries[i].replace(stockVehicle.cargo.id, cargoString); + } + } + + return stockEntries[i]; + }); + + return parsedEntries.join(';'); +} diff --git a/src/mixins/stockMixin.ts b/src/mixins/stockMixin.ts index 01dad46..b8c061e 100644 --- a/src/mixins/stockMixin.ts +++ b/src/mixins/stockMixin.ts @@ -1,7 +1,7 @@ import { defineComponent } from 'vue'; import { useStore } from '../store'; import { ICarWagon, ILocomotive, IStock, ICargo, IVehicle } from '../types/common.types'; -import { isTractionUnit } from '../utils/vehicleUtils'; +import { additionalCargoTypes, isTractionUnit } from '../utils/vehicleUtils'; export default defineComponent({ setup() { @@ -28,11 +28,7 @@ export default defineComponent({ const stock = this.getStockObject(vehicle, cargo); - if ( - isTractionUnit(stock.vehicleRef) && - this.store.stockList.length > 0 && - !isTractionUnit(this.store.stockList[0].vehicleRef) - ) + if (isTractionUnit(stock.vehicleRef) && this.store.stockList.length > 0 && !isTractionUnit(this.store.stockList[0].vehicleRef)) this.store.stockList.unshift(stock); else this.store.stockList.push(stock); }, @@ -40,8 +36,7 @@ export default defineComponent({ addLocomotive(loco: ILocomotive) { const stockObj = this.getStockObject(loco); - if (this.store.stockList.length > 0 && !isTractionUnit(this.store.stockList[0].vehicleRef)) - this.store.stockList.unshift(stockObj); + if (this.store.stockList.length > 0 && !isTractionUnit(this.store.stockList[0].vehicleRef)) this.store.stockList.unshift(stockObj); else this.store.stockList.push(stockObj); }, @@ -80,10 +75,22 @@ export default defineComponent({ this.store.isDoubleManned = spawnProps.includes('d'); } } else { - const [carType, cargo] = type.split(':'); + const [carType, ...cargo] = type.split(':'); vehicle = this.store.carDataList.find((car) => car.type == carType) || null; - if (cargo) vehicleCargo = vehicle?.cargoTypes.find((c) => c.id == cargo) || null; + if (vehicle && cargo.length > 0) { + if (/412Z|627Z/.test(vehicle.constructionType)) { + const additionalCargo = additionalCargoTypes.find( + (c) => c.groupType == vehicle!.constructionType && c.cargoStringVariations.includes(cargo.join(':')) + ); + + if (additionalCargo) { + cargo[0] = additionalCargo.id; + } + } + + vehicleCargo = vehicle?.cargoTypes.find((c) => c.id == cargo[0]) || null; + } } if (!vehicle && type) { diff --git a/src/store.ts b/src/store.ts index 2cd98a9..95b81ce 100644 --- a/src/store.ts +++ b/src/store.ts @@ -93,8 +93,6 @@ export const useStore = defineStore('store', { return state.stockList .map((stock, i) => { - // let cargoString = ''; - let stockTypeStr = isTractionUnit(stock.vehicleRef) || !stock.cargo ? stock.vehicleRef.type : `${stock.vehicleRef.type}:${stock.cargo.id}`; if (i == 0 && (coldStartActive || doubleManningActive)) diff --git a/src/utils/vehicleUtils.ts b/src/utils/vehicleUtils.ts index 305bc2c..23f9098 100644 --- a/src/utils/vehicleUtils.ts +++ b/src/utils/vehicleUtils.ts @@ -1,6 +1,56 @@ import { ICarWagon, ILocomotive, IStock, IVehicleData, LocoGroupType, WagonGroupType } from '../types/common.types'; import { MassLimitLocoType, calculateMassLimit, calculateSpeedLimit } from './vehicleLimitsUtils'; +export const additionalCargoTypes = [ + { + groupType: '627Z', + id: '627Z_mix1_sctc_loaded', + weight: 96500, + cargoStringVariations: [ + 'sc_20:tc_20_loaded:tc_20_loaded:tc_20_loaded', + 'tc_20_loaded:sc_20:tc_20_loaded:tc_20_loaded', + 'tc_20_loaded:tc_20_loaded:sc_20:tc_20_loaded', + 'tc_20_loaded:tc_20_loaded:tc_20_loaded:sc_20', + ], + }, + { + groupType: '627Z', + id: '627Z_mix2_sctc_loaded', + weight: 87000, + cargoStringVariations: [ + 'sc_20:tc_20_loaded:tc_20_loaded:sc_20', + 'sc_20:tc_20_loaded:sc_20:tc_20_loaded', + 'sc_20:sc_20:tc_20_loaded:tc_20_loaded', + 'tc_20_loaded:tc_20_loaded:sc_20:sc_20', + 'tc_20_loaded:sc_20:tc_20_loaded:sc_20', + 'tc_20_loaded:sc_20:sc_20:tc_20_loaded', + ], + }, + { + groupType: '627Z', + id: '627Z_mix3_sctc_loaded', + weight: 77500, + cargoStringVariations: [ + 'sc_20:sc_20:sc_20:tc_20_loaded', + 'sc_20:sc_20:tc_20_loaded:sc_20', + 'sc_20:tc_20_loaded:sc_20:sc_20', + 'tc_20_loaded:sc_20:sc_20:sc_20', + ], + }, + { + groupType: '412Z', + id: '412Z_mix1_sctc_loaded', + weight: 43500, + cargoStringVariations: ['sc_20:tc_20_loaded', 'tc_20_loaded:sc_20'], + }, + { + groupType: '412Z', + id: '412Z_mix1_sctc_empty', + weight: 33970, + cargoStringVariations: ['sc_20:tc_20_empty:sc_20'], + }, +]; + export function isTractionUnit(vehicle: ILocomotive | ICarWagon): vehicle is ILocomotive { return (vehicle as ILocomotive).cabinType !== undefined; } @@ -42,12 +92,25 @@ export function carDataList(vehiclesData: IVehicleData[] | undefined) { return vehiclesData.reduce((acc, data) => { if (data.cabinName !== null) return acc; + const cargoTypes = data.group.cargoTypes || []; + + if (/412Z|627Z/.test(data.group.name)) { + cargoTypes.push( + ...additionalCargoTypes + .filter((c) => c.groupType == data.group.name) + .map((c) => ({ + id: c.id, + weight: c.weight, + })) + ); + } + acc.push({ group: data.type as WagonGroupType, type: data.name, constructionType: data.group.name, loadable: data.group.cargoTypes !== null && data.group.cargoTypes.length > 0, - cargoTypes: data.group?.cargoTypes ?? [], + cargoTypes, sponsorOnlyTimestamp: data.restrictions?.sponsorOnly ?? 0, teamOnly: data.restrictions?.teamOnly ?? false,