diff --git a/src/js/game/belt_path.js b/src/js/game/belt_path.js index 41dffd73..5abcef3f 100644 --- a/src/js/game/belt_path.js +++ b/src/js/game/belt_path.js @@ -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 diff --git a/src/js/game/components/belt.js b/src/js/game/components/belt.js index 2772dc05..0c90d24a 100644 --- a/src/js/game/components/belt.js +++ b/src/js/game/components/belt.js @@ -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} diff --git a/src/js/game/components/hub.js b/src/js/game/components/hub.js index e038cf3e..fb88d6f6 100644 --- a/src/js/game/components/hub.js +++ b/src/js/game/components/hub.js @@ -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() { diff --git a/src/js/game/components/item_acceptor.js b/src/js/game/components/item_acceptor.js index b9faa486..3e3ecbeb 100644 --- a/src/js/game/components/item_acceptor.js +++ b/src/js/game/components/item_acceptor.js @@ -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, diff --git a/src/js/game/systems/item_processor.js b/src/js/game/systems/item_processor.js index 5baecc4e..e5d32d4d 100644 --- a/src/js/game/systems/item_processor.js +++ b/src/js/game/systems/item_processor.js @@ -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;