mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-15 19:21:49 +00:00
Fix double painter bug (#1349)
This commit is contained in:
parent
bf7e1887a8
commit
d44191092a
@ -109,6 +109,11 @@ export class ItemProcessorComponent extends Component {
|
|||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.bonusTime = 0;
|
this.bonusTime = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Array<EjectorItemToEject>}
|
||||||
|
*/
|
||||||
|
this.queuedEjects = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -94,49 +94,16 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it finished
|
// Check if it finished and we don't already have queued ejects
|
||||||
if (currentCharge.remainingTime <= 0.0) {
|
if (currentCharge.remainingTime <= 0.0 && !processorComp.queuedEjects.length) {
|
||||||
const itemsToEject = currentCharge.items;
|
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) {
|
for (let j = 0; j < itemsToEject.length; ++j) {
|
||||||
const { item, requiredSlot, preferredSlot } = itemsToEject[j];
|
processorComp.queuedEjects.push(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the charge was entirely emptied to the outputs, start the next charge
|
processorComp.ongoingCharges.shift();
|
||||||
if (itemsToEject.length === 0) {
|
|
||||||
processorComp.ongoingCharges.shift();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,6 +113,40 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
this.startNewCharge(entity);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user