Fix item filters being ignored

This commit is contained in:
tobspr 2020-08-10 22:04:38 +02:00
parent d2077f5009
commit 8d329990ef
5 changed files with 44 additions and 29 deletions

View File

@ -1009,25 +1009,8 @@ export class BeltPath extends BasicSerializableObject {
// Check if we have an item which is ready to be emitted // Check if we have an item which is ready to be emitted
const lastItem = this.items[this.items.length - 1]; const lastItem = this.items[this.items.length - 1];
if (lastItem && lastItem[_nextDistance] === 0 && this.acceptorTarget) { if (lastItem && lastItem[_nextDistance] === 0 && this.acceptorTarget) {
// Pass over the item if (this.tryHandOverItem(lastItem[_item])) {
if (
this.root.systemMgr.systems.itemEjector.tryPassOverItem(
lastItem[_item],
this.acceptorTarget.entity,
this.acceptorTarget.slot
)
) {
this.items.pop(); 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 * Computes a world space position from the given progress
* @param {number} progress * @param {number} progress

View File

@ -2,8 +2,6 @@ import { enumDirection, Vector } from "../../core/vector";
import { types } from "../../savegame/serialization"; import { types } from "../../savegame/serialization";
import { BeltPath } from "../belt_path"; import { BeltPath } from "../belt_path";
import { Component } from "../component"; import { Component } from "../component";
import { Entity } from "../entity";
import { enumLayer } from "../root";
export const curvedBeltLength = /* Math.PI / 4 */ 0.78; export const curvedBeltLength = /* Math.PI / 4 */ 0.78;
@ -43,7 +41,6 @@ export class BeltComponent extends Component {
} }
static getSchema() { static getSchema() {
// The followUpCache field is not serialized.
return { return {
direction: types.string, direction: types.string,
}; };
@ -63,9 +60,6 @@ export class BeltComponent extends Component {
this.direction = direction; this.direction = direction;
/** @type {Entity} */
this.followUpCache = null;
/** /**
* The path this belt is contained in, not serialized * The path this belt is contained in, not serialized
* @type {BeltPath} * @type {BeltPath}

View File

@ -1,6 +1,4 @@
import { Component } from "../component"; import { Component } from "../component";
import { ShapeDefinition } from "../shape_definition";
import { types } from "../../savegame/serialization";
export class HubComponent extends Component { export class HubComponent extends Component {
static getId() { static getId() {

View File

@ -2,7 +2,6 @@ import { enumDirection, enumInvertedDirections, Vector } from "../../core/vector
import { types } from "../../savegame/serialization"; import { types } from "../../savegame/serialization";
import { BaseItem, enumItemType } from "../base_item"; import { BaseItem, enumItemType } from "../base_item";
import { Component } from "../component"; import { Component } from "../component";
import { enumLayer } from "../root";
/** @typedef {{ /** @typedef {{
* pos: Vector, * pos: Vector,

View File

@ -347,8 +347,8 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
assert(hubComponent, "Hub item processor has no hub component"); assert(hubComponent, "Hub item processor has no hub component");
for (let i = 0; i < items.length; ++i) { for (let i = 0; i < items.length; ++i) {
const shapeItem = /** @type {ShapeItem} */ (items[i].item); const item = /** @type {ShapeItem} */ (items[i].item);
this.root.hubGoals.handleDefinitionDelivered(shapeItem.definition); this.root.hubGoals.handleDefinitionDelivered(item.definition);
} }
break; break;