From bf8868a243b225b9e585698944ee257c5e2f9688 Mon Sep 17 00:00:00 2001 From: Spythere Date: Tue, 8 Nov 2022 16:47:00 +0100 Subject: [PATCH] =?UTF-8?q?Generator=20sk=C5=82ad=C3=B3w=20towarowych=20(w?= =?UTF-8?q?ip)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/StockGeneratorTab.vue | 120 ++++++++++++++++++++++++--- src/components/StockSection.vue | 6 +- src/data/generatorData.json | 2 +- src/styles/global.scss | 2 +- 4 files changed, 114 insertions(+), 16 deletions(-) diff --git a/src/components/StockGeneratorTab.vue b/src/components/StockGeneratorTab.vue index 76ae638..fb6effc 100644 --- a/src/components/StockGeneratorTab.vue +++ b/src/components/StockGeneratorTab.vue @@ -1,7 +1,8 @@ @@ -63,6 +82,8 @@ import { defineComponent } from 'vue'; import { useStore } from '../store'; import generatorData from '../data/generatorData.json'; +import stockMixin from '../mixins/stockMixin'; +import { ICargo, ICarWagon } from '../types'; export default defineComponent({ name: 'stock-generator', @@ -73,6 +94,8 @@ export default defineComponent({ }; }, + mixins: [stockMixin], + data() { return { generatorData, @@ -82,6 +105,10 @@ export default defineComponent({ chosenCargoTypes: [] as string[], previewTimeout: -1, + + maxMass: 3000, + maxLength: 650, + maxCarCount: 50, }; }, @@ -104,6 +131,51 @@ export default defineComponent({ window.clearTimeout(this.previewTimeout); }, + resetChosenCargo() { + this.chosenCargoTypes.length = 0; + this.chosenCarTypes.length = 0; + this.excludedCarTypes.length = 0; + }, + + generateStock() { + const generatedChosenStockList = this.chosenCargoTypes.reduce((acc, type) => { + this.generatorData.cargo[type as keyof typeof this.generatorData.cargo] + .filter((c) => !this.excludedCarTypes.includes(c.split(':')[0])) + .forEach((c) => { + const [type, cargoType] = c.split(':'); + const carWagonObjs = this.store.carDataList.filter((cw) => cw.type.startsWith(type)); + const cargoObjs = [] as (ICargo | undefined)[]; + + if (cargoType == 'all') cargoObjs.push(...carWagonObjs[0]?.cargoList); + else if (cargoType) cargoObjs.push(carWagonObjs[0]?.cargoList.find((cargo) => cargo.id == cargoType)); + else cargoObjs.push(undefined); + + carWagonObjs.forEach((cw) => { + console.log(cw, cargoType); + + cargoObjs.forEach((cargoObj) => { + acc.push({ carWagon: cw, cargo: cargoObj }); + }); + }); + }); + + return acc; + }, [] as { carWagon: ICarWagon; cargo?: ICargo }[]); + + this.store.stockList.length = 0; + + new Array(this.maxCarCount).fill(0).forEach(() => { + const { carWagon, cargo } = generatedChosenStockList[~~(Math.random() * generatedChosenStockList.length)]; + + if (this.store.totalMass + (cargo?.totalMass || carWagon.mass) > this.maxMass) return; + if (this.store.totalLength + carWagon.length > this.maxLength) return; + + this.addCarWagon(carWagon, cargo); + }); + + this.store.stockSectionMode = 'stock-list'; + }, + previewCar(type: string) { const c = this.store.carDataList.find((c) => c.type.startsWith(type)) || null; @@ -113,8 +185,6 @@ export default defineComponent({ this.store.chosenCargo = null; if (c) this.store.chosenCarUseType = c?.useType; - - // this.store.chosenVehicle = this.store.chosenCar; }, toggleCargoChosen(cargoType: string, vehicles: string[]) { @@ -132,8 +202,6 @@ export default defineComponent({ vehicles.forEach((v) => { const [type] = v.split(':'); - // const cars = this.store.carDataList.filter((c) => c.constructionType == type); - this.chosenCarTypes.push(type); }); }, @@ -150,10 +218,26 @@ export default defineComponent({ @import '../styles/global.scss'; .stock_actions { - justify-content: flex-end; + align-items: center; + + h2 { + margin: 0; + color: white; + font-size: 1.35em; + } + + button { + margin-left: auto; + } } + +.stock-generator { + height: 100%; +} + .generator_content { margin-top: 1em; + height: 100%; } h2 { @@ -216,4 +300,18 @@ h2 { } } } + +.generator_actions { + display: grid; + gap: 0.5em; + grid-template-columns: repeat(3, 1fr); + margin-top: 2em; + + button { + background-color: #4b4b4b; + + padding: 0.5em; + font-weight: bold; + } +} diff --git a/src/components/StockSection.vue b/src/components/StockSection.vue index 4edb4dd..8f99ba2 100644 --- a/src/components/StockSection.vue +++ b/src/components/StockSection.vue @@ -1,8 +1,8 @@ diff --git a/src/data/generatorData.json b/src/data/generatorData.json index 49399c1..92c413f 100644 --- a/src/data/generatorData.json +++ b/src/data/generatorData.json @@ -21,7 +21,7 @@ "szyny": ["424Z:rails_01"], "kable": ["424Z:cables_01"], "cement": ["408S:all"], - "kruszywo": ["203V:all"], + "kruszywo": ["203V"], "techniczne": ["209c", "304Ca"] } } diff --git a/src/styles/global.scss b/src/styles/global.scss index abe14e3..41df96c 100644 --- a/src/styles/global.scss +++ b/src/styles/global.scss @@ -169,7 +169,7 @@ ul { } &--grayed { - color: gray; + color: #aaa; } }