From ebf6567e88b61bba87eda1d84f6a9c060e0f8a5c Mon Sep 17 00:00:00 2001 From: Spythere Date: Sun, 19 Feb 2023 22:55:38 +0100 Subject: [PATCH] =?UTF-8?q?feature=20fix:=20akceptowalna=20masa=20sk=C5=82?= =?UTF-8?q?adu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/tabs/StockGeneratorTab.vue | 87 +++++++------ src/components/tabs/StockListTab.vue | 3 +- src/mixins/warningsMixin.ts | 27 +--- src/store.ts | 2 + src/utils/vehicleUtils.ts | 145 ++++------------------ 5 files changed, 77 insertions(+), 187 deletions(-) diff --git a/src/components/tabs/StockGeneratorTab.vue b/src/components/tabs/StockGeneratorTab.vue index 8bf1e27..f7de857 100644 --- a/src/components/tabs/StockGeneratorTab.vue +++ b/src/components/tabs/StockGeneratorTab.vue @@ -5,53 +5,61 @@
-

WŁAŚCIWOŚCI SKŁADU

+
+

WŁAŚCIWOŚCI SKŁADU

-
- + ⇐ Dodaj lokomotywę na pierwsze miejsce listy, aby uwzględnić ją przy losowaniu składu! - +
+ - + + + +
-

ŁADUNEK

-

Wybierz ładunki, którymi chcesz wypełnić dostępne wagony:

+
+

ŁADUNEK

+ Wybierz ładunki, którymi chcesz wypełnić dostępne wagony: +
-

WAGONY Z WYBRANYMI ŁADUNKAMI

+
+

WAGONY Z WYBRANYMI ŁADUNKAMI

-
- - Wybierz co najmniej jeden ładunek, aby zobaczyć wagony, które go posiadają! - +
+ + Wybierz co najmniej jeden ładunek, aby zobaczyć wagony, które go posiadają! + - - Wagony posiadające wybrane ładunki. Najedź na nazwę, aby zobaczyć podgląd wagonu. Kliknij, aby wyłączyć z - losowania (tylko podświetlone nazwy będą uwzględnione). - + + Wagony posiadające wybrane ładunki. Najedź na nazwę, aby zobaczyć podgląd wagonu. Kliknij, aby wyłączyć z + losowania (tylko podświetlone nazwy będą uwzględnione). + +
-
+
diff --git a/src/mixins/warningsMixin.ts b/src/mixins/warningsMixin.ts index 57cfc80..0515d62 100644 --- a/src/mixins/warningsMixin.ts +++ b/src/mixins/warningsMixin.ts @@ -18,32 +18,7 @@ export default defineComponent({ }, trainTooHeavy() { - const totalMass = this.store.totalMass; - const isTrainPassenger = this.store.isTrainPassenger; - const stockList = this.store.stockList; - - if (stockList.length == 0 || !stockList[0].isLoco) return false; - - const activeLocomotiveType = stockList[0].type; - - // Spalinowy SM - if (/^SM/.test(activeLocomotiveType) && totalMass > 2400) return true; - - // Elektryczne EU07 / EP07 / EP08 / ET41 - - // Pasażerski elektr. - if (isTrainPassenger) { - if (/^(EU|EP)/.test(activeLocomotiveType) && totalMass > 650) return true; - if (/^ET/.test(activeLocomotiveType) && totalMass > 700) return true; - - return false; - } - - // Towarowy / inny elektr. - if (/^EU/.test(activeLocomotiveType) && totalMass > 2000) return true; - if (/^ET/.test(activeLocomotiveType) && totalMass > 4000) return true; - - return false; + return this.store.acceptableMass && this.store.totalMass > this.store.acceptableMass; }, locoNotSuitable() { diff --git a/src/store.ts b/src/store.ts index 6d1c758..36d26e4 100644 --- a/src/store.ts +++ b/src/store.ts @@ -1,6 +1,7 @@ import { IStore } from './types'; import { defineStore } from 'pinia'; import { + acceptableMass, carDataList, chosenRealStock, isTrainPassenger, @@ -53,6 +54,7 @@ export const useStore = defineStore({ maxStockSpeed: (state) => maxStockSpeed(state), isTrainPassenger: (state) => isTrainPassenger(state), chosenRealStock: (state) => chosenRealStock(state), + acceptableMass: (state) => acceptableMass(state), }, }); diff --git a/src/utils/vehicleUtils.ts b/src/utils/vehicleUtils.ts index a3ff4fb..132cffd 100644 --- a/src/utils/vehicleUtils.ts +++ b/src/utils/vehicleUtils.ts @@ -111,6 +111,30 @@ export function maxStockSpeed(state: IStore) { return speedLimitByMass ? Math.min(stockSpeedLimit, speedLimitByMass) : stockSpeedLimit; } +export function acceptableMass(state: IStore) { + if (state.stockList.length == 0 || !state.stockList[0].isLoco) return 0; + const activeLocomotiveType = state.stockList[0].type; + + if (/^SM/.test(activeLocomotiveType)) return 2400; + + // Elektryczne EU07 / EP07 / EP08 / ET41 + + // Pasażerski elektr. + if (isTrainPassenger(state)) { + if (/^(EU|EP)/.test(activeLocomotiveType)) return 650; + if (/^ET/.test(activeLocomotiveType)) return 700; + + return 0; + } + + // Towarowy / inny elektr. + if (/^EU/.test(activeLocomotiveType)) return 2000; + if (/^ET/.test(activeLocomotiveType)) return 4000; + if (/^EP/.test(activeLocomotiveType)) return 0; + + return 0; +} + export function isTrainPassenger(state: IStore) { if (state.stockList.length == 0) return false; if (state.stockList.every((stock) => stock.isLoco)) return false; @@ -139,124 +163,3 @@ export function chosenRealStock(state: IStore) { return realStockObj; } -// export function maxAllowedSpeed(state: IStore) { -// const headLocoType = state.stockList[0]?.isLoco ? state.stockList[0].type : undefined; - -// if (!headLocoType) return 0; - -// const isPassenger = isTrainPassenger(state); -// const stockMass = totalMass(state); - -// // const maxSpeed = maxAllowedSpeedTable[headLocoType]; - -// // if() -// } - -// export function maxAllowedSpeed(state: IStore) { -// if (state.stockList.length < 1) return -1; -// if (!state.stockList[0].isLoco) return -1; - -// const headingLoco = state.stockList[0]; -// const isPassenger = isTrainPassenger(state); - -// if (headingLoco.type.startsWith('EU07')) { -// if (isPassenger && totalMass.value <= 650) return 125; -// if (!isPassenger && totalMass.value <= 2000) return 70; - -// return -1; -// } - -// if (headingLoco.type.startsWith('EP07')) { -// if (isPassenger && totalMass.value <= 650) return 125; -// if (!isPassenger) return -1; - -// return -1; -// } - -// if (headingLoco.type.startsWith('EP08')) { -// if (isPassenger && totalMass.value <= 650) return 140; -// if (!isPassenger) return -1; - -// return -1; -// } - -// if (headingLoco.type.startsWith('ET41')) { -// if (isPassenger && totalMass.value <= 700) return 125; -// if (!isPassenger && totalMass.value <= 4000) return 70; - -// return -1; -// } - -// if (headingLoco.type.startsWith('SM42')) { -// if (totalMass.value <= 95) return 90; -// if (totalMass.value <= 200) return 80; -// if (totalMass.value <= 300) return 70; -// if (totalMass.value <= 450) return 60; -// if (totalMass.value <= 750) return 50; -// if (totalMass.value <= 1130) return 40; -// if (totalMass.value <= 1720) return 30; -// if (totalMass.value <= 2400) return 20; - -// return -1; -// } - -// return Store.stockList.reduce((acc, stock) => (stock.maxSpeed < acc || acc == 0 ? stock.maxSpeed : acc), 0); -// }); - -// export const warnings = { -// trainTooLong: computed(() => { -// if (isTrainPassenger.value && totalLength.value > 350) return true; -// if (!isTrainPassenger.value && totalLength.value > 650) return true; - -// return false; -// }), - -// locoNotSuitable: computed(() => { -// if ( -// !isTrainPassenger.value && -// Store.stockList.length > 1 && -// !Store.stockList.every((stock) => stock.isLoco) && -// Store.stockList.find((stock) => stock.isLoco && stock.type.startsWith('EP')) -// ) -// return true; - -// return false; -// }), - -// trainTooHeavy: computed(() => { -// if (Store.stockList.length == 0 || !Store.stockList[0].isLoco) return false; - -// const headingLoco = Store.stockList[0]; - -// if ( -// isTrainPassenger.value && -// (headingLoco.type.startsWith('EU') || headingLoco.type.startsWith('EP')) && -// totalMass.value > 650 -// ) -// return true; -// if (isTrainPassenger.value && headingLoco.type.startsWith('ET') && totalMass.value > 700) return true; - -// if (!isTrainPassenger.value && headingLoco.type.startsWith('EU') && totalMass.value > 2000) return true; -// if (!isTrainPassenger.value && headingLoco.type.startsWith('ET') && totalMass.value > 4000) return true; - -// if (headingLoco.type.startsWith('SM') && totalMass.value > 2400) return true; - -// return false; -// }), - -// tooManyLocos: computed(() => { -// if ( -// Store.stockList.reduce((acc, stock) => { -// if (!stock.isLoco) return acc; - -// acc += stock.count; - -// return acc; -// }, 0) > 2 -// ) -// return true; - -// return false; -// }), -// }; -