support zimnego startu lokomotyw

This commit is contained in:
2023-07-13 17:51:09 +02:00
parent 7362d4ffbd
commit cbe983f96c
11 changed files with 108 additions and 81 deletions
+2 -18
View File
@@ -107,10 +107,8 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { IStock } from '../../types';
import imageMixin from '../../mixins/imageMixin'; import imageMixin from '../../mixins/imageMixin';
import { useStore } from '../../store'; import { useStore } from '../../store';
import { isLocomotive } from '../../utils/vehicleUtils';
import stockPreviewMixin from '../../mixins/stockPreviewMixin'; import stockPreviewMixin from '../../mixins/stockPreviewMixin';
import stockMixin from '../../mixins/stockMixin'; import stockMixin from '../../mixins/stockMixin';
@@ -197,22 +195,8 @@ export default defineComponent({
if (!vehicle) return; if (!vehicle) return;
const stockObj: IStock = { const stockObject = this.getStockObject(vehicle, this.store.chosenCargo);
id: `${Date.now()}`, this.store.stockList[this.store.chosenStockListIndex] = stockObject;
useType: isLocomotive(vehicle) ? vehicle.power : vehicle.useType,
type: vehicle.type,
length: vehicle.length,
mass: vehicle.mass,
maxSpeed: vehicle.maxSpeed,
isLoco: isLocomotive(vehicle),
cargo:
!isLocomotive(vehicle) && vehicle.loadable && this.store.chosenCargo ? this.store.chosenCargo : undefined,
count: 1,
imgSrc: vehicle.imageSrc,
supportersOnly: vehicle.supportersOnly,
};
this.store.stockList[this.store.chosenStockListIndex] = stockObj;
}, },
}, },
}); });
+1 -3
View File
@@ -49,12 +49,10 @@ const sectionKeyIndexes: { [key: number]: SectionMode } = {
}; };
onMounted(() => { onMounted(() => {
console.log(sectionButtonRefs.value);
window.addEventListener('keydown', (e) => { window.addEventListener('keydown', (e) => {
if (e.target instanceof HTMLInputElement) return; if (e.target instanceof HTMLInputElement) return;
if (e.key == '1' || e.key == '2' || e.key == '3' || e.key == '4') { if (/[1234]/.test(e.key)) {
const keyNum = Number(e.key); const keyNum = Number(e.key);
store.stockSectionMode = sectionKeyIndexes[keyNum]; store.stockSectionMode = sectionKeyIndexes[keyNum];
(sectionButtonRefs.value[keyNum - 1] as HTMLButtonElement).focus(); (sectionButtonRefs.value[keyNum - 1] as HTMLButtonElement).focus();
+30 -29
View File
@@ -1,5 +1,5 @@
<template> <template>
<section class="stock-list"> <section class="stock-list-tab">
<div class="stock_controls" :data-disabled="store.chosenStockListIndex == -1"> <div class="stock_controls" :data-disabled="store.chosenStockListIndex == -1">
<b class="no"> <b class="no">
POJAZD NR <span class="text--accent">{{ store.chosenStockListIndex + 1 }}</span> &nbsp; POJAZD NR <span class="text--accent">{{ store.chosenStockListIndex + 1 }}</span> &nbsp;
@@ -68,7 +68,18 @@
</span> </span>
</div> </div>
<div class="stock_warnings"> <div class="stock_cold-start">
<label>
<input
type="checkbox"
v-model="store.isColdStart"
:disabled="!locoSupportsColdStart(store.stockList[0]?.constructionType || '')"
/>
Zimny start lokomotywy czołowej (tylko elektrowozy typów 303E i 203E)
</label>
</div>
<div class="stock_warnings" v-if="stockHasWarnings">
<div class="warning" v-if="locoNotSuitable"> <div class="warning" v-if="locoNotSuitable">
Lokomotywy EP07 i EP08 przeznaczone jedynie do ruchu pasażerskiego! Lokomotywy EP07 i EP08 przeznaczone jedynie do ruchu pasażerskiego!
</div> </div>
@@ -147,10 +158,11 @@ import { defineComponent } from 'vue';
import TrainImage from '../sections/TrainImageSection.vue'; import TrainImage from '../sections/TrainImageSection.vue';
import { useStore } from '../../store'; import { useStore } from '../../store';
import { locoSupportsColdStart } from '../../utils/locoUtils';
import warningsMixin from '../../mixins/warningsMixin'; import warningsMixin from '../../mixins/warningsMixin';
import imageMixin from '../../mixins/imageMixin'; import imageMixin from '../../mixins/imageMixin';
import stockPreviewMixin from '../../mixins/stockPreviewMixin'; import stockPreviewMixin from '../../mixins/stockPreviewMixin';
import { IStock } from '../../types';
import StockThumbnails from '../utils/StockThumbnails.vue'; import StockThumbnails from '../utils/StockThumbnails.vue';
import stockMixin from '../../mixins/stockMixin'; import stockMixin from '../../mixins/stockMixin';
@@ -162,8 +174,7 @@ export default defineComponent({
setup() { setup() {
const store = useStore(); const store = useStore();
return { return {
store, store,
}; };
@@ -178,13 +189,12 @@ export default defineComponent({
computed: { computed: {
stockString() { stockString() {
return this.store.stockList return this.store.stockList
.map((stock) => { .map((stock, i) => {
let s = stock.isLoco || !stock.cargo ? stock.type : `${stock.type}:${stock.cargo.id}`; let stockTypeStr = stock.isLoco || !stock.cargo ? stock.type : `${stock.type}:${stock.cargo.id}`;
let coldStart =
i == 0 && this.store.isColdStart && locoSupportsColdStart(stock.constructionType || '') ? ',c' : '';
let final = s; return stockTypeStr + coldStart;
for (let i = 0; i < stock.count - 1; i++) final += `;${s}`;
return final;
}) })
.join(';'); .join(';');
}, },
@@ -196,19 +206,16 @@ export default defineComponent({
chosenStockVehicle() { chosenStockVehicle() {
return this.store.chosenStockListIndex == -1 ? undefined : this.store.stockList[this.store.chosenStockListIndex]; return this.store.chosenStockListIndex == -1 ? undefined : this.store.stockList[this.store.chosenStockListIndex];
}, },
},
methods: {
stockHasWarnings() { stockHasWarnings() {
return this.tooManyLocomotives || this.trainTooHeavy || this.trainTooLong || this.locoNotSuitable; return this.tooManyLocomotives || this.trainTooHeavy || this.trainTooLong || this.locoNotSuitable;
}, },
},
methods: {
locoSupportsColdStart,
copyToClipboard() { copyToClipboard() {
// if (this.stockHasWarnings()) {
// alert('Jazda tym pociągiem jest niezgodna z regulaminem symulatora! Zmień parametry zestawienia!');
// return;
// }
navigator.clipboard.writeText(this.stockString); navigator.clipboard.writeText(this.stockString);
setTimeout(() => { setTimeout(() => {
@@ -317,9 +324,6 @@ export default defineComponent({
downloadStock() { downloadStock() {
if (this.store.stockList.length == 0) return alert('Lista pojazdów jest pusta!'); if (this.store.stockList.length == 0) return alert('Lista pojazdów jest pusta!');
// if (this.stockHasWarnings())
// return alert('Jazda tym pociągiem jest niezgodna z regulaminem symulatora! Zmień parametry zestawienia!');
const defaultName = `${this.store.chosenRealStockName || this.store.stockList[0].type} ${ const defaultName = `${this.store.chosenRealStockName || this.store.stockList[0].type} ${
this.store.totalMass this.store.totalMass
}t; ${this.store.totalLength}m; vmax ${this.store.maxStockSpeed}`; }t; ${this.store.totalLength}m; vmax ${this.store.maxStockSpeed}`;
@@ -395,6 +399,11 @@ export default defineComponent({
<style lang="scss" scoped> <style lang="scss" scoped>
@import '../../styles/global'; @import '../../styles/global';
.stock-list-tab {
display: grid;
grid-gap: 0.5em;
}
.warning { .warning {
padding: 0.25em; padding: 0.25em;
background: $accentColor; background: $accentColor;
@@ -417,7 +426,6 @@ export default defineComponent({
flex-wrap: wrap; flex-wrap: wrap;
padding: 0.5em; padding: 0.5em;
margin-bottom: 1em;
background-color: #353a57; background-color: #353a57;
@@ -450,7 +458,6 @@ export default defineComponent({
.stock_actions { .stock_actions {
display: grid; display: grid;
gap: 0.5em; gap: 0.5em;
margin-bottom: 1em;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
@@ -472,9 +479,7 @@ export default defineComponent({
ul { ul {
position: relative; position: relative;
overflow: auto; overflow: auto;
height: 500px; height: 500px;
} }
@@ -518,10 +523,6 @@ li > .stock-info {
} }
} }
.stock_warnings {
margin: 0.5em 0;
}
.supporter { .supporter {
color: salmon; color: salmon;
} }
+51 -22
View File
@@ -15,7 +15,7 @@
<table> <table>
<thead> <thead>
<tr> <tr>
<th v-for="header in wikiMode == 'locomotives' ? locoHeaders : carHeaders" @click="toggleSorter(header.id)"> <th v-for="header in wikiMode == 'locomotives' ? locoHeaders : carHeaders" @click="toggleSorter(header)">
{{ header.name }} {{ header.name }}
<span v-if="currentModeSorter.id == header.id"> <span v-if="currentModeSorter.id == header.id">
@@ -44,6 +44,7 @@
<td>{{ loco.type }}</td> <td>{{ loco.type }}</td>
<td>{{ vehicleTypes[loco.power] }}</td> <td>{{ vehicleTypes[loco.power] }}</td>
<td>{{ loco.constructionType }}</td> <td>{{ loco.constructionType }}</td>
<td>{{ locoSupportsColdStart(loco.constructionType) ? `&check;` : '&cross;' }}</td>
<td>{{ loco.length }}m</td> <td>{{ loco.length }}m</td>
<td>{{ loco.mass }}t</td> <td>{{ loco.mass }}t</td>
<td>{{ loco.maxSpeed }}km/h</td> <td>{{ loco.maxSpeed }}km/h</td>
@@ -86,28 +87,45 @@ import stockPreviewMixin from '../../mixins/stockPreviewMixin';
import { Vehicle } from '../../types'; import { Vehicle } from '../../types';
import { isLocomotive } from '../../utils/vehicleUtils'; import { isLocomotive } from '../../utils/vehicleUtils';
import stockMixin from '../../mixins/stockMixin'; import stockMixin from '../../mixins/stockMixin';
import { locoSupportsColdStart } from '../../utils/locoUtils';
type WikiMode = 'locomotives' | 'carWagons'; type WikiMode = 'locomotives' | 'carWagons';
type SorterID = 'type' | 'constructionType' | 'image' | 'length' | 'mass' | 'maxSpeed' | 'cargoCount' | 'power'; type SorterID =
| 'type'
| 'constructionType'
| 'image'
| 'length'
| 'mass'
| 'maxSpeed'
| 'cargoCount'
| 'power'
| 'coldStart';
const locoHeaders: { name: string; id: SorterID }[] = [ interface WikiHeader {
{ name: 'Zdjęcie', id: 'image' }, name: string;
{ name: 'Nazwa', id: 'type' }, id: SorterID;
{ name: 'Rodzaj', id: 'power' }, sortable: boolean;
{ name: 'Konstrukcja', id: 'constructionType' }, }
{ name: 'Długość', id: 'length' },
{ name: 'Masa', id: 'mass' }, const locoHeaders: WikiHeader[] = [
{ name: 'Prędkość', id: 'maxSpeed' }, { name: 'Zdjęcie', id: 'image', sortable: false },
{ name: 'Nazwa', id: 'type', sortable: true },
{ name: 'Rodzaj', id: 'power', sortable: true },
{ name: 'Konstrukcja', id: 'constructionType', sortable: true },
{ name: 'Zimny start', id: 'coldStart', sortable: true },
{ name: 'Długość', id: 'length', sortable: true },
{ name: 'Masa', id: 'mass', sortable: true },
{ name: 'Prędkość', id: 'maxSpeed', sortable: true },
]; ];
const carHeaders: { name: string; id: SorterID }[] = [ const carHeaders: WikiHeader[] = [
{ name: 'Zdjęcie', id: 'image' }, { name: 'Zdjęcie', id: 'image', sortable: false },
{ name: 'Nazwa', id: 'type' }, { name: 'Nazwa', id: 'type', sortable: true },
{ name: 'Konstrukcja', id: 'constructionType' }, { name: 'Konstrukcja', id: 'constructionType', sortable: true },
{ name: 'Długość', id: 'length' }, { name: 'Długość', id: 'length', sortable: true },
{ name: 'Masa', id: 'mass' }, { name: 'Masa', id: 'mass', sortable: true },
{ name: 'Prędkość', id: 'maxSpeed' }, { name: 'Prędkość', id: 'maxSpeed', sortable: true },
{ name: 'Ładunki', id: 'cargoCount' }, { name: 'Ładunki', id: 'cargoCount', sortable: true },
]; ];
const vehicleTypes: { [key: string]: string } = { const vehicleTypes: { [key: string]: string } = {
@@ -151,6 +169,8 @@ export default defineComponent({
}, },
methods: { methods: {
locoSupportsColdStart,
scrollEvent(e: Event) { scrollEvent(e: Event) {
const tableScrollTop = (e.target as HTMLElement).scrollTop; const tableScrollTop = (e.target as HTMLElement).scrollTop;
@@ -163,14 +183,16 @@ export default defineComponent({
this.wikiMode = wikiMode; this.wikiMode = wikiMode;
}, },
toggleSorter(id: SorterID) { toggleSorter(header: WikiHeader) {
if (id == this.currentModeSorter.id) this.currentModeSorter.direction = -this.currentModeSorter.direction; if (!header.sortable) return;
this.currentModeSorter.id = id;
if (header.id == this.currentModeSorter.id) this.currentModeSorter.direction *= -1;
this.currentModeSorter.id = header.id;
}, },
sortVehicles(vA: Vehicle, vB: Vehicle) { sortVehicles(vA: Vehicle, vB: Vehicle) {
const { id, direction } = this.currentModeSorter; const { id, direction } = this.currentModeSorter;
// const vehiclesAreLocos = isLocomotive(vA) && isLocomotive(vB); const vehiclesAreLocos = isLocomotive(vA) && isLocomotive(vB);
const vehiclesAreCars = !isLocomotive(vA) && !isLocomotive(vB); const vehiclesAreCars = !isLocomotive(vA) && !isLocomotive(vB);
switch (id) { switch (id) {
@@ -186,6 +208,13 @@ export default defineComponent({
case 'cargoCount': case 'cargoCount':
if (vehiclesAreCars) return Math.sign((vA.cargoList.length || -1) - (vB.cargoList.length || -1)) * direction; if (vehiclesAreCars) return Math.sign((vA.cargoList.length || -1) - (vB.cargoList.length || -1)) * direction;
case 'coldStart':
if (vehiclesAreLocos)
return (
(locoSupportsColdStart(vA.constructionType) > locoSupportsColdStart(vB.constructionType) ? 1 : -1) *
direction
);
default: default:
break; break;
} }
-3
View File
@@ -86,10 +86,7 @@ const allowDrop = (e: DragEvent) => {
<style lang="scss" scoped> <style lang="scss" scoped>
.stock_thumbnails { .stock_thumbnails {
display: flex; display: flex;
margin: 1em 0;
overflow: auto; overflow: auto;
background-color: #353a57; background-color: #353a57;
> div { > div {
+4 -1
View File
@@ -30,6 +30,7 @@ export default defineComponent({
imgSrc: vehicle.imageSrc, imgSrc: vehicle.imageSrc,
useType: isLoco ? vehicle.power : vehicle.useType, useType: isLoco ? vehicle.power : vehicle.useType,
supportersOnly: vehicle.supportersOnly, supportersOnly: vehicle.supportersOnly,
constructionType: vehicle.constructionType,
}; };
}, },
@@ -67,13 +68,15 @@ export default defineComponent({
this.store.swapVehicles = false; this.store.swapVehicles = false;
stockArray.forEach((type) => { stockArray.forEach((type, i) => {
let vehicle: Vehicle | null = null; let vehicle: Vehicle | null = null;
let vehicleCargo: ICargo | null = null; let vehicleCargo: ICargo | null = null;
if (/^(EU|EP|ET|SM|EN|2EN|SN)/.test(type)) { if (/^(EU|EP|ET|SM|EN|2EN|SN)/.test(type)) {
const [locoType, coldStart] = type.split(','); const [locoType, coldStart] = type.split(',');
vehicle = this.store.locoDataList.find((loco) => loco.type == locoType) || null; vehicle = this.store.locoDataList.find((loco) => loco.type == locoType) || null;
if (i == 0 && coldStart == 'c') this.store.isColdStart = true;
} else { } else {
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;
+1 -1
View File
@@ -26,7 +26,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.find((stock) => stock.isLoco && stock.type.startsWith('EP')) this.store.stockList.some((stock) => stock.isLoco && stock.type.startsWith('EP'))
); );
}, },
+6
View File
@@ -20,6 +20,8 @@ export const useStore = defineStore({
chosenCargo: null, chosenCargo: null,
chosenVehicle: null, chosenVehicle: null,
isColdStart: false,
showSupporter: false, showSupporter: false,
imageLoading: false, imageLoading: false,
@@ -71,6 +73,9 @@ export const useStore = defineStore({
case '/stockgnr': case '/stockgnr':
this.stockSectionMode = 'stock-generator'; this.stockSectionMode = 'stock-generator';
break; break;
case '/vehicles':
this.stockSectionMode = 'wiki-list';
break;
default: default:
break; break;
} }
@@ -78,3 +83,4 @@ export const useStore = defineStore({
}, },
}); });
+4 -2
View File
@@ -134,8 +134,9 @@ button {
} }
select, select,
input { input[type="text"],
background: $bgColor; input[type="number"] {
background: none;
border: 2px solid #aaa; border: 2px solid #aaa;
outline: none; outline: none;
@@ -158,6 +159,7 @@ input {
option { option {
color: white; color: white;
border: none; border: none;
background-color: $bgColor;
} }
ul { ul {
+4 -2
View File
@@ -5,9 +5,10 @@ export interface IStore {
chosenCar: ICarWagon | null; chosenCar: ICarWagon | null;
chosenLoco: ILocomotive | null; chosenLoco: ILocomotive | null;
chosenCargo: ICargo | null; chosenCargo: ICargo | null;
chosenVehicle: Vehicle | null; chosenVehicle: Vehicle | null;
isColdStart: boolean;
showSupporter: boolean; showSupporter: boolean;
imageLoading: boolean; imageLoading: boolean;
@@ -99,8 +100,9 @@ export interface ICargo {
export interface IStock { export interface IStock {
id: string; id: string;
useType: string;
type: string; type: string;
useType: string;
constructionType: string;
length: number; length: number;
mass: number; mass: number;
maxSpeed: number; maxSpeed: number;
+5
View File
@@ -0,0 +1,5 @@
const supportedConstructions = ['303e', '203e'];
export function locoSupportsColdStart(constructionType: string) {
return new RegExp(`(${supportedConstructions.join('|')})`).test(constructionType);
}