mirror of
https://github.com/Spythere/pojazdownik.git
synced 2026-05-05 04:28:10 +00:00
fix: generowanie składów
This commit is contained in:
@@ -183,17 +183,25 @@ export default defineComponent({
|
|||||||
const headingLoco = this.store.stockList[0]?.isLoco ? this.store.stockList[0] : undefined;
|
const headingLoco = this.store.stockList[0]?.isLoco ? this.store.stockList[0] : undefined;
|
||||||
|
|
||||||
this.store.stockList.length = headingLoco ? 1 : 0;
|
this.store.stockList.length = headingLoco ? 1 : 0;
|
||||||
const maxMass = this.store.acceptableMass || this.maxMass;
|
const maxMass = Math.min(this.store.acceptableMass, this.maxMass);
|
||||||
|
|
||||||
new Array(this.maxCarCount).fill(0).forEach(() => {
|
let exceeded = false;
|
||||||
|
|
||||||
|
while (!exceeded) {
|
||||||
const randomStockType = generatedChosenStockList[~~(Math.random() * generatedChosenStockList.length)];
|
const randomStockType = generatedChosenStockList[~~(Math.random() * generatedChosenStockList.length)];
|
||||||
const { carWagon, cargo } = randomStockType.carPool[~~(Math.random() * randomStockType.carPool.length)];
|
const { carWagon, cargo } = randomStockType.carPool[~~(Math.random() * randomStockType.carPool.length)];
|
||||||
|
|
||||||
if (this.store.totalMass + (cargo?.totalMass || carWagon.mass) > maxMass) return;
|
if (
|
||||||
if (this.store.totalLength + carWagon.length > this.maxLength) return;
|
this.store.totalMass + (cargo?.totalMass || carWagon.mass) > maxMass ||
|
||||||
|
this.store.totalLength + carWagon.length > this.maxLength ||
|
||||||
|
this.store.stockList.length > this.maxCarCount
|
||||||
|
) {
|
||||||
|
exceeded = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
this.addCarWagon(carWagon, cargo);
|
this.addCarWagon(carWagon, cargo);
|
||||||
});
|
}
|
||||||
|
|
||||||
this.store.stockSectionMode = 'stock-list';
|
this.store.stockSectionMode = 'stock-list';
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -43,13 +43,6 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addLocomotive(loco: ILocomotive) {
|
addLocomotive(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 = this.getStockObject(loco);
|
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);
|
||||||
@@ -57,15 +50,6 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addCarWagon(car: ICarWagon, cargo?: ICargo) {
|
addCarWagon(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 = this.getStockObject(car, cargo);
|
const stockObj = this.getStockObject(car, cargo);
|
||||||
|
|
||||||
this.store.stockList.push(stockObj);
|
this.store.stockList.push(stockObj);
|
||||||
|
|||||||
Reference in New Issue
Block a user