1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-13 02:01:51 +00:00

Fix double painter bug (#1349)

This commit is contained in:
Sense101 2022-02-01 13:50:07 +00:00 committed by GitHub
parent bf7e1887a8
commit d44191092a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 38 deletions

View File

@ -109,6 +109,11 @@ export class ItemProcessorComponent extends Component {
* @type {number}
*/
this.bonusTime = 0;
/**
* @type {Array<EjectorItemToEject>}
*/
this.queuedEjects = [];
}
/**

View File

@ -94,49 +94,16 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
}
}
// Check if it finished
if (currentCharge.remainingTime <= 0.0) {
// Check if it finished and we don't already have queued ejects
if (currentCharge.remainingTime <= 0.0 && !processorComp.queuedEjects.length) {
const itemsToEject = currentCharge.items;
// Go over all items and try to eject them
// Go over all items and add them to the queue
for (let j = 0; j < itemsToEject.length; ++j) {
const { item, requiredSlot, preferredSlot } = itemsToEject[j];
assert(ejectorComp, "To eject items, the building needs to have an ejector");
let slot = null;
if (requiredSlot !== null && requiredSlot !== undefined) {
// We have a slot override, check if that is free
if (ejectorComp.canEjectOnSlot(requiredSlot)) {
slot = requiredSlot;
}
} else if (preferredSlot !== null && preferredSlot !== undefined) {
// We have a slot preference, try using it but otherwise use a free slot
if (ejectorComp.canEjectOnSlot(preferredSlot)) {
slot = preferredSlot;
} else {
slot = ejectorComp.getFirstFreeSlot();
}
} else {
// We can eject on any slot
slot = ejectorComp.getFirstFreeSlot();
}
if (slot !== null) {
// Alright, we can actually eject
if (!ejectorComp.tryEject(slot, item)) {
assert(false, "Failed to eject");
} else {
itemsToEject.splice(j, 1);
j -= 1;
}
}
processorComp.queuedEjects.push(itemsToEject[j]);
}
// If the charge was entirely emptied to the outputs, start the next charge
if (itemsToEject.length === 0) {
processorComp.ongoingCharges.shift();
}
processorComp.ongoingCharges.shift();
}
}
@ -146,6 +113,40 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
this.startNewCharge(entity);
}
}
for (let j = 0; j < processorComp.queuedEjects.length; ++j) {
const { item, requiredSlot, preferredSlot } = processorComp.queuedEjects[j];
assert(ejectorComp, "To eject items, the building needs to have an ejector");
let slot = null;
if (requiredSlot !== null && requiredSlot !== undefined) {
// We have a slot override, check if that is free
if (ejectorComp.canEjectOnSlot(requiredSlot)) {
slot = requiredSlot;
}
} else if (preferredSlot !== null && preferredSlot !== undefined) {
// We have a slot preference, try using it but otherwise use a free slot
if (ejectorComp.canEjectOnSlot(preferredSlot)) {
slot = preferredSlot;
} else {
slot = ejectorComp.getFirstFreeSlot();
}
} else {
// We can eject on any slot
slot = ejectorComp.getFirstFreeSlot();
}
if (slot !== null) {
// Alright, we can actually eject
if (!ejectorComp.tryEject(slot, item)) {
assert(false, "Failed to eject");
} else {
processorComp.queuedEjects.splice(j, 1);
j -= 1;
}
}
}
}
}