format; linting; aktualizacja do 2023.2.1

This commit is contained in:
2023-10-24 23:28:42 +02:00
parent 57ab6cc02d
commit 1c2a93fbd5
40 changed files with 2019 additions and 1640 deletions
+10 -2
View File
@@ -1,9 +1,17 @@
import { defineComponent } from 'vue';
import { defineComponent } from "vue";
export default defineComponent({
methods: {
getIconURL(name: string, ext = 'svg'): string {
getIconURL(name: string, ext = "svg"): string {
return `/images/icon-${name}.${ext}`;
},
getThumbnailURL(vehicleType: string, size: "small" | "large") {
return `${
import.meta.env.VITE_API_DEV === "1"
? "http://localhost:5500"
: "https://spythere.github.io/api"
}/td2/images/${vehicleType}--${size == "small" ? 300 : 800}px.jpg`;
},
},
});
+21 -15
View File
@@ -1,7 +1,7 @@
import { defineComponent } from 'vue';
import { useStore } from '../store';
import { ICargo, ICarWagon, ILocomotive, IStock, Vehicle } from '../types';
import { isLocomotive } from '../utils/vehicleUtils';
import { defineComponent } from "vue";
import { useStore } from "../store";
import { ICargo, ICarWagon, ILocomotive, IStock, Vehicle } from "../types";
import { isLocomotive } from "../utils/vehicleUtils";
export default defineComponent({
setup() {
@@ -39,14 +39,16 @@ export default defineComponent({
const stock = this.getStockObject(vehicle, cargo);
if (stock.isLoco && !this.store.stockList[0]?.isLoco) this.store.stockList.unshift(stock);
if (stock.isLoco && !this.store.stockList[0]?.isLoco)
this.store.stockList.unshift(stock);
else this.store.stockList.push(stock);
},
addLocomotive(loco: ILocomotive) {
const stockObj = this.getStockObject(loco);
if (this.store.stockList.length > 0 && !this.store.stockList[0].isLoco) this.store.stockList.unshift(stockObj);
if (this.store.stockList.length > 0 && !this.store.stockList[0].isLoco)
this.store.stockList.unshift(stockObj);
else this.store.stockList.push(stockObj);
},
@@ -57,7 +59,7 @@ export default defineComponent({
},
loadStockFromString(stockString: string) {
const stockArray = stockString.trim().split(';');
const stockArray = stockString.trim().split(";");
this.store.stockList.length = 0;
this.store.chosenVehicle = null;
@@ -73,22 +75,26 @@ export default defineComponent({
let vehicleCargo: ICargo | null = null;
if (/^(EU|EP|ET|SM|EN|2EN|SN)/.test(type)) {
const [locoType, coldStart] = type.split(',');
vehicle = this.store.locoDataList.find((loco) => loco.type == locoType) || null;
const [locoType, coldStart] = type.split(",");
vehicle =
this.store.locoDataList.find((loco) => loco.type == locoType) ||
null;
if (i == 0 && coldStart == 'c') this.store.isColdStart = true;
if (i == 0 && coldStart == "c") this.store.isColdStart = true;
} else {
const [carType, cargo] = type.split(':');
vehicle = this.store.carDataList.find((car) => car.type == carType) || null;
const [carType, cargo] = type.split(":");
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?.cargoList.find((c) => c.id == cargo) || null;
}
if (!vehicle) console.log('Brak pojazdu:', type);
if (!vehicle) console.log("Brak pojazdu:", type);
this.addVehicle(vehicle, vehicleCargo);
});
},
},
});
+17 -10
View File
@@ -1,6 +1,6 @@
import { defineComponent } from 'vue';
import { useStore } from '../store';
import { ICarWagon, ILocomotive, IStock, Vehicle } from '../types';
import { defineComponent } from "vue";
import { useStore } from "../store";
import { ICarWagon, ILocomotive, IStock } from "../types";
export default defineComponent({
setup() {
@@ -12,12 +12,14 @@ export default defineComponent({
computed: {
locoOptions() {
return this.store.locoDataList
.slice()
.sort((a, b) => (a.type > b.type ? 1 : -1))
.filter((loco) => loco.power == this.store.chosenLocoPower);
},
carOptions() {
return this.store.carDataList
.slice()
.sort((a, b) => (a.type > b.type ? 1 : -1))
.filter((car) => car.useType == this.store.chosenCarUseType);
},
@@ -37,28 +39,34 @@ export default defineComponent({
this.store.chosenCargo = null;
},
previewVehicleByType(type: 'loco' | 'car' | 'cargo') {
previewVehicleByType(type: "loco" | "car" | "cargo") {
this.$nextTick(() => {
if (!this.store.chosenLoco && !this.store.chosenCar) return;
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.chosenCar?.cargoList.find(
(cargo) => cargo.id == this.store.chosenCargo?.id,
) || null;
});
},
previewStock(stock: IStock) {
if (this.store.chosenVehicle?.imageSrc != stock.imgSrc) this.store.imageLoading = true;
if (this.store.chosenVehicle?.imageSrc != stock.imgSrc)
this.store.imageLoading = true;
if (stock.isLoco) {
const chosenLoco = this.store.locoDataList.find((v) => v.type == stock.type) || null;
const chosenLoco =
this.store.locoDataList.find((v) => v.type == stock.type) || null;
this.store.chosenVehicle = chosenLoco;
this.store.chosenLoco = chosenLoco;
this.store.chosenCargo = null;
this.store.chosenLocoPower = stock.useType;
} else {
const chosenCar = this.store.carDataList.find((v) => v.type == stock.type) || null;
const chosenCar =
this.store.carDataList.find((v) => v.type == stock.type) || null;
this.store.chosenVehicle = chosenCar;
this.store.chosenCar = chosenCar;
@@ -89,4 +97,3 @@ export default defineComponent({
},
},
});
+15 -8
View File
@@ -1,5 +1,5 @@
import { defineComponent } from 'vue';
import { useStore } from '../store';
import { defineComponent } from "vue";
import { useStore } from "../store";
export default defineComponent({
setup() {
@@ -18,7 +18,10 @@ export default defineComponent({
},
trainTooHeavy() {
return this.store.acceptableMass && this.store.totalMass > this.store.acceptableMass;
return (
this.store.acceptableMass &&
this.store.totalMass > this.store.acceptableMass
);
},
locoNotSuitable() {
@@ -26,15 +29,19 @@ export default defineComponent({
!this.store.isTrainPassenger &&
this.store.stockList.length > 1 &&
!this.store.stockList.every((stock) => stock.isLoco) &&
this.store.stockList.some((stock) => stock.isLoco && stock.type.startsWith('EP'))
this.store.stockList.some(
(stock) => stock.isLoco && stock.type.startsWith("EP"),
)
);
},
tooManyLocomotives() {
return this.store.stockList.reduce((acc, stock) => {
if (stock.isLoco) acc += stock.count;
return acc;
}, 0) > 2;
return (
this.store.stockList.reduce((acc, stock) => {
if (stock.isLoco) acc += stock.count;
return acc;
}, 0) > 2
);
},
},
});