mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-13 10:11:50 +00:00
Merge branch 'modloader' of github.com:tobspr/shapez.io into modloader
This commit is contained in:
commit
8327f170f9
@ -109,6 +109,11 @@ export class ItemProcessorComponent extends Component {
|
||||
* @type {number}
|
||||
*/
|
||||
this.bonusTime = 0;
|
||||
|
||||
/**
|
||||
* @type {Array<EjectorItemToEject>}
|
||||
*/
|
||||
this.queuedEjects = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user