1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Add support for a buffered second item to be ejected

This allows the double painter to start the next paint job immediately,
thus eliminating the reason it ran slower than specified.

Fixes #842
This commit is contained in:
Frode Austvik 2020-11-16 23:05:01 +01:00
parent d33a72202a
commit 473d91365b
3 changed files with 18 additions and 7 deletions

View File

@ -182,7 +182,7 @@ export class MetaPainterBuilding extends MetaBuilding {
]); ]);
entity.components.ItemEjector.setSlots([ entity.components.ItemEjector.setSlots([
{ pos: new Vector(1, 0), direction: enumDirection.right }, { pos: new Vector(1, 0), direction: enumDirection.right, buffered: true },
]); ]);
entity.components.ItemProcessor.type = enumItemProcessorTypes.painterDouble; entity.components.ItemProcessor.type = enumItemProcessorTypes.painterDouble;

View File

@ -12,6 +12,7 @@ import { typeItemSingleton } from "../item_resolver";
* direction: enumDirection, * direction: enumDirection,
* item: BaseItem, * item: BaseItem,
* progress: number?, * progress: number?,
* nextItem?: BaseItem,
* cachedDestSlot?: import("./item_acceptor").ItemAcceptorLocatedSlot, * cachedDestSlot?: import("./item_acceptor").ItemAcceptorLocatedSlot,
* cachedBeltPath?: BeltPath, * cachedBeltPath?: BeltPath,
* cachedTargetEntity?: Entity * cachedTargetEntity?: Entity
@ -38,7 +39,7 @@ export class ItemEjectorComponent extends Component {
/** /**
* *
* @param {object} param0 * @param {object} param0
* @param {Array<{pos: Vector, direction: enumDirection }>=} param0.slots The slots to eject on * @param {Array<{pos: Vector, direction: enumDirection, buffered?: boolean }>=} param0.slots The slots to eject on
* @param {boolean=} param0.renderFloatingItems Whether to render items even if they are not connected * @param {boolean=} param0.renderFloatingItems Whether to render items even if they are not connected
*/ */
constructor({ slots = [], renderFloatingItems = true }) { constructor({ slots = [], renderFloatingItems = true }) {
@ -49,7 +50,7 @@ export class ItemEjectorComponent extends Component {
} }
/** /**
* @param {Array<{pos: Vector, direction: enumDirection }>} slots The slots to eject on * @param {Array<{pos: Vector, direction: enumDirection, buffered?: boolean }>} slots The slots to eject on
*/ */
setSlots(slots) { setSlots(slots) {
/** @type {Array<ItemEjectorSlot>} */ /** @type {Array<ItemEjectorSlot>} */
@ -61,6 +62,7 @@ export class ItemEjectorComponent extends Component {
direction: slot.direction, direction: slot.direction,
item: null, item: null,
progress: 0, progress: 0,
nextItem: slot.buffered ? null : undefined,
cachedDestSlot: null, cachedDestSlot: null,
cachedTargetEntity: null, cachedTargetEntity: null,
}); });
@ -97,7 +99,7 @@ export class ItemEjectorComponent extends Component {
*/ */
canEjectOnSlot(slotIndex) { canEjectOnSlot(slotIndex) {
assert(slotIndex >= 0 && slotIndex < this.slots.length, "Invalid ejector slot: " + slotIndex); assert(slotIndex >= 0 && slotIndex < this.slots.length, "Invalid ejector slot: " + slotIndex);
return !this.slots[slotIndex].item; return !this.slots[slotIndex].item || this.slots[slotIndex].nextItem === null;
} }
/** /**
@ -123,6 +125,10 @@ export class ItemEjectorComponent extends Component {
if (!this.canEjectOnSlot(slotIndex)) { if (!this.canEjectOnSlot(slotIndex)) {
return false; return false;
} }
if (this.slots[slotIndex].item) {
this.slots[slotIndex].nextItem = item;
return true;
}
this.slots[slotIndex].item = item; this.slots[slotIndex].item = item;
this.slots[slotIndex].progress = 0; this.slots[slotIndex].progress = 0;
return true; return true;
@ -136,7 +142,12 @@ export class ItemEjectorComponent extends Component {
takeSlotItem(slotIndex) { takeSlotItem(slotIndex) {
const slot = this.slots[slotIndex]; const slot = this.slots[slotIndex];
const item = slot.item; const item = slot.item;
slot.item = null; if (slot.nextItem === undefined) {
slot.item = null;
} else {
slot.item = slot.nextItem;
slot.nextItem = null;
}
slot.progress = 0.0; slot.progress = 0.0;
return item; return item;
} }

View File

@ -182,7 +182,7 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
if (destPath) { if (destPath) {
// Try passing the item over // Try passing the item over
if (destPath.tryAcceptItem(item)) { if (destPath.tryAcceptItem(item)) {
sourceSlot.item = null; sourceEjectorComp.takeSlotItem(j);
} }
// Always stop here, since there can *either* be a belt path *or* // Always stop here, since there can *either* be a belt path *or*
@ -209,7 +209,7 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
item item
); );
} }
sourceSlot.item = null; sourceEjectorComp.takeSlotItem(j);
continue; continue;
} }
} }