Aktualizacja 1.0.5

This commit is contained in:
2021-11-17 14:16:23 +01:00
parent 60d8da9598
commit 0459bbb90c
9 changed files with 592 additions and 128 deletions
+13 -13
View File
@@ -1,13 +1,13 @@
favicon.ico,1636839873685,665ba81c9556ba00abb1a0fa575fe801b3c35f23481b17528a211b8c3021f7cd favicon.ico,1636908703056,665ba81c9556ba00abb1a0fa575fe801b3c35f23481b17528a211b8c3021f7cd
index.html,1636839873685,2bfbcf0ae387abf043a6c4012c8383751c3df6bac2abb5fbfa00ecb7ec1e29ba index.html,1636908703056,6894914497fb85a5fd56e07601efb80d51eb8459397f3c98753f4f29f2a1cbd1
css/app.e318326a.css,1636839873687,5f8edf44d0d80443531b74e2fba1c192d8f524f7a92daab577abd758c568eb73 img/higher-icon.68df973e.svg,1636908703060,258bcb0fc4c62a0ecd53681bfa4777451e0cb4b980e1094f68d89d4077fa657a
img/add-icon.a0f313fe.svg,1636839873690,be43aa8b694c90777971ad2d7f611f52c7ee172131fe2e24a82348891bb6aa18 css/app.e6df6391.css,1636908703060,649cf1518bfa2a52c89ec8e6703b22bc462b9f1942de6706855febed1f734241
img/higher-icon.68df973e.svg,1636839873690,258bcb0fc4c62a0ecd53681bfa4777451e0cb4b980e1094f68d89d4077fa657a img/add-icon.a0f313fe.svg,1636908703060,be43aa8b694c90777971ad2d7f611f52c7ee172131fe2e24a82348891bb6aa18
img/lower-icon.7c306380.svg,1636839873685,286e1759ea8d4c11327f425f6d6af41603b329dab36c419b228acbea217c2080 img/lower-icon.7c306380.svg,1636908703059,286e1759ea8d4c11327f425f6d6af41603b329dab36c419b228acbea217c2080
img/remove-icon.09c0dbc9.svg,1636839873690,1e01bccdf38cee755fc54c9768b4089fdb11d904a6b9aa86fcb20a2357dc8d61 img/sub-icon.bfa10f67.svg,1636908703060,afa120d2f8afe18161a6ed011eb0482ef9604fd35c1d3be8cd93b1087b1138eb
img/logo.c9fcc748.svg,1636839873690,59a9ce681c6123558f2b025931a262148f1d0bb47d5a3300a14a2e9020a85bc9 img/remove-icon.09c0dbc9.svg,1636908703060,1e01bccdf38cee755fc54c9768b4089fdb11d904a6b9aa86fcb20a2357dc8d61
img/sub-icon.bfa10f67.svg,1636839873690,afa120d2f8afe18161a6ed011eb0482ef9604fd35c1d3be8cd93b1087b1138eb img/logo.c9fcc748.svg,1636908703060,59a9ce681c6123558f2b025931a262148f1d0bb47d5a3300a14a2e9020a85bc9
js/app.e79b9cbd.js,1636839873687,371740d1e17483c569dbfde222073ba25cca03b522d4af59c9dd617d3c5372e6 js/app.68f816df.js,1636908703060,2c887f2145b31dee1596c41b6aa4e0bd67ad5c590dbeeacc9f1aa2fd1eba37e9
js/app.e79b9cbd.js.map,1636839873691,2e93a681e3d233d413b4045488ba0fedd0cf40592570b9e743b52bd36d8b5c62 js/app.68f816df.js.map,1636908703061,a3bb3a6d8b76b0ab08428bd9a098b4d9c1ae55e895ceda9e88dcea1bf18e4d40
js/chunk-vendors.e3e59fe7.js,1636839873690,b8da867c1596780117d35525b8065aeaa4337aa2caee1c5bc043834baf717406 js/chunk-vendors.1cf1afd1.js,1636908703061,138b204e055fd02583bb465dcac5481d5f10484aa9765cf40c69997e045f4a7d
js/chunk-vendors.e3e59fe7.js.map,1636839873692,cdae68767a1b7010a6ccdcb43952d9fcd5d1d974617e4d02b4da5919d28dfbac js/chunk-vendors.1cf1afd1.js.map,1636908703061,46aa56f02ef6c577f5ed79d5c3e58f06306595c6c83d1652e9bfea77fb303321
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "pojazdownik", "name": "pojazdownik",
"version": "1.0.4", "version": "1.0.5",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
+1
View File
@@ -55,6 +55,7 @@ export default defineComponent({
if (this.store.vehiclePreviewSrc == '') return; if (this.store.vehiclePreviewSrc == '') return;
if (ev.key.toLowerCase() == 'escape') this.store.vehiclePreviewSrc = ''; if (ev.key.toLowerCase() == 'escape') this.store.vehiclePreviewSrc = '';
// if(ev.key.toLowerCase() == 'enter')
}); });
// window.focus(); // window.focus();
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 7.7 KiB

+10 -81
View File
@@ -125,91 +125,20 @@ export default defineComponent({
}, },
mounted() { mounted() {
document.addEventListener('wheel', (ev) => { document.addEventListener('keydown', (ev) => {
if (!ev.target) return; const keyName = ev.key.toLowerCase();
if (keyName == 'enter') {
const selectAttr = (ev.target as Element).attributes.getNamedItem('data-select'); ev.preventDefault();
this.addVehicle();
if (!selectAttr) return;
if (selectAttr.value == 'loco') {
const chosenLoco = this.store.chosenLoco;
if (!chosenLoco) {
this.store.chosenLoco = this.locoOptions[0];
this.onLocoTypeChange();
return;
}
if (ev.deltaY > 0) {
const nextOptionIndex = this.locoOptions.findIndex((opt) => opt.type == chosenLoco.type) + 1;
if (nextOptionIndex >= this.locoOptions.length) return;
this.store.chosenLoco = this.locoOptions[nextOptionIndex];
this.onLocoTypeChange();
} else {
const prevOptionIndex = this.locoOptions.findIndex((opt) => opt.type == chosenLoco.type) - 1;
if (prevOptionIndex < 0) return;
this.store.chosenLoco = this.locoOptions[prevOptionIndex];
this.onLocoTypeChange();
}
} }
if (selectAttr.value == 'car') { if (keyName == 'backspace') {
const chosenCar = this.store.chosenCar; if (this.store.stockList.length == 0) return;
if (!chosenCar) { const lastStock = this.store.stockList.slice(-1)[0];
this.store.chosenCar = this.carOptions[0];
this.onCarTypeChange();
return; if (lastStock.count > 1) lastStock.count--;
} else this.store.stockList.splice(-1);
if (ev.deltaY > 0) {
const nextOptionIndex = this.carOptions.findIndex((opt) => opt.type == chosenCar.type) + 1;
if (nextOptionIndex >= this.carOptions.length) return;
this.store.chosenCar = this.carOptions[nextOptionIndex];
this.onCarTypeChange();
} else {
const prevOptionIndex = this.carOptions.findIndex((opt) => opt.type == chosenCar.type) - 1;
if (prevOptionIndex < 0) return;
this.store.chosenCar = this.carOptions[prevOptionIndex];
this.onCarTypeChange();
}
}
if (selectAttr.value == 'cargo') {
if (!this.store.chosenCar) return;
if (!this.store.chosenCar.cargoList || this.store.chosenCar.cargoList.length == 0) return;
const chosenCargoList = this.store.chosenCar.cargoList;
if (!this.store.chosenCargo) {
this.store.chosenCargo = chosenCargoList[0];
return;
}
if (ev.deltaY > 0) {
const nextOptionIndex = chosenCargoList.findIndex((cargo) => cargo.id == this.store.chosenCargo?.id) + 1;
if (nextOptionIndex >= chosenCargoList.length) return;
this.store.chosenCargo = chosenCargoList[nextOptionIndex];
} else {
const prevOptionIndex = chosenCargoList.findIndex((cargo) => cargo.id == this.store.chosenCargo?.id) - 1;
if (prevOptionIndex < 0) return;
this.store.chosenCargo = chosenCargoList[prevOptionIndex];
}
} }
}); });
+182 -32
View File
@@ -1,5 +1,11 @@
<template> <template>
<div class="bottom"> <div class="bottom">
<div class="bg-dimmer" v-if="isRandomizerCardOpen"></div>
<transition name="card-anim">
<randomizer-card v-if="isRandomizerCardOpen" />
</transition>
<section class="image"> <section class="image">
<div class="image__wrapper"> <div class="image__wrapper">
<div <div
@@ -17,13 +23,15 @@
@load="onImageLoad" @load="onImageLoad"
@click="onImageClick" @click="onImageClick"
/> />
<!-- <img </div>
v-if="store.chosenCar" </div>
:src="store.chosenCar.imageSrc"
:alt="store.chosenCar.type" <div class="brief-info" v-if="store.chosenLoco || store.chosenCar">
@load="onImageLoad" <b class="text--accent">{{ (store.chosenLoco || store.chosenCar)?.type }}</b>
@click="onImageClick" <div>{{ vehicleTypes[store.chosenLoco?.power || store.chosenCar?.useType || 'loco-e'] }}</div>
/> --> <div>
{{ (store.chosenCar || store.chosenLoco)?.length }}m | {{ (store.chosenCar || store.chosenLoco)?.mass }}t |
{{ (store.chosenCar || store.chosenLoco)?.maxSpeed }} km/h
</div> </div>
</div> </div>
</section> </section>
@@ -34,11 +42,14 @@
<div class="stock-list_buttons"> <div class="stock-list_buttons">
<button class="btn" @click="downloadStock">POBIERZ POCIĄG</button> <button class="btn" @click="downloadStock">POBIERZ POCIĄG</button>
<button class="btn" @click="resetStock">ZRESETUJ LISTĘ</button> <button class="btn" @click="resetStock">ZRESETUJ LISTĘ</button>
<span></span>
<button class="btn" @click="shuffleCars">TASUJ WAGONY</button>
<button class="btn" @click="openRandomizerCard">LOSUJ SKŁAD</button>
</div> </div>
<div class="stock-list_specs"> <div class="stock-list_specs">
Masa: <span class="text--accent">{{ totalMass }}</span> t | Długość: Masa: <span class="text--accent">{{ totalMass }}t</span> | Długość:
<span class="text--accent">{{ totalLength }}</span> <span class="text--accent">{{ totalLength }}m</span>
m | Vmax pociągu: <span class="text--accent">{{ maxStockSpeed }} km/h</span>
</div> </div>
<div class="warnings"> <div class="warnings">
@@ -49,6 +60,8 @@
<div class="warning" v-if="warnings.trainTooLong.value">Ten skład jest za długi!</div> <div class="warning" v-if="warnings.trainTooLong.value">Ten skład jest za długi!</div>
<div class="warning" v-if="warnings.trainTooHeavy.value">Ten skład jest za ciężki!</div> <div class="warning" v-if="warnings.trainTooHeavy.value">Ten skład jest za ciężki!</div>
<div class="warning" v-if="warnings.tooManyLocos.value">Ten skład posiada za dużo pojazdów trakcyjnych!</div>
</div> </div>
<ul> <ul>
@@ -72,15 +85,13 @@
@dragover="allowDrop" @dragover="allowDrop"
draggable="true" draggable="true"
> >
<span v-if="stock.supportersOnly" style="color: salmon"> *S* </span> <span class="stock__type" :class="{ supporter: stock.supportersOnly }">
<span>
{{ stock.isLoco ? stock.type : getCarSpecFromType(stock.type) }} {{ stock.isLoco ? stock.type : getCarSpecFromType(stock.type) }}
</span> </span>
<span v-if="stock.cargo"> &nbsp; ({{ stock.cargo?.id }}) </span> <span class="stock__cargo" v-if="stock.cargo"> {{ stock.cargo.id }} </span>
&nbsp; <span class="stock__length"> {{ stock.length }}m </span>
<span> {{ stock.length }}m</span> <span class="stock__mass">{{ stock.cargo ? stock.cargo.totalMass : stock.mass }}t </span>
&nbsp; <span class="stock__speed"> {{ stock.maxSpeed }}km/h </span>
<span>{{ stock.cargo ? stock.cargo.totalMass : stock.mass }}t</span>
</div> </div>
<div class="item-actions"> <div class="item-actions">
@@ -110,13 +121,24 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { computed, ComputedRef, defineComponent, inject } from 'vue'; import { computed, ComputedRef, defineComponent, inject, provide, reactive, ref } from 'vue';
import { ICarWagon, ILocomotive, IStore } from '@/types'; import { ICarWagon, ILocomotive, IStore } from '@/types';
import RandomizerCard from './RandomizerCard.vue';
export default defineComponent({ export default defineComponent({
components: { RandomizerCard },
setup() { setup() {
const store = inject('Store') as IStore; const store = inject('Store') as IStore;
const isRandomizerCardOpen = ref(false);
provide('isCardOpen', isRandomizerCardOpen);
provide('chosenLength', ref(350));
provide('chosenMass', ref(1000));
provide('chosenLocoType', ref('loco-e'));
provide('chosenCarTypes', reactive([]));
provide('includeSupporterVehicles', ref(false));
return { return {
store, store,
locoDataList: inject('locoDataList') as ILocomotive[], locoDataList: inject('locoDataList') as ILocomotive[],
@@ -131,8 +153,11 @@ export default defineComponent({
locoNotSuitable: ComputedRef<boolean>; locoNotSuitable: ComputedRef<boolean>;
trainTooLong: ComputedRef<boolean>; trainTooLong: ComputedRef<boolean>;
trainTooHeavy: ComputedRef<boolean>; trainTooHeavy: ComputedRef<boolean>;
tooManyLocos: ComputedRef<boolean>;
}, },
isRandomizerCardOpen,
hasSupporterOnlyVehicle: computed(() => store.stockList.some((stock) => stock.supportersOnly)), hasSupporterOnlyVehicle: computed(() => store.stockList.some((stock) => stock.supportersOnly)),
}; };
}, },
@@ -146,13 +171,26 @@ export default defineComponent({
higher: require('@/assets/higher-icon.svg'), higher: require('@/assets/higher-icon.svg'),
}, },
imageOffsetY: 0,
draggedVehicleID: -1, draggedVehicleID: -1,
vehicleTypes: {
'loco-e': 'ELEKTROWÓZ',
'loco-s': 'SPALINOWÓZ',
'loco-ezt': 'ELEKTRYCZNY ZESP. TRAKCYJNY',
'loco-szt': 'SPALINOWY ZESP. TRAKCYJNY',
'car-passenger': 'WAGON PASAŻERSKI',
'car-cargo': 'WAGON TOWAROWY',
} as { [key: string]: string },
}), }),
methods: { methods: {
onListItemFocus(vehicleID: number) { onListItemFocus(vehicleID: number) {
const vehicle = this.store.stockList[vehicleID]; const vehicle = this.store.stockList[vehicleID];
if ((this.store.chosenCar || this.store.chosenLoco)?.imageSrc != vehicle.imgSrc) this.store.imageLoading = true;
if (this.store.showSupporter && !vehicle.supportersOnly) { if (this.store.showSupporter && !vehicle.supportersOnly) {
this.store.showSupporter = false; this.store.showSupporter = false;
} }
@@ -165,7 +203,6 @@ export default defineComponent({
this.store.chosenCar = null; this.store.chosenCar = null;
this.store.chosenCargo = null; this.store.chosenCargo = null;
// this.store.onLocoPowerChange(vehicle.useType);
return; return;
} }
@@ -174,8 +211,6 @@ export default defineComponent({
this.store.chosenLoco = null; this.store.chosenLoco = null;
this.store.chosenCar = this.carDataList.find((v) => v.type == vehicle.type) || null; this.store.chosenCar = this.carDataList.find((v) => v.type == vehicle.type) || null;
this.store.chosenCargo = vehicle.cargo || null; this.store.chosenCargo = vehicle.cargo || null;
// this.chose = vehicle.useType;
}, },
getCarSpecFromType(typeStr: string) { getCarSpecFromType(typeStr: string) {
@@ -226,12 +261,32 @@ export default defineComponent({
this.store.stockList[index + 1] = tempStock; this.store.stockList[index + 1] = tempStock;
}, },
shuffleCars() {
const availableIndexes = this.store.stockList.reduce((acc, stock, i) => {
if (!stock.isLoco) acc.push(i);
return acc;
}, [] as number[]);
for (let i = 0; i < this.store.stockList.length; i++) {
if (!availableIndexes.includes(i)) continue;
availableIndexes.splice(i, -1);
const randAvailableIndex = availableIndexes[Math.floor(Math.random() * availableIndexes.length)];
const tempSwap = this.store.stockList[randAvailableIndex];
this.store.stockList[randAvailableIndex] = this.store.stockList[i];
this.store.stockList[i] = tempSwap;
}
},
openRandomizerCard() {
this.isRandomizerCardOpen = true;
},
downloadStock() { downloadStock() {
if ( if (Object.values(this.warnings).some((v) => v.value == true)) {
this.warnings.locoNotSuitable.value ||
this.warnings.trainTooLong.value ||
this.warnings.trainTooHeavy.value
) {
``; ``;
const allowDownload = confirm( const allowDownload = confirm(
'Jazda tym pociągiem może być niezgodna z regulaminem symulatora! Czy na pewno chcesz kontynuować?' 'Jazda tym pociągiem może być niezgodna z regulaminem symulatora! Czy na pewno chcesz kontynuować?'
@@ -310,6 +365,17 @@ export default defineComponent({
<style lang="scss" scoped> <style lang="scss" scoped>
@import '../styles/global'; @import '../styles/global';
.bg-dimmer {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(black, 0.85);
z-index: 100;
}
.bottom { .bottom {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@@ -348,6 +414,9 @@ export default defineComponent({
flex-grow: 2; flex-grow: 2;
padding: 0 1em 0 0; padding: 0 1em 0 0;
display: flex;
flex-direction: column;
&__wrapper { &__wrapper {
max-width: 380px; max-width: 380px;
width: 22em; width: 22em;
@@ -367,6 +436,8 @@ export default defineComponent({
img { img {
width: 100%; width: 100%;
height: 100%; height: 100%;
cursor: pointer;
} }
.empty-message, .empty-message,
@@ -390,17 +461,42 @@ export default defineComponent({
} }
} }
.brief-info {
text-align: center;
margin: 1em 0;
font-size: 1.1em;
b {
font-size: 1.2em;
}
div {
margin: 0.25em 0;
}
}
.stock-list { .stock-list {
flex-grow: 3; flex-grow: 3;
width: 100%; width: 100%;
&_buttons { &_buttons {
margin-bottom: 0.5em; display: flex;
span {
flex-grow: 2;
}
button { button {
font-size: 0.9em; font-size: 0.9em;
padding: 0.4em 0.55em; padding: 0.4em 0.55em;
margin-right: 0.5em; margin: 0 0.5em 1em 0;
&:nth-child(5) {
margin-right: 0;
}
&:focus { &:focus {
color: $accentColor; color: $accentColor;
@@ -411,6 +507,9 @@ export default defineComponent({
ul { ul {
margin-top: 1em; margin-top: 1em;
max-height: 500px;
overflow: auto;
} }
ul li { ul li {
@@ -426,19 +525,35 @@ export default defineComponent({
color: $accentColor; color: $accentColor;
} }
&:hover .item-content {
color: $accentColor;
}
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
.item-content { .item-content {
/* background: whitesmoke; */ display: flex;
flex-wrap: wrap;
color: white; color: white;
font-weight: 700; font-weight: 700;
margin: 1em 0; margin: 0.5em 0;
margin-right: 0.5em; transition: color 100ms;
/* max-width: 200px; */ span {
padding: 0.5em;
margin-right: 0.25em;
margin-top: 0.25em;
}
@media screen and (max-width: 800px) {
span {
padding: 0.25em;
}
}
} }
.item-actions { .item-actions {
@@ -472,4 +587,39 @@ export default defineComponent({
} }
} }
} }
.stock {
&__type {
background-color: #222;
&.supporter {
background-color: #ff887b;
}
}
&__cargo {
background-color: #333;
}
&__length,
&__mass,
&__speed {
background-color: #555;
}
}
.card-anim {
&-enter {
opacity: 0;
}
&-enter-active,
&-leave-active {
transition: opacity 300ms;
}
&-leave-to {
opacity: 0;
}
}
</style> </style>
+355
View File
@@ -0,0 +1,355 @@
<template>
<div class="card">
<!-- <button class="btn" @click="closeCard">X</button> -->
<div class="wrapper">
<h1>LOSUJ SKŁAD TOWAROWY <img :src="icons.randomize" alt="losuj skład" /></h1>
<h3>
Skład zostanie dołączony do dodanej na liście lokomotywy czołowej bądź wygenerowany z losową w przypadku jej
braku
</h3>
<div class="car-choice">
<p>Dobierz rodzaje wagonów</p>
<div>
<button
class="btn choice-btn"
v-for="car in carList"
:key="car.id"
@click="toggleCarType(car.id)"
:class="{ chosen: chosenCarTypes.includes(car.id) }"
>
{{ car.title }}
</button>
</div>
</div>
<div class="length-choice">
<p>Wybierz preferowaną długość składu (m) i (opcjonalnie) max. masę (t)</p>
<input
type="number"
v-model="chosenLength"
name="length"
max="650"
min="20"
step="10"
title="Długość składu (m)"
/>
<input
type="number"
v-model="chosenMass"
name="length"
max="2500"
min="100"
step="100"
title="Masa składu (t)"
/>
</div>
<div style="margin-top: 1em">
<button
class="btn choice-btn"
:class="{ chosen: includeSupporterVehicles }"
@click="
() => {
includeSupporterVehicles = !includeSupporterVehicles;
}
"
>
DOŁĄCZ POJAZDY DLA SUPPORTERÓW
</button>
</div>
<button class="btn" style="font-size: 1.15em; margin-top: 2em" @click="randomize">LOSUJ SKŁAD!</button>
<button class="btn" style="font-size: 1.15em; margin-top: 2em" @click="closeCard">ZAMKNIJ</button>
</div>
</div>
</template>
<script lang="ts">
import { ICargo, ICarWagon, ILocomotive, IStore } from '@/types';
import { defineComponent, inject } from 'vue';
export default defineComponent({
setup() {
const isCardOpen = inject('isCardOpen') as boolean;
const store = inject('Store') as IStore;
return {
isCardOpen,
store,
locoDataList: inject('locoDataList') as ILocomotive[],
carDataList: inject('carDataList') as ICarWagon[],
chosenLength: inject('chosenLength') as number,
chosenMass: inject('chosenMass') as number,
chosenLocoType: inject('chosenLocoType') as string,
chosenCarTypes: inject('chosenCarTypes') as string[],
includeSupporterVehicles: inject('includeSupporterVehicles') as boolean,
};
},
data: () => ({
icons: {
randomize: require('@/assets/randomize-icon.svg'),
},
carList: [
{
id: 'cisterns',
title: 'CYSTERNY',
types: ['29R'],
},
{
id: 'coal-cars',
title: 'WĘGLARKI',
types: ['412W', '429W'],
},
{
id: 'conteners',
title: 'KONTENEROWCE',
types: ['412Z', '424Z', '627Z'],
},
{
id: 'special-cars',
title: 'SPECJALNE',
types: ['441V', '426S', '304Ca', '209c'],
},
{
id: 'tanks',
title: 'ZBIORNIKOWE',
types: ['408S'],
},
{
id: 'covered-cars',
title: 'KRYTE',
types: ['203V'],
},
],
}),
methods: {
closeCard() {
this.isCardOpen = false;
},
randomize() {
if (this.chosenCarTypes.length == 0) {
alert('Wybierz przynajmniej jeden rodzaj wagonów!');
return;
}
if (this.chosenLength <= 20) {
alert('Długość składu musi być większa niż 20m!');
return;
}
if (this.chosenMass <= 100) {
alert('Masa składu musi być większa niż 100t!');
return;
}
if (this.chosenMass > 2500) {
alert('Masa składu nie powinna przekraczać 2500t!');
return;
}
if (this.chosenLength > 650) {
alert('Długość składu nie może przekraczać 650m dla pociągów towarowych!');
return;
}
let totalStockLength = 0;
let totalStockMass = 0;
if (this.store.stockList.length == 0 || !this.store.stockList[0].isLoco) {
this.store.stockList.length = 0;
const locoSet = this.locoDataList
.filter((loco) => !loco.type.startsWith('EP') && (loco.power == 'loco-e' || loco.power == 'loco-s'))
.filter((loco) => (!this.includeSupporterVehicles && loco.supportersOnly ? false : true));
const randLoco = locoSet[Math.floor(Math.random() * locoSet.length)];
this.addLoco(randLoco);
} else this.store.stockList.length = 1;
totalStockLength += this.store.stockList[0].length;
totalStockMass += this.store.stockList[0].mass;
let availableCarsSet = this.carDataList.filter((car) => {
if (!this.includeSupporterVehicles && car.supportersOnly) return false;
if (this.carList.find((c) => c.types.includes(car.constructionType) && this.chosenCarTypes.includes(c.id)))
return true;
return false;
});
while (totalStockLength < this.chosenLength && totalStockMass < this.chosenMass) {
const randCarIndex = Math.floor(Math.random() * availableCarsSet.length);
const randCar = availableCarsSet[randCarIndex];
// const count = Math.random() < 0.25 ? Math.floor(Math.random() * 2) + 1 : 1;
const count = 1;
if (randCar.length * count + totalStockLength >= this.chosenLength) break;
let randCargo = undefined;
let randNum = Math.random();
if (randCar.cargoList.length != 0 && randNum >= 0.6)
randCargo = randCar.cargoList[Math.floor(Math.random() * randCar.cargoList.length)];
if ((randCargo?.totalMass || randCar.mass) * count + totalStockMass >= this.chosenMass) break;
for (let i = 0; i < count; i++) this.addCar(randCar, randCargo);
totalStockLength += randCar.length * count;
totalStockMass += randCargo?.totalMass || randCar.mass;
}
this.isCardOpen = false;
},
toggleCarType(id: string) {
if (this.chosenCarTypes.includes(id)) this.chosenCarTypes.splice(this.chosenCarTypes.indexOf(id), 1);
else this.chosenCarTypes.push(id);
},
addLoco(loco: ILocomotive) {
const previousStock =
this.store.stockList.length > 0 ? this.store.stockList[this.store.stockList.length - 1] : null;
if (previousStock && previousStock.type == loco.type) {
this.store.stockList[this.store.stockList.length - 1].count++;
return;
}
const stockObj = {
type: loco.type,
length: loco.length,
mass: loco.mass,
maxSpeed: loco.maxSpeed,
isLoco: true,
cargo: undefined,
count: 1,
imgSrc: loco.imageSrc,
useType: loco.power,
supportersOnly: loco.supportersOnly,
};
if (this.store.stockList.length > 0 && !this.store.stockList[0].isLoco) this.store.stockList.unshift(stockObj);
else this.store.stockList.push(stockObj);
},
addCar(car: ICarWagon, cargo?: ICargo) {
const previousStock =
this.store.stockList.length > 0 ? this.store.stockList[this.store.stockList.length - 1] : null;
if (previousStock && previousStock.type == car.type && previousStock.cargo?.id == cargo?.id) {
this.store.stockList[this.store.stockList.length - 1].count++;
return;
}
const stockObj = {
type: car.type,
length: car.length,
mass: car.mass,
maxSpeed: car.maxSpeed,
isLoco: false,
cargo: car.loadable && cargo ? cargo : undefined,
count: 1,
imgSrc: car.imageSrc,
useType: car.useType,
supportersOnly: car.supportersOnly,
};
this.store.stockList.push(stockObj);
},
},
});
</script>
<style lang="scss" scoped>
/* @import url('../styles/global.scss'); */
.card {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 100;
display: flex;
justify-content: center;
text-align: center;
border: 2px solid white;
width: 700px;
padding: 2em 1em;
background: rgba(black, 0.95);
@media screen and (max-width: 700px) {
width: 95%;
}
border-radius: 1em;
}
p {
font-size: 1.2em;
}
h1 {
display: flex;
justify-content: center;
flex-wrap: wrap;
margin: 0;
img {
margin-left: 0.5em;
width: 2em;
}
}
h3 {
margin: 0 0 2em 0;
color: #999;
}
button,
input {
margin: 0.25em;
}
input {
font-size: 1.2em;
}
button.choice-btn {
color: gray;
border-color: gray;
&:hover,
*:focus {
color: white;
border-color: white;
}
user-select: none;
}
button.chosen {
border-color: gold;
color: gold;
}
</style>
+12 -1
View File
@@ -142,7 +142,6 @@ export const carDataList = computed(() => Object.keys(vehicleDataJSON).reduce(
id: cargo.split(":")[0], id: cargo.split(":")[0],
totalMass: Number(cargo.split(":")[1]), totalMass: Number(cargo.split(":")[1]),
})) : [], })) : [],
mass: carPropsData?.mass || 0, mass: carPropsData?.mass || 0,
length: carPropsData?.length || 0, length: carPropsData?.length || 0,
}); });
@@ -272,6 +271,18 @@ export const warnings = {
if (headingLoco.type.startsWith("SM") && totalMass.value > 2400) 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; return false;
}) })
} }
+8
View File
@@ -34,11 +34,19 @@ a {
} }
} }
p {
font-size: 1.2em;
font-weight: bold;
color: $accentColor;
}
select, select,
option, option,
input, input,
button { button {
font-family: "Lato", sans-serif; font-family: "Lato", sans-serif;
font-size: 1em;
} }
button { button {