Fix item filters being ignored
This commit is contained in:
parent
d2077f5009
commit
8d329990ef
|
@ -1009,25 +1009,8 @@ export class BeltPath extends BasicSerializableObject {
|
|||
// Check if we have an item which is ready to be emitted
|
||||
const lastItem = this.items[this.items.length - 1];
|
||||
if (lastItem && lastItem[_nextDistance] === 0 && this.acceptorTarget) {
|
||||
// Pass over the item
|
||||
if (
|
||||
this.root.systemMgr.systems.itemEjector.tryPassOverItem(
|
||||
lastItem[_item],
|
||||
this.acceptorTarget.entity,
|
||||
this.acceptorTarget.slot
|
||||
)
|
||||
) {
|
||||
if (this.tryHandOverItem(lastItem[_item])) {
|
||||
this.items.pop();
|
||||
|
||||
// Also trigger animation
|
||||
const targetAcceptorComp = this.acceptorTarget.entity.components.ItemAcceptor;
|
||||
if (targetAcceptorComp) {
|
||||
targetAcceptorComp.onItemAccepted(
|
||||
this.acceptorTarget.slot,
|
||||
this.acceptorTarget.direction,
|
||||
lastItem[_item]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1036,6 +1019,47 @@ export class BeltPath extends BasicSerializableObject {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to hand over the item to the end entity
|
||||
* @param {BaseItem} item
|
||||
*/
|
||||
tryHandOverItem(item) {
|
||||
if (!this.acceptorTarget) {
|
||||
return;
|
||||
}
|
||||
|
||||
const targetAcceptorComp = this.acceptorTarget.entity.components.ItemAcceptor;
|
||||
|
||||
// Check if the acceptor has a filter for example
|
||||
if (targetAcceptorComp && !targetAcceptorComp.canAcceptItem(this.acceptorTarget.slot, item)) {
|
||||
// Well, this item is not accepted
|
||||
return false;
|
||||
}
|
||||
|
||||
// Try to pass over
|
||||
if (
|
||||
this.root.systemMgr.systems.itemEjector.tryPassOverItem(
|
||||
item,
|
||||
this.acceptorTarget.entity,
|
||||
this.acceptorTarget.slot
|
||||
)
|
||||
) {
|
||||
// Trigger animation on the acceptor comp
|
||||
const targetAcceptorComp = this.acceptorTarget.entity.components.ItemAcceptor;
|
||||
if (targetAcceptorComp) {
|
||||
targetAcceptorComp.onItemAccepted(
|
||||
this.acceptorTarget.slot,
|
||||
this.acceptorTarget.direction,
|
||||
item
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a world space position from the given progress
|
||||
* @param {number} progress
|
||||
|
|
|
@ -2,8 +2,6 @@ import { enumDirection, Vector } from "../../core/vector";
|
|||
import { types } from "../../savegame/serialization";
|
||||
import { BeltPath } from "../belt_path";
|
||||
import { Component } from "../component";
|
||||
import { Entity } from "../entity";
|
||||
import { enumLayer } from "../root";
|
||||
|
||||
export const curvedBeltLength = /* Math.PI / 4 */ 0.78;
|
||||
|
||||
|
@ -43,7 +41,6 @@ export class BeltComponent extends Component {
|
|||
}
|
||||
|
||||
static getSchema() {
|
||||
// The followUpCache field is not serialized.
|
||||
return {
|
||||
direction: types.string,
|
||||
};
|
||||
|
@ -63,9 +60,6 @@ export class BeltComponent extends Component {
|
|||
|
||||
this.direction = direction;
|
||||
|
||||
/** @type {Entity} */
|
||||
this.followUpCache = null;
|
||||
|
||||
/**
|
||||
* The path this belt is contained in, not serialized
|
||||
* @type {BeltPath}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import { Component } from "../component";
|
||||
import { ShapeDefinition } from "../shape_definition";
|
||||
import { types } from "../../savegame/serialization";
|
||||
|
||||
export class HubComponent extends Component {
|
||||
static getId() {
|
||||
|
|
|
@ -2,7 +2,6 @@ import { enumDirection, enumInvertedDirections, Vector } from "../../core/vector
|
|||
import { types } from "../../savegame/serialization";
|
||||
import { BaseItem, enumItemType } from "../base_item";
|
||||
import { Component } from "../component";
|
||||
import { enumLayer } from "../root";
|
||||
|
||||
/** @typedef {{
|
||||
* pos: Vector,
|
||||
|
|
|
@ -347,8 +347,8 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||
assert(hubComponent, "Hub item processor has no hub component");
|
||||
|
||||
for (let i = 0; i < items.length; ++i) {
|
||||
const shapeItem = /** @type {ShapeItem} */ (items[i].item);
|
||||
this.root.hubGoals.handleDefinitionDelivered(shapeItem.definition);
|
||||
const item = /** @type {ShapeItem} */ (items[i].item);
|
||||
this.root.hubGoals.handleDefinitionDelivered(item.definition);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue