code adaptation for API changes; tons changed to kilos

This commit is contained in:
2024-02-19 17:37:46 +01:00
parent 77cb64e25a
commit 83f5b07c7e
25 changed files with 365 additions and 234 deletions
+6 -6
View File
@@ -5,11 +5,11 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from "vue";
import { useStore } from './store'; import { useStore } from "./store";
import ImageFullscreenPreview from './components/utils/ImageFullscreenPreview.vue'; import ImageFullscreenPreview from "./components/utils/ImageFullscreenPreview.vue";
import AppContainerView from './views/AppContainerView.vue'; import AppContainerView from "./views/AppContainerView.vue";
import AppModals from './components/app/AppModals.vue'; import AppModals from "./components/app/AppModals.vue";
export default defineComponent({ export default defineComponent({
data() { data() {
@@ -26,7 +26,7 @@ export default defineComponent({
</script> </script>
<style lang="scss"> <style lang="scss">
@import './styles/global.scss'; @import "./styles/global.scss";
/* APP */ /* APP */
#app { #app {
+11 -8
View File
@@ -3,32 +3,35 @@
<i18n-t keypath="footer.disclaimer" tag="div" class="text--grayed"> <i18n-t keypath="footer.disclaimer" tag="div" class="text--grayed">
<template #tos> <template #tos>
<a style="color: #ccc" :href="$t('footer.tos-href')" target="_blank"> <a style="color: #ccc" :href="$t('footer.tos-href')" target="_blank">
{{ $t('footer.tos') }} {{ $t("footer.tos") }}
</a> </a>
</template> </template>
</i18n-t> </i18n-t>
<div class="text--grayed" v-if="store.stockData"> <div class="text--grayed" v-if="store.stockData">
{{ $t('footer.version-check', { version: store.stockData.version }) }} {{ $t("footer.version-check", { version: store.stockData.version }) }}
</div> </div>
<div> <div>
&copy; &copy;
<a href="https://td2.info.pl/profile/?u=20777" target="_blank">Spythere</a> <a href="https://td2.info.pl/profile/?u=20777" target="_blank"
{{ new Date().getUTCFullYear() }} | v{{ VERSION }}{{ !isOnProductionHost ? 'dev' : '' }} >Spythere</a
>
{{ new Date().getUTCFullYear() }} | v{{ VERSION
}}{{ !isOnProductionHost ? "dev" : "" }}
</div> </div>
</footer> </footer>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from "vue";
import packageInfo from '../../../package.json'; import packageInfo from "../../../package.json";
import { useStore } from '../../store'; import { useStore } from "../../store";
export default defineComponent({ export default defineComponent({
data() { data() {
return { return {
isOnProductionHost: location.hostname == 'pojazdownik-td2.web.app', isOnProductionHost: location.hostname == "pojazdownik-td2.web.app",
VERSION: packageInfo.version, VERSION: packageInfo.version,
store: useStore(), store: useStore(),
}; };
+6 -6
View File
@@ -8,11 +8,11 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from "vue";
import LogoSection from '../sections/LogoSection.vue'; import LogoSection from "../sections/LogoSection.vue";
import InputsSection from '../sections/InputsSection.vue'; import InputsSection from "../sections/InputsSection.vue";
import TrainImageSection from '../sections/TrainImageSection.vue'; import TrainImageSection from "../sections/TrainImageSection.vue";
import StockSection from '../sections/StockSection.vue'; import StockSection from "../sections/StockSection.vue";
export default defineComponent({ export default defineComponent({
components: { LogoSection, InputsSection, TrainImageSection, StockSection }, components: { LogoSection, InputsSection, TrainImageSection, StockSection },
@@ -20,7 +20,7 @@ export default defineComponent({
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import '../../styles/global.scss'; @import "../../styles/global.scss";
main { main {
display: grid; display: grid;
+2 -2
View File
@@ -27,7 +27,7 @@ div {
user-select: none; user-select: none;
&::before { &::before {
content: '\2716'; content: "\2716";
margin-right: 0.5em; margin-right: 0.5em;
color: #aaa; color: #aaa;
} }
@@ -51,7 +51,7 @@ input {
&::before { &::before {
color: palegreen; color: palegreen;
content: '\2714'; content: "\2714";
} }
} }
} }
+2 -2
View File
@@ -80,7 +80,7 @@
</option> </option>
<option :value="null" v-else>{{ $t('inputs.cargo-empty') }}</option> <option :value="null" v-else>{{ $t('inputs.cargo-empty') }}</option>
<option v-for="cargo in store.chosenCar?.cargoList" :value="cargo" :key="cargo.id"> <option v-for="cargo in store.chosenCar?.cargoTypes" :value="cargo" :key="cargo.id">
{{ cargo.id }} {{ cargo.id }}
</option> </option>
</select> </select>
@@ -216,7 +216,7 @@ export default defineComponent({
this.store.chosenVehicle = type == 'loco' ? this.store.chosenLoco : this.store.chosenCar; this.store.chosenVehicle = type == 'loco' ? this.store.chosenLoco : this.store.chosenCar;
this.store.chosenCargo = this.store.chosenCar?.cargoList.find((cargo) => cargo.id == this.store.chosenCargo?.id) || null; this.store.chosenCargo = this.store.chosenCar?.cargoTypes.find((cargo) => cargo.id == this.store.chosenCargo?.id) || null;
}); });
}, },
}, },
+20 -15
View File
@@ -23,22 +23,27 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, onMounted, ref } from 'vue'; import { computed, onMounted, ref } from "vue";
import { useStore } from '../../store'; import { useStore } from "../../store";
import StockListTab from '../tabs/StockListTab.vue'; import StockListTab from "../tabs/StockListTab.vue";
import StockGeneratorTab from '../tabs/StockGeneratorTab.vue'; import StockGeneratorTab from "../tabs/StockGeneratorTab.vue";
import NumberGeneratorTab from '../tabs/NumberGeneratorTab.vue'; import NumberGeneratorTab from "../tabs/NumberGeneratorTab.vue";
import WikiListTab from '../tabs/WikiListTab.vue'; import WikiListTab from "../tabs/WikiListTab.vue";
const sectionButtonRefs = ref([]); const sectionButtonRefs = ref([]);
const store = useStore(); const store = useStore();
type SectionMode = typeof store.stockSectionMode; type SectionMode = typeof store.stockSectionMode;
const sectionModes: SectionMode[] = ['stock-list', 'wiki-list', 'number-generator', 'stock-generator']; const sectionModes: SectionMode[] = [
"stock-list",
"wiki-list",
"number-generator",
"stock-generator",
];
onMounted(() => { onMounted(() => {
window.addEventListener('keydown', (e) => { window.addEventListener("keydown", (e) => {
if (e.target instanceof HTMLInputElement) return; if (e.target instanceof HTMLInputElement) return;
if (/[1234]/.test(e.key)) { if (/[1234]/.test(e.key)) {
@@ -51,16 +56,16 @@ onMounted(() => {
const chosenSectionComponent = computed(() => { const chosenSectionComponent = computed(() => {
switch (store.stockSectionMode) { switch (store.stockSectionMode) {
case 'stock-list': case "stock-list":
return StockListTab; return StockListTab;
case 'wiki-list': case "wiki-list":
return WikiListTab; return WikiListTab;
case 'stock-generator': case "stock-generator":
return StockGeneratorTab; return StockGeneratorTab;
case 'number-generator': case "number-generator":
return NumberGeneratorTab; return NumberGeneratorTab;
default: default:
@@ -74,7 +79,7 @@ function chooseSection(sectionId: SectionMode) {
</script> </script>
<style lang="scss"> <style lang="scss">
@import '../../styles/global.scss'; @import "../../styles/global.scss";
// Tab change animation // Tab change animation
.tab-change { .tab-change {
@@ -116,14 +121,14 @@ function chooseSection(sectionId: SectionMode) {
left: 50%; left: 50%;
transform: translateX(-50%); transform: translateX(-50%);
content: ''; content: "";
width: 0; width: 0;
height: 2px; height: 2px;
transition: all 100ms; transition: all 100ms;
background-color: $accentColor; background-color: $accentColor;
} }
&[data-selected='true']::after { &[data-selected="true"]::after {
width: 100%; width: 100%;
} }
} }
@@ -18,7 +18,7 @@
</b> </b>
<div style="color: #ccc"> <div style="color: #ccc">
<div>{{ store.chosenVehicle.length }}m | {{ store.chosenVehicle.mass }}t | {{ store.chosenVehicle.maxSpeed }} km/h</div> <div>{{ store.chosenVehicle.length }}m | {{ (store.chosenVehicle.weight / 1000).toFixed(1) }}t | {{ store.chosenVehicle.maxSpeed }} km/h</div>
<div v-if="isLocomotive(store.chosenVehicle)">{{ $t('preview.cabin') }} {{ store.chosenVehicle.cabinType }}</div> <div v-if="isLocomotive(store.chosenVehicle)">{{ $t('preview.cabin') }} {{ store.chosenVehicle.cabinType }}</div>
+107 -49
View File
@@ -1,18 +1,26 @@
<template> <template>
<div class="number-generator tab"> <div class="number-generator tab">
<div class="tab_header"> <div class="tab_header">
<h2>{{ $t('numgen.title') }}</h2> <h2>{{ $t("numgen.title") }}</h2>
<h3>{{ $t('numgen.subtitle') }}</h3> <h3>{{ $t("numgen.subtitle") }}</h3>
</div> </div>
<div class="tab_content"> <div class="tab_content">
<div class="category-select"> <div class="category-select">
<label for="category"> {{ $t('numgen.train-category') }}</label> <label for="category"> {{ $t("numgen.train-category") }}</label>
<select id="category" v-model="chosenCategory" @change="randomizeTrainNumber()"> <select
id="category"
v-model="chosenCategory"
@change="randomizeTrainNumber()"
>
<option :value="null" disabled> <option :value="null" disabled>
{{ $t('numgen.train-category') }} {{ $t("numgen.train-category") }}
</option> </option>
<option v-for="(_, category) in genData.categoriesRules" :key="category" :value="category"> <option
v-for="(_, category) in genData.categoriesRules"
:key="category"
:value="category"
>
{{ $t(`numgen.categories.${category}`) }} {{ $t(`numgen.categories.${category}`) }}
</option> </option>
</select> </select>
@@ -20,22 +28,40 @@
<div class="regions-select"> <div class="regions-select">
<div> <div>
<label for="begin-region"> {{ $t('numgen.start-region') }}</label> <label for="begin-region"> {{ $t("numgen.start-region") }}</label>
<select id="begin-region" v-model="beginRegionName" @change="randomizeTrainNumber()"> <select
id="begin-region"
v-model="beginRegionName"
@change="randomizeTrainNumber()"
>
<option :value="null" disabled> <option :value="null" disabled>
{{ $t('numgen.start-region') }} {{ $t("numgen.start-region") }}
</option> </option>
<option v-for="(_, name) in genData.regionNumbers" :key="name" :value="name"> <option
v-for="(_, name) in genData.regionNumbers"
:key="name"
:value="name"
>
{{ name }} {{ name }}
</option> </option>
</select> </select>
</div> </div>
<div> <div>
<label for="end-region"> {{ $t('numgen.end-region') }}</label> <label for="end-region"> {{ $t("numgen.end-region") }}</label>
<select id="end-region" v-model="endRegionName" @change="randomizeTrainNumber()"> <select
<option :value="null" disabled>{{ $t('numgen.end-region') }}</option> id="end-region"
<option v-for="(_, name) in genData.regionNumbers" :key="name" :value="name"> v-model="endRegionName"
@change="randomizeTrainNumber()"
>
<option :value="null" disabled>
{{ $t("numgen.end-region") }}
</option>
<option
v-for="(_, name) in genData.regionNumbers"
:key="name"
:value="name"
>
{{ name }} {{ name }}
</option> </option>
</select> </select>
@@ -44,50 +70,71 @@
<div class="generated-number" @click="copyNumber"> <div class="generated-number" @click="copyNumber">
<span v-if="trainNumber"> <span v-if="trainNumber">
{{ $t('numgen.number-info') }} {{ $t("numgen.number-info") }}
<b class="text--accent">{{ trainNumber }}</b> <b class="text--accent">{{ trainNumber }}</b>
</span> </span>
<span v-else>{{ $t('numgen.warning') }}</span> <span v-else>{{ $t("numgen.warning") }}</span>
</div> </div>
<div class="category-rules" v-if="chosenCategory && categoryRules && trainNumber"> <div
class="category-rules"
v-if="chosenCategory && categoryRules && trainNumber"
>
<!-- First & second digit (the same regions) --> <!-- First & second digit (the same regions) -->
<div v-if="beginRegionName && endRegionName && beginRegionName == endRegionName"> <div
<b>{{ $t('numgen.rules.two-first-digits') }}</b> {{ $t('numgen.rules.from-pool') }} v-if="
<b class="text--accent">{{ genData.sameRegions[beginRegionName].join(', ') }}</b> beginRegionName && endRegionName && beginRegionName == endRegionName
{{ $t('numgen.rules.for-region') }} {{ beginRegionName }} "
>
<b>{{ $t("numgen.rules.two-first-digits") }}</b>
{{ $t("numgen.rules.from-pool") }}
<b class="text--accent">{{
genData.sameRegions[beginRegionName].join(", ")
}}</b>
{{ $t("numgen.rules.for-region") }} {{ beginRegionName }}
</div> </div>
<!-- First & second digit (different regions) --> <!-- First & second digit (different regions) -->
<div v-else> <div v-else>
<div> <div>
<b> <b>
{{ $t('numgen.rules.first-digit') }} <span class="text--accent">{{ trainNumber[0] }}</span> {{ $t("numgen.rules.first-digit") }}
<span class="text--accent">{{ trainNumber[0] }}</span>
</b> </b>
{{ $t('numgen.rules.for-region-begin') }} {{ beginRegionName }} {{ $t("numgen.rules.for-region-begin") }} {{ beginRegionName }}
</div> </div>
<div> <div>
<b> <b>
{{ $t('numgen.rules.second-digit') }} <span class="text--accent">{{ trainNumber[1] }} </span> {{ $t("numgen.rules.second-digit") }}
<span class="text--accent">{{ trainNumber[1] }} </span>
</b> </b>
{{ $t('numgen.rules.for-region-end') }} {{ endRegionName }} {{ $t("numgen.rules.for-region-end") }} {{ endRegionName }}
</div> </div>
</div> </div>
<!-- Third digit (non-passenger only) --> <!-- Third digit (non-passenger only) -->
<div v-if="categoryRules[0] != null"> <div v-if="categoryRules[0] != null">
<b> <b>
{{ $t('numgen.rules.third-digit') }} <span class="text--accent">{{ categoryRules[0] }}</span> {{ $t("numgen.rules.third-digit") }}
<span class="text--accent">{{ categoryRules[0] }}</span>
</b> </b>
{{ $t('numgen.rules.for-category') }} {{ chosenCategory }} {{ $t("numgen.rules.for-category") }} {{ chosenCategory }}
</div> </div>
<!-- Last digits --> <!-- Last digits -->
<div> <div>
<b> {{ $t(`numgen.rules.${categoryRules[1]?.length == 3 ? 'three' : 'two'}-last-digits`) }}</b> <b>
{{ $t('numgen.rules.from-range') }} {{
<b class="text--accent">{{ categoryRules[1] }}-{{ categoryRules[2] }}</b> $t(
`numgen.rules.${categoryRules[1]?.length == 3 ? "three" : "two"}-last-digits`,
)
}}</b
>
{{ $t("numgen.rules.from-range") }}
<b class="text--accent"
>{{ categoryRules[1] }}-{{ categoryRules[2] }}</b
>
</div> </div>
</div> </div>
@@ -95,7 +142,7 @@
<div class="tab_links"> <div class="tab_links">
<a :href="$t('numgen.td2-wiki-link')" target="_blank"> <a :href="$t('numgen.td2-wiki-link')" target="_blank">
{{ $t('numgen.td2-wiki') }} {{ $t("numgen.td2-wiki") }}
</a> </a>
</div> </div>
@@ -103,15 +150,15 @@
<div class="tab_actions"> <div class="tab_actions">
<button class="btn" @click="randomizeTrainNumber(true)"> <button class="btn" @click="randomizeTrainNumber(true)">
{{ $t('numgen.action-random-region') }} {{ $t("numgen.action-random-region") }}
</button> </button>
<button class="btn" @click="randomizeCategory"> <button class="btn" @click="randomizeCategory">
{{ $t('numgen.action-random-category') }} {{ $t("numgen.action-random-category") }}
</button> </button>
<button class="btn" @click="randomizeTrainNumber(false)"> <button class="btn" @click="randomizeTrainNumber(false)">
{{ $t('numgen.action-random-number') }} {{ $t("numgen.action-random-number") }}
</button> </button>
</div> </div>
</div> </div>
@@ -119,11 +166,11 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { Ref, ref } from 'vue'; import { Ref, ref } from "vue";
import { useI18n } from 'vue-i18n'; import { useI18n } from "vue-i18n";
import genData from '../../constants/numberGeneratorData.json'; import genData from "../../constants/numberGeneratorData.json";
import { computed } from 'vue'; import { computed } from "vue";
const i18n = useI18n(); const i18n = useI18n();
type RegionName = keyof typeof genData.regionNumbers; type RegionName = keyof typeof genData.regionNumbers;
@@ -138,7 +185,7 @@ const trainNumber = ref(null) as Ref<string | null>;
const copyNumber = () => { const copyNumber = () => {
if (trainNumber.value) { if (trainNumber.value) {
navigator.clipboard.writeText(trainNumber.value); navigator.clipboard.writeText(trainNumber.value);
alert(i18n.t('numgen.alert')); alert(i18n.t("numgen.alert"));
} }
}; };
@@ -160,16 +207,23 @@ const randomizeTrainNumber = (randomizeRegions = false) => {
const regionKeys = Object.keys(genData.regionNumbers); const regionKeys = Object.keys(genData.regionNumbers);
if (beginRegionName.value == null || randomizeRegions) beginRegionName.value = regionKeys[(regionKeys.length * Math.random()) << 0] as RegionName; if (beginRegionName.value == null || randomizeRegions)
beginRegionName.value = regionKeys[
(regionKeys.length * Math.random()) << 0
] as RegionName;
if (endRegionName.value == null || randomizeRegions) endRegionName.value = regionKeys[(regionKeys.length * Math.random()) << 0] as RegionName; if (endRegionName.value == null || randomizeRegions)
endRegionName.value = regionKeys[
(regionKeys.length * Math.random()) << 0
] as RegionName;
let number = ''; let number = "";
// Two first numbers (begin & end regions) // Two first numbers (begin & end regions)
if (beginRegionName.value == endRegionName.value) { if (beginRegionName.value == endRegionName.value) {
const sameRegionsNumbers = genData.sameRegions[beginRegionName.value!]; const sameRegionsNumbers = genData.sameRegions[beginRegionName.value!];
const randRegionNumber = sameRegionsNumbers[Math.floor(Math.random() * sameRegionsNumbers.length)]; const randRegionNumber =
sameRegionsNumbers[Math.floor(Math.random() * sameRegionsNumbers.length)];
number += randRegionNumber.toString(); number += randRegionNumber.toString();
} else { } else {
const beginRegionNumber = genData.regionNumbers[beginRegionName.value!]; const beginRegionNumber = genData.regionNumbers[beginRegionName.value!];
@@ -185,18 +239,22 @@ const randomizeTrainNumber = (randomizeRegions = false) => {
} }
// Choose default category if it's not chosen // Choose default category if it's not chosen
if (chosenCategory.value == null) chosenCategory.value = 'EI'; if (chosenCategory.value == null) chosenCategory.value = "EI";
// Get category rules // Get category rules
const [thirdNumber, minRange, maxRange] = categoryRules.value!; const [thirdNumber, minRange, maxRange] = categoryRules.value!;
// Third number // Third number
number += thirdNumber ?? ''; number += thirdNumber ?? "";
// Remaining numbers // Remaining numbers
const rangeNums = minRange!.length; const rangeNums = minRange!.length;
const randRange = Math.floor(Math.random() * (Number(maxRange) - Number(minRange)) + Number(minRange)).toString(); const randRange = Math.floor(
const leadingZeros = new Array(Math.abs(randRange.length - rangeNums)).fill('0').join(''); Math.random() * (Number(maxRange) - Number(minRange)) + Number(minRange),
).toString();
const leadingZeros = new Array(Math.abs(randRange.length - rangeNums))
.fill("0")
.join("");
number += `${leadingZeros}${randRange}`; number += `${leadingZeros}${randRange}`;
@@ -205,8 +263,8 @@ const randomizeTrainNumber = (randomizeRegions = false) => {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import '../../styles/tab.scss'; @import "../../styles/tab.scss";
@import '../../styles/global.scss'; @import "../../styles/global.scss";
label { label {
display: block; display: block;
+8 -8
View File
@@ -15,7 +15,7 @@
<div class="tab_attributes"> <div class="tab_attributes">
<label> <label>
{{ $t('stockgen.input-mass') }} {{ $t('stockgen.input-mass') }}
<input type="number" v-model="maxMass" step="100" max="4000" min="0" /> <input type="number" v-model="maxTons" step="100" max="4000" min="0" />
</label> </label>
<label> <label>
@@ -122,7 +122,7 @@ export default defineComponent({
previewTimeout: -1, previewTimeout: -1,
maxMass: 3000, maxTons: 3000,
maxLength: 650, maxLength: 650,
maxCarCount: 50, maxCarCount: 50,
@@ -191,8 +191,8 @@ export default defineComponent({
const cargoObjs = [] as (ICargo | undefined)[]; const cargoObjs = [] as (ICargo | undefined)[];
if (!cargoType || empty) cargoObjs.push(undefined); if (!cargoType || empty) cargoObjs.push(undefined);
else if (cargoType == 'all') cargoObjs.push(...carWagonObjs[0]!.cargoList); else if (cargoType == 'all') cargoObjs.push(...carWagonObjs[0]!.cargoTypes);
else cargoObjs.push(carWagonObjs[0]?.cargoList.find((cargo) => cargo.id == cargoType)); else cargoObjs.push(carWagonObjs[0]?.cargoTypes.find((cargo) => cargo.id == cargoType));
carWagonObjs.forEach((cw) => { carWagonObjs.forEach((cw) => {
cargoObjs.forEach((cargoObj) => { cargoObjs.forEach((cargoObj) => {
@@ -223,9 +223,9 @@ export default defineComponent({
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
this.store.stockList.splice(this.store.stockList[0]?.isLoco ? 1 : 0); this.store.stockList.splice(this.store.stockList[0]?.isLoco ? 1 : 0);
let carCount = 0;
const maxMass = this.store.acceptableMass > 0 ? Math.min(this.store.acceptableMass, this.maxMass) : this.maxMass; let carCount = 0;
const maxWeight = this.store.acceptableWeight > 0 ? Math.min(this.store.acceptableWeight, this.maxTons * 1000) : this.maxTons * 1000;
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
while (true) { while (true) {
@@ -233,7 +233,7 @@ export default defineComponent({
const { carWagon, cargo } = randomStockType.carPool[~~(Math.random() * randomStockType.carPool.length)]; const { carWagon, cargo } = randomStockType.carPool[~~(Math.random() * randomStockType.carPool.length)];
if ( if (
this.store.totalMass + (cargo?.totalMass || carWagon.mass) > maxMass || this.store.totalWeight + (carWagon.weight + (cargo?.weight ?? 0)) > maxWeight ||
this.store.totalLength + carWagon.length > this.maxLength || this.store.totalLength + carWagon.length > this.maxLength ||
carCount >= this.maxCarCount carCount >= this.maxCarCount
) { ) {
@@ -244,7 +244,7 @@ export default defineComponent({
carCount++; carCount++;
} }
const currentGenerationValue = this.store.totalLength + this.store.totalMass + carCount; const currentGenerationValue = this.store.totalLength + this.store.totalWeight + carCount;
if (bestGeneration.value < currentGenerationValue) { if (bestGeneration.value < currentGenerationValue) {
bestGeneration.stockList = this.store.stockList; bestGeneration.stockList = this.store.stockList;
+6 -6
View File
@@ -60,8 +60,8 @@
<span> <span>
{{ $t('stocklist.mass') }} {{ $t('stocklist.mass') }}
<span class="text--accent">{{ store.totalMass }}t</span> ({{ $t('stocklist.mass-accepted') }}: <span class="text--accent">{{ (store.totalWeight / 1000).toFixed(1) }}t</span> ({{ $t('stocklist.mass-accepted') }}:
<span class="text--accent">{{ store.acceptableMass ? store.acceptableMass + 't' : '-' }}</span <span class="text--accent">{{ store.acceptableWeight ? `${~~(store.acceptableWeight / 1000)}t` : '-' }}</span
>) - {{ $t('stocklist.length') }}: >) - {{ $t('stocklist.length') }}:
<span class="text--accent">{{ store.totalLength }}m</span> <span class="text--accent">{{ store.totalLength }}m</span>
- {{ $t('stocklist.vmax') }}: - {{ $t('stocklist.vmax') }}:
@@ -136,9 +136,9 @@
<span class="stock-info__cargo" v-if="stock.cargo"> <span class="stock-info__cargo" v-if="stock.cargo">
{{ stock.cargo.id }} {{ stock.cargo.id }}
</span> </span>
<span class="stock-info__length"> {{ stock.length }}m </span> <span class="stock-info__length">{{ stock.length }}m</span>
<span class="stock-info__mass">{{ stock.cargo ? stock.cargo.totalMass : stock.mass }}t </span> <span class="stock-info__mass">{{ ((stock.weight + (stock.cargo?.weight ?? 0)) / 1000).toFixed(1) }}t</span>
<span class="stock-info__speed"> {{ stock.maxSpeed }}km/h </span> <span class="stock-info__speed">{{ stock.maxSpeed }}km/h</span>
</div> </div>
</li> </li>
</TransitionGroup> </TransitionGroup>
@@ -324,7 +324,7 @@ export default defineComponent({
downloadStock() { downloadStock() {
if (this.store.stockList.length == 0) return alert(this.$t('stocklist.alert-empty')); if (this.store.stockList.length == 0) return alert(this.$t('stocklist.alert-empty'));
const defaultName = `${this.store.chosenRealStockName || this.store.stockList[0].type} ${this.store.totalMass}t; ${ const defaultName = `${this.store.chosenRealStockName || this.store.stockList[0].type} ${this.store.totalWeight}t; ${
this.store.totalLength this.store.totalLength
}m; vmax ${this.store.maxStockSpeed}`; }m; vmax ${this.store.maxStockSpeed}`;
+15 -9
View File
@@ -54,17 +54,23 @@
/> />
</td> </td>
<td :data-sponsoronly="vehicle.isSponsorsOnly">{{ vehicle.type }}</td> <td :data-sponsoronly="vehicle.isSponsorsOnly">
{{ vehicle.type }}
</td>
<td v-if="isLocomotive(vehicle)">{{ $t(`wiki.${vehicle.power}`) }}</td> <td v-if="isLocomotive(vehicle)">
{{ $t(`wiki.${vehicle.power}`) }}
</td>
<td v-else>{{ $t(`wiki.${vehicle.useType}`) }}</td> <td v-else>{{ $t(`wiki.${vehicle.useType}`) }}</td>
<td>{{ vehicle.constructionType }}</td> <td>{{ vehicle.constructionType }}</td>
<td>{{ vehicle.length }}m</td> <td>{{ vehicle.length }}m</td>
<td>{{ vehicle.mass }}t</td> <td>{{ (vehicle.weight / 1000).toFixed(1) }}t</td>
<td>{{ vehicle.maxSpeed }}km/h</td> <td>{{ vehicle.maxSpeed }}km/h</td>
<td v-if="currentFilterMode == 'carriages'">{{ !isLocomotive(vehicle) ? vehicle.cargoList.length : '---' }}</td> <td v-if="currentFilterMode == 'carriages'">
{{ !isLocomotive(vehicle) ? vehicle.cargoTypes.length : '---' }}
</td>
<td v-if="currentFilterMode == 'tractions'"> <td v-if="currentFilterMode == 'tractions'">
{{ isLocomotive(vehicle) ? (vehicle.coldStart ? `&check;` : '&cross;') : '---' }} {{ isLocomotive(vehicle) ? (vehicle.coldStart ? `&check;` : '&cross;') : '---' }}
</td> </td>
@@ -87,7 +93,7 @@ import { isLocomotive } from '../../utils/vehicleUtils';
import stockMixin from '../../mixins/stockMixin'; import stockMixin from '../../mixins/stockMixin';
import imageMixin from '../../mixins/imageMixin'; import imageMixin from '../../mixins/imageMixin';
type SorterID = 'type' | 'constructionType' | 'image' | 'length' | 'mass' | 'maxSpeed' | 'cargoCount' | 'group' | 'coldStart'; type SorterID = 'type' | 'constructionType' | 'image' | 'length' | 'weight' | 'maxSpeed' | 'cargoCount' | 'group' | 'coldStart';
interface IWikiHeader { interface IWikiHeader {
id: SorterID; id: SorterID;
@@ -106,7 +112,7 @@ const headers: IWikiHeader[] = [
{ id: 'group', sortable: true, for: 'all' }, { id: 'group', sortable: true, for: 'all' },
{ id: 'constructionType', sortable: true, for: 'all' }, { id: 'constructionType', sortable: true, for: 'all' },
{ id: 'length', sortable: true, for: 'all' }, { id: 'length', sortable: true, for: 'all' },
{ id: 'mass', sortable: true, for: 'all' }, { id: 'weight', sortable: true, for: 'all' },
{ id: 'maxSpeed', sortable: true, for: 'all' }, { id: 'maxSpeed', sortable: true, for: 'all' },
{ id: 'coldStart', sortable: true, for: 'tractions' }, { id: 'coldStart', sortable: true, for: 'tractions' },
{ id: 'cargoCount', sortable: true, for: 'carriages' }, { id: 'cargoCount', sortable: true, for: 'carriages' },
@@ -166,15 +172,15 @@ export default defineComponent({
case 'group': case 'group':
return direction == 1 ? row1.vehicle[id].localeCompare(row2.vehicle[id]) : row2.vehicle[id].localeCompare(row1.vehicle[id]); return direction == 1 ? row1.vehicle[id].localeCompare(row2.vehicle[id]) : row2.vehicle[id].localeCompare(row1.vehicle[id]);
case 'mass': case 'weight':
case 'length': case 'length':
case 'maxSpeed': case 'maxSpeed':
return Math.sign(row1.vehicle[id] - row2.vehicle[id]) * direction; return Math.sign(row1.vehicle[id] - row2.vehicle[id]) * direction;
case 'cargoCount': case 'cargoCount':
return ( return (
(!isLocomotive(row1.vehicle) ? Math.sign(row1.vehicle.cargoList.length || -1) : -1) - (!isLocomotive(row1.vehicle) ? Math.sign(row1.vehicle.cargoTypes.length || -1) : -1) -
(!isLocomotive(row2.vehicle) ? (row2.vehicle.cargoList.length || -1) * direction : -1) (!isLocomotive(row2.vehicle) ? (row2.vehicle.cargoTypes.length || -1) * direction : -1)
); );
case 'coldStart': case 'coldStart':
+18 -14
View File
@@ -28,18 +28,18 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { Ref, computed, nextTick, ref, watch } from 'vue'; import { Ref, computed, nextTick, ref, watch } from "vue";
import { useStore } from '../../store'; import { useStore } from "../../store";
import { IStock } from '../../types'; import { IStock } from "../../types";
const store = useStore(); const store = useStore();
const emit = defineEmits(['listItemClick']); const emit = defineEmits(["listItemClick"]);
const thumbnailsRef = ref() as Ref<HTMLElement>; const thumbnailsRef = ref() as Ref<HTMLElement>;
const draggedIndex = ref(-1); const draggedIndex = ref(-1);
const onListItemClick = (index: number) => { const onListItemClick = (index: number) => {
emit('listItemClick', index); emit("listItemClick", index);
}; };
const stockImageError = (e: Event, stock: IStock) => { const stockImageError = (e: Event, stock: IStock) => {
@@ -52,13 +52,15 @@ watch(
if (index < 0) return; if (index < 0) return;
nextTick(() => { nextTick(() => {
(thumbnailsRef.value as HTMLElement).querySelector(`div:nth-child(${index + 1})`)?.scrollIntoView({ (thumbnailsRef.value as HTMLElement)
block: 'nearest', .querySelector(`div:nth-child(${index + 1})`)
inline: 'start', ?.scrollIntoView({
behavior: 'smooth', block: "nearest",
}); inline: "start",
behavior: "smooth",
});
}); });
} },
); );
// Dragging images // Dragging images
@@ -69,7 +71,9 @@ const onDragStart = (vehicleIndex: number) => {
const onDrop = (e: DragEvent, vehicleIndex: number) => { const onDrop = (e: DragEvent, vehicleIndex: number) => {
e.preventDefault(); e.preventDefault();
let targetEl = thumbnailsRef.value.querySelector(`div:nth-child(${vehicleIndex + 1})`); let targetEl = thumbnailsRef.value.querySelector(
`div:nth-child(${vehicleIndex + 1})`,
);
if (!targetEl && draggedIndex.value != -1) return; if (!targetEl && draggedIndex.value != -1) return;
@@ -110,7 +114,7 @@ const allowDrop = (e: DragEvent) => {
-moz-user-select: none; -moz-user-select: none;
-webkit-user-select: none; -webkit-user-select: none;
&[data-selected='true'] { &[data-selected="true"] {
background-color: rebeccapurple; background-color: rebeccapurple;
} }
@@ -119,7 +123,7 @@ const allowDrop = (e: DragEvent) => {
margin: 0 1em; margin: 0 1em;
} }
&[data-sponsor='true'] > b { &[data-sponsor="true"] > b {
color: salmon; color: salmon;
} }
+9 -8
View File
@@ -1,10 +1,11 @@
{ {
"EU06": [650, 2000], "EU06": [650000, 2000000],
"EU07": [650, 2000], "EU07": [650000, 2000000],
"EU07E": [650, 2000], "4E": [650000, 2000000],
"EP07": [650, 650], "EU07E": [650000, 2000000],
"EP08": [650, 650], "EP07": [650000, 650000],
"EP09": [800, 800], "EP08": [650000, 650000],
"ET41": [700, 4000], "EP09": [800000, 800000],
"SM42": [2400, 2400] "ET41": [700000, 4000000],
"SM42": [2400000, 2400000]
} }
+1 -1
View File
@@ -166,7 +166,7 @@
"constructionType": "Construction", "constructionType": "Construction",
"coldStart": "Cold start", "coldStart": "Cold start",
"length": "Length", "length": "Length",
"mass": "Mass", "weight": "Mass",
"maxSpeed": "Speed", "maxSpeed": "Speed",
"cargoCount": "Cargo count" "cargoCount": "Cargo count"
}, },
+1 -1
View File
@@ -166,7 +166,7 @@
"constructionType": "Konstrukcja", "constructionType": "Konstrukcja",
"coldStart": "Zimny start", "coldStart": "Zimny start",
"length": "Długość", "length": "Długość",
"mass": "Masa", "weight": "Masa",
"maxSpeed": "Prędkość", "maxSpeed": "Prędkość",
"cargoCount": "Ładunki" "cargoCount": "Ładunki"
}, },
+5 -5
View File
@@ -1,8 +1,8 @@
import { createApp } from 'vue'; import { createApp } from "vue";
import { createPinia } from 'pinia'; import { createPinia } from "pinia";
import App from './App.vue'; import App from "./App.vue";
import i18n from './i18n-setup'; import i18n from "./i18n-setup";
const pinia = createPinia(); const pinia = createPinia();
createApp(App).use(pinia).use(i18n).mount('#app'); createApp(App).use(pinia).use(i18n).mount("#app");
+3 -3
View File
@@ -1,6 +1,6 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { useStore } from '../store'; import { useStore } from '../store';
import { ICargo, ICarWagon, ILocomotive, IStock, Vehicle } from '../types'; import { ICarWagon, ILocomotive, IStock, ICargo, Vehicle } from '../types';
import { isLocomotive } from '../utils/vehicleUtils'; import { isLocomotive } from '../utils/vehicleUtils';
export default defineComponent({ export default defineComponent({
@@ -22,7 +22,7 @@ export default defineComponent({
id: this.getStockId(), id: this.getStockId(),
type: vehicle.type, type: vehicle.type,
length: vehicle.length, length: vehicle.length,
mass: vehicle.mass, weight: vehicle.weight,
maxSpeed: vehicle.maxSpeed, maxSpeed: vehicle.maxSpeed,
isLoco, isLoco,
cargo: !isLoco && vehicle.loadable && cargo ? cargo : undefined, cargo: !isLoco && vehicle.loadable && cargo ? cargo : undefined,
@@ -88,7 +88,7 @@ export default defineComponent({
const [carType, cargo] = type.split(':'); const [carType, cargo] = type.split(':');
vehicle = this.store.carDataList.find((car) => car.type == carType) || null; vehicle = this.store.carDataList.find((car) => car.type == carType) || null;
if (cargo) vehicleCargo = vehicle?.cargoList.find((c) => c.id == cargo) || null; if (cargo) vehicleCargo = vehicle?.cargoTypes.find((c) => c.id == cargo) || null;
} }
if (!vehicle) console.log('Brak pojazdu / rodzaj pojazdu źle wczytany:', type); if (!vehicle) console.log('Brak pojazdu / rodzaj pojazdu źle wczytany:', type);
+5 -13
View File
@@ -1,5 +1,5 @@
import { defineComponent } from "vue"; import { defineComponent } from 'vue';
import { useStore } from "../store"; import { useStore } from '../store';
export default defineComponent({ export default defineComponent({
setup() { setup() {
@@ -11,17 +11,11 @@ export default defineComponent({
}, },
computed: { computed: {
trainTooLong() { trainTooLong() {
return ( return (this.store.totalLength > 350 && this.store.isTrainPassenger) || (this.store.totalLength > 650 && !this.store.isTrainPassenger);
(this.store.totalLength > 350 && this.store.isTrainPassenger) ||
(this.store.totalLength > 650 && !this.store.isTrainPassenger)
);
}, },
trainTooHeavy() { trainTooHeavy() {
return ( return this.store.acceptableWeight && this.store.totalWeight > this.store.acceptableWeight;
this.store.acceptableMass &&
this.store.totalMass > this.store.acceptableMass
);
}, },
locoNotSuitable() { locoNotSuitable() {
@@ -29,9 +23,7 @@ export default defineComponent({
!this.store.isTrainPassenger && !this.store.isTrainPassenger &&
this.store.stockList.length > 1 && this.store.stockList.length > 1 &&
!this.store.stockList.every((stock) => stock.isLoco) && !this.store.stockList.every((stock) => stock.isLoco) &&
this.store.stockList.some( this.store.stockList.some((stock) => stock.isLoco && stock.type.startsWith('EP'))
(stock) => stock.isLoco && stock.type.startsWith("EP"),
)
); );
}, },
+4 -4
View File
@@ -1,14 +1,14 @@
import { IStockData, IStore } from './types'; import { IStockData, IStore } from './types';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { import {
acceptableMass, acceptableMass as acceptableWeight,
carDataList, carDataList,
chosenRealStock, chosenRealStock,
isTrainPassenger, isTrainPassenger,
locoDataList, locoDataList,
maxStockSpeed, maxStockSpeed,
totalLength, totalLength,
totalMass, totalWeight,
} from './utils/vehicleUtils'; } from './utils/vehicleUtils';
import http from './http'; import http from './http';
@@ -56,12 +56,12 @@ export const useStore = defineStore({
locoDataList: (state) => locoDataList(state), locoDataList: (state) => locoDataList(state),
carDataList: (state) => carDataList(state), carDataList: (state) => carDataList(state),
vehicleDataList: (state) => [...locoDataList(state), ...carDataList(state)], vehicleDataList: (state) => [...locoDataList(state), ...carDataList(state)],
totalMass: (state) => totalMass(state), totalWeight: (state) => totalWeight(state),
totalLength: (state) => totalLength(state), totalLength: (state) => totalLength(state),
maxStockSpeed: (state) => maxStockSpeed(state), maxStockSpeed: (state) => maxStockSpeed(state),
isTrainPassenger: (state) => isTrainPassenger(state), isTrainPassenger: (state) => isTrainPassenger(state),
chosenRealStock: (state) => chosenRealStock(state), chosenRealStock: (state) => chosenRealStock(state),
acceptableMass: (state) => acceptableMass(state), acceptableWeight: (state) => acceptableWeight(state),
stockSupportsColdStart: (state) => { stockSupportsColdStart: (state) => {
if (state.stockList.length == 0) return false; if (state.stockList.length == 0) return false;
+13 -13
View File
@@ -7,30 +7,30 @@ $secondaryColor: #1b1b1b;
$accentColor: #e4c428; $accentColor: #e4c428;
@font-face { @font-face {
font-family: 'Lato'; font-family: "Lato";
src: src:
url('/fonts/Lato-Light.woff2') format('woff2'), url("/fonts/Lato-Light.woff2") format("woff2"),
url('/fonts/Lato-Light.woff') format('woff'); url("/fonts/Lato-Light.woff") format("woff");
font-weight: 300; font-weight: 300;
font-style: normal; font-style: normal;
font-display: swap; font-display: swap;
} }
@font-face { @font-face {
font-family: 'Lato'; font-family: "Lato";
src: src:
url('/fonts/Lato-Bold.woff2') format('woff2'), url("/fonts/Lato-Bold.woff2") format("woff2"),
url('/fonts/Lato-Bold.woff') format('woff'); url("/fonts/Lato-Bold.woff") format("woff");
font-weight: bold; font-weight: bold;
font-style: normal; font-style: normal;
font-display: swap; font-display: swap;
} }
@font-face { @font-face {
font-family: 'Lato'; font-family: "Lato";
src: src:
url('/fonts/Lato-Regular.woff2') format('woff2'), url("/fonts/Lato-Regular.woff2") format("woff2"),
url('/fonts/Lato-Regular.woff') format('woff'); url("/fonts/Lato-Regular.woff") format("woff");
font-weight: normal; font-weight: normal;
font-style: normal; font-style: normal;
font-display: swap; font-display: swap;
@@ -141,14 +141,14 @@ button {
outline: 1px solid white; outline: 1px solid white;
} }
&[data-chosen='true'] { &[data-chosen="true"] {
background-color: $accentColor; background-color: $accentColor;
color: black; color: black;
box-shadow: 0 0 5px 1px $accentColor; box-shadow: 0 0 5px 1px $accentColor;
} }
&[data-disabled='true'] { &[data-disabled="true"] {
user-select: none; user-select: none;
pointer-events: none; pointer-events: none;
-moz-user-select: none; -moz-user-select: none;
@@ -183,8 +183,8 @@ button {
} }
select, select,
input[type='text'], input[type="text"],
input[type='number'] { input[type="number"] {
background: $bgColor; background: $bgColor;
border: 2px solid #aaa; border: 2px solid #aaa;
outline: none; outline: none;
+1 -1
View File
@@ -1,4 +1,4 @@
@import './global.scss'; @import "./global.scss";
.tab { .tab {
height: 100%; height: 100%;
+15 -14
View File
@@ -41,12 +41,19 @@ export type TCarWagonGroup = 'car-passenger' | 'car-cargo';
export interface IStockProps { export interface IStockProps {
type: string; type: string;
length: number; length: number;
mass: number; // mass: number;
cargo?: string | null; weight: number;
// cargo?: string | null;
cargoTypes: ICargo[] | null;
coldStart?: boolean; coldStart?: boolean;
doubleManned?: boolean; doubleManned?: boolean;
} }
export interface ICargo {
id: string;
weight: number;
}
export interface IStockData { export interface IStockData {
version: string; version: string;
@@ -79,8 +86,7 @@ export interface ILocomotive {
isSponsorsOnly: boolean; isSponsorsOnly: boolean;
sponsorsOnlyTimestamp: number; sponsorsOnlyTimestamp: number;
imageSrc: string; imageSrc: string;
weight: number;
mass: number;
length: number; length: number;
coldStart: boolean; coldStart: boolean;
doubleManned: boolean; doubleManned: boolean;
@@ -96,15 +102,9 @@ export interface ICarWagon {
sponsorsOnlyTimestamp: number; sponsorsOnlyTimestamp: number;
maxSpeed: number; maxSpeed: number;
imageSrc: string; imageSrc: string;
weight: number;
mass: number;
length: number; length: number;
cargoList: { id: string; totalMass: number }[]; cargoTypes: ICargo[];
}
export interface ICargo {
id: string;
totalMass: number;
} }
export interface IStock { export interface IStock {
@@ -113,9 +113,10 @@ export interface IStock {
useType: string; useType: string;
constructionType: string; constructionType: string;
length: number; length: number;
mass: number; // mass: number;
weight: number;
maxSpeed: number; maxSpeed: number;
cargo?: { id: string; totalMass: number }; cargo?: ICargo;
isLoco: boolean; isLoco: boolean;
isSponsorsOnly: boolean; isSponsorsOnly: boolean;
sponsorsOnlyTimestamp: number; sponsorsOnlyTimestamp: number;
+15 -6
View File
@@ -1,25 +1,34 @@
import speedLimits from '../constants/speedLimits.json'; import speedLimits from "../constants/speedLimits.json";
import massLimits from '../constants/massLimits.json'; import massLimits from "../constants/massLimits.json";
export type SpeedLimitLocoType = keyof typeof speedLimits; export type SpeedLimitLocoType = keyof typeof speedLimits;
export type MassLimitLocoType = keyof typeof massLimits; export type MassLimitLocoType = keyof typeof massLimits;
export function calculateSpeedLimit(locoType: SpeedLimitLocoType, stockMass: number, isTrainPassenger: boolean) { export function calculateSpeedLimit(
locoType: SpeedLimitLocoType,
stockTotalWeight: number,
isTrainPassenger: boolean,
) {
console.log(speedLimits[locoType]); console.log(speedLimits[locoType]);
if (speedLimits[locoType] === undefined) return 0; if (speedLimits[locoType] === undefined) return 0;
const speedTable = speedLimits[locoType][isTrainPassenger ? 'passenger' : 'cargo']; const speedTable =
speedLimits[locoType][isTrainPassenger ? "passenger" : "cargo"];
if (!speedTable) return undefined; if (!speedTable) return undefined;
let speedLimit = 0; let speedLimit = 0;
for (const mass in speedTable) if (stockMass > Number(mass)) speedLimit = (speedTable as any)[mass]; for (const mass in speedTable)
if (stockTotalWeight > Number(mass)) speedLimit = (speedTable as any)[mass];
return speedLimit; return speedLimit;
} }
export function calculateMassLimit(locoType: MassLimitLocoType, isTrainPassenger: boolean) { export function calculateMassLimit(
locoType: MassLimitLocoType,
isTrainPassenger: boolean,
) {
if (massLimits[locoType] === undefined) return 0; if (massLimits[locoType] === undefined) return 0;
return massLimits[locoType][isTrainPassenger ? 0 : 1] || 0; return massLimits[locoType][isTrainPassenger ? 0 : 1] || 0;
+87 -35
View File
@@ -1,8 +1,21 @@
import { EVehicleUseType } from '../enums/EVehicleUseType'; import { EVehicleUseType } from "../enums/EVehicleUseType";
import { ICarWagon, ILocomotive, IStore, TCarWagonGroup, TLocoGroup } from '../types'; import {
import { MassLimitLocoType, SpeedLimitLocoType, calculateMassLimit, calculateSpeedLimit } from './vehicleLimitsUtils'; ICarWagon,
ILocomotive,
IStore,
TCarWagonGroup,
TLocoGroup,
} from "../types";
import {
MassLimitLocoType,
SpeedLimitLocoType,
calculateMassLimit,
calculateSpeedLimit,
} from "./vehicleLimitsUtils";
export function isLocomotive(vehicle: ILocomotive | ICarWagon): vehicle is ILocomotive { export function isLocomotive(
vehicle: ILocomotive | ICarWagon,
): vehicle is ILocomotive {
return (vehicle as ILocomotive).power !== undefined; return (vehicle as ILocomotive).power !== undefined;
} }
@@ -12,15 +25,18 @@ export function locoDataList(state: IStore) {
const stockData = state.stockData; const stockData = state.stockData;
return Object.keys(stockData.info).reduce((acc, vehiclePower) => { return Object.keys(stockData.info).reduce((acc, vehiclePower) => {
if (!vehiclePower.startsWith('loco')) return acc; if (!vehiclePower.startsWith("loco")) return acc;
const locoVehiclesData = stockData.info[vehiclePower as TLocoGroup]; const locoVehiclesData = stockData.info[vehiclePower as TLocoGroup];
locoVehiclesData.forEach((loco) => { locoVehiclesData.forEach((loco) => {
if (state.showSupporter && !loco[4]) return; if (state.showSupporter && !loco[4]) return;
const [type, constructionType, cabinType, maxSpeed, sponsorsTimestamp] = loco; const [type, constructionType, cabinType, maxSpeed, sponsorsTimestamp] =
const locoProps = stockData.props.find((prop) => constructionType == prop.type); loco;
const locoProps = stockData.props.find(
(prop) => constructionType == prop.type,
);
acc.push({ acc.push({
power: vehiclePower as TLocoGroup, power: vehiclePower as TLocoGroup,
@@ -31,10 +47,16 @@ export function locoDataList(state: IStore) {
maxSpeed: Number(maxSpeed), maxSpeed: Number(maxSpeed),
isSponsorsOnly: Number(sponsorsTimestamp) > Date.now(), isSponsorsOnly: Number(sponsorsTimestamp) > Date.now(),
sponsorsOnlyTimestamp: Number(sponsorsTimestamp), sponsorsOnlyTimestamp: Number(sponsorsTimestamp),
imageSrc: '', imageSrc: "",
length: locoProps?.length && type.startsWith('2EN') ? locoProps.length * 2 : locoProps?.length ?? 0, length:
mass: locoProps?.mass && type.startsWith('2EN') ? 253 : locoProps?.mass ?? 0, locoProps?.length && type.startsWith("2EN")
? locoProps.length * 2
: locoProps?.length ?? 0,
weight:
locoProps?.weight && type.startsWith("2EN")
? 253000
: locoProps?.weight ?? 0,
coldStart: locoProps?.coldStart ?? false, coldStart: locoProps?.coldStart ?? false,
doubleManned: locoProps?.doubleManned ?? false, doubleManned: locoProps?.doubleManned ?? false,
@@ -51,16 +73,25 @@ export function carDataList(state: IStore) {
const stockData = state.stockData; const stockData = state.stockData;
return Object.keys(stockData.info).reduce((acc, vehicleUseType) => { return Object.keys(stockData.info).reduce((acc, vehicleUseType) => {
if (!vehicleUseType.startsWith('car')) return acc; if (!vehicleUseType.startsWith("car")) return acc;
const carVehiclesData = stockData.info[vehicleUseType as TCarWagonGroup]; const carVehiclesData = stockData.info[vehicleUseType as TCarWagonGroup];
carVehiclesData.forEach((car) => { carVehiclesData.forEach((car) => {
const [type, constructionType, loadable, sponsorsOnlyTimestamp, maxSpeed] = car; const [
type,
constructionType,
loadable,
sponsorsOnlyTimestamp,
maxSpeed,
] = car;
if (state.showSupporter && Number(sponsorsOnlyTimestamp) <= Date.now()) return; if (state.showSupporter && Number(sponsorsOnlyTimestamp) <= Date.now())
return;
const carPropsData = stockData.props.find((v) => type.toString().startsWith(v.type)); const carPropsData = stockData.props.find((v) =>
type.toString().startsWith(v.type),
);
acc.push({ acc.push({
useType: vehicleUseType as TCarWagonGroup, useType: vehicleUseType as TCarWagonGroup,
@@ -71,14 +102,10 @@ export function carDataList(state: IStore) {
isSponsorsOnly: Number(sponsorsOnlyTimestamp) > Date.now(), isSponsorsOnly: Number(sponsorsOnlyTimestamp) > Date.now(),
sponsorsOnlyTimestamp: Number(sponsorsOnlyTimestamp), sponsorsOnlyTimestamp: Number(sponsorsOnlyTimestamp),
maxSpeed: Number(maxSpeed), maxSpeed: Number(maxSpeed),
imageSrc: '', imageSrc: "",
cargoList: cargoTypes: carPropsData?.cargoTypes ?? [],
carPropsData?.cargo?.split(';').map((cargo) => ({
id: cargo.split(':')[0],
totalMass: Number(cargo.split(':')[1]),
})) || [],
mass: carPropsData?.mass || 0, weight: carPropsData?.weight || 0,
length: carPropsData?.length || 0, length: carPropsData?.length || 0,
}); });
}); });
@@ -87,37 +114,58 @@ export function carDataList(state: IStore) {
}, [] as ICarWagon[]); }, [] as ICarWagon[]);
} }
export function totalMass(state: IStore) { export function totalWeight(state: IStore) {
return ~~state.stockList.reduce((acc, stock) => acc + (stock.cargo ? stock.cargo.totalMass : stock.mass) * stock.count, 0); return state.stockList.reduce(
(acc, stock) =>
acc + (stock.weight + (stock.cargo?.weight ?? 0)) * stock.count,
0,
);
} }
export function totalLength(state: IStore) { export function totalLength(state: IStore) {
return state.stockList.reduce((acc, stock) => acc + stock.length * stock.count, 0); return state.stockList.reduce(
(acc, stock) => acc + stock.length * stock.count,
0,
);
} }
export function maxStockSpeed(state: IStore) { export function maxStockSpeed(state: IStore) {
const stockSpeedLimit = state.stockList.reduce((acc, stock) => (stock.maxSpeed < acc || acc == 0 ? stock.maxSpeed : acc), 0); const stockSpeedLimit = state.stockList.reduce(
const headingLoco = state.stockList[0]?.isLoco ? state.stockList[0] : undefined; (acc, stock) => (stock.maxSpeed < acc || acc == 0 ? stock.maxSpeed : acc),
0,
);
const headingLoco = state.stockList[0]?.isLoco
? state.stockList[0]
: undefined;
if (!headingLoco) return stockSpeedLimit; if (!headingLoco) return stockSpeedLimit;
const locoType = headingLoco.type.split('-')[0]; const locoType = headingLoco.type.split("-")[0];
if (/^(EN|2EN|SN)/.test(locoType)) return stockSpeedLimit; if (/^(EN|2EN|SN)/.test(locoType)) return stockSpeedLimit;
const stockMass = totalMass(state); const stockTotalWeight = totalWeight(state);
const speedLimitByMass = calculateSpeedLimit(locoType as SpeedLimitLocoType, stockMass, isTrainPassenger(state)); const speedLimitByMass = calculateSpeedLimit(
locoType as SpeedLimitLocoType,
stockTotalWeight,
isTrainPassenger(state),
);
return speedLimitByMass ? Math.min(stockSpeedLimit, speedLimitByMass) : stockSpeedLimit; return speedLimitByMass
? Math.min(stockSpeedLimit, speedLimitByMass)
: stockSpeedLimit;
} }
export function acceptableMass(state: IStore) { export function acceptableMass(state: IStore) {
if (state.stockList.length == 0 || !state.stockList[0].isLoco) return 0; if (state.stockList.length == 0 || !state.stockList[0].isLoco) return 0;
const activeLocomotiveType = state.stockList[0].type.split('-')[0]; const activeLocomotiveType = state.stockList[0].type.split("-")[0];
const locoMassLimit = calculateMassLimit(activeLocomotiveType as MassLimitLocoType, isTrainPassenger(state)); const locoMassLimit = calculateMassLimit(
activeLocomotiveType as MassLimitLocoType,
isTrainPassenger(state),
);
return locoMassLimit; return locoMassLimit;
} }
@@ -126,7 +174,9 @@ export function isTrainPassenger(state: IStore) {
if (state.stockList.length == 0) return false; if (state.stockList.length == 0) return false;
if (state.stockList.every((stock) => stock.isLoco)) return false; if (state.stockList.every((stock) => stock.isLoco)) return false;
return state.stockList.filter((stock) => !stock.isLoco).every((stock) => stock.useType === EVehicleUseType.CAR_PASSENGER); return state.stockList
.filter((stock) => !stock.isLoco)
.every((stock) => stock.useType === EVehicleUseType.CAR_PASSENGER);
} }
export function chosenRealStock(state: IStore) { export function chosenRealStock(state: IStore) {
@@ -135,9 +185,11 @@ export function chosenRealStock(state: IStore) {
for (let i = 0; i < stock.count; i++) acc.push(stock.type); for (let i = 0; i < stock.count; i++) acc.push(stock.type);
return acc; return acc;
}, [] as string[]) }, [] as string[])
.join(';'); .join(";");
const realStockObj = state.readyStockList.find((readyStock) => readyStock.stockString == currentStockString); const realStockObj = state.readyStockList.find(
(readyStock) => readyStock.stockString == currentStockString,
);
state.chosenRealStockName = realStockObj?.stockId ?? undefined; state.chosenRealStockName = realStockObj?.stockId ?? undefined;
+4 -4
View File
@@ -6,11 +6,11 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from "vue";
import { useStore } from '../store'; import { useStore } from "../store";
import MainContainer from '../components/app/MainContainer.vue'; import MainContainer from "../components/app/MainContainer.vue";
import FooterVue from '../components/app/Footer.vue'; import FooterVue from "../components/app/Footer.vue";
export default defineComponent({ export default defineComponent({
components: { components: {