From 3425cb149d83faad6baa3f2c2095bebaa57e2cb9 Mon Sep 17 00:00:00 2001 From: ZygZagGaming <46930418+ZygZagGaming@users.noreply.github.com> Date: Mon, 7 Feb 2022 20:33:18 -0500 Subject: [PATCH] added a workaround for mods this should allow mod devs to work around the semi-hacky logic for item accepting by registering "filters" in the MOD_ITEM_FILTERS object in item_ejector.js --- src/js/game/belt_path.js | 18 +++++++++++++++++- src/js/game/systems/item_ejector.js | 19 ++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/js/game/belt_path.js b/src/js/game/belt_path.js index e1b466e9..11941d6d 100644 --- a/src/js/game/belt_path.js +++ b/src/js/game/belt_path.js @@ -11,6 +11,7 @@ import { BaseItem } from "./base_item"; import { Entity } from "./entity"; import { typeItemSingleton } from "./item_resolver"; import { GameRoot } from "./root"; +import { MOD_ITEM_FILTERS } from "./systems/item_ejector"; const logger = createLogger("belt_path"); @@ -315,7 +316,7 @@ export class BeltPath extends BasicSerializableObject { const systems = this.root.systemMgr.systems; const hubGoals = this.root.hubGoals; - // NOTICE: THIS IS COPIED FROM THE ITEM EJECTOR SYSTEM FOR PEROFMANCE REASONS + // NOTICE: THIS IS COPIED FROM THE ITEM EJECTOR SYSTEM FOR PERFORMANCE REASONS const itemProcessorComp = entity.components.ItemProcessor; if (itemProcessorComp) { @@ -361,6 +362,21 @@ export class BeltPath extends BasicSerializableObject { } }; } + + return function (item) { + // it could be a custom mod case + // let's check if it is any of them + var any = false; // so that all matching components can process it + for (let id in MOD_ITEM_FILTERS) { + if (entity.components[id]) { + let handler = MOD_ITEM_FILTERS[id]; + if (handler(item, entity, matchingSlotIndex)) any = true; + else return false; + } + } + + return any; + }; } // Following code will be compiled out outside of dev versions diff --git a/src/js/game/systems/item_ejector.js b/src/js/game/systems/item_ejector.js index 8c7468ad..ad4e64b5 100644 --- a/src/js/game/systems/item_ejector.js +++ b/src/js/game/systems/item_ejector.js @@ -14,6 +14,12 @@ import { MapChunkView } from "../map_chunk_view"; const logger = createLogger("systems/ejector"); +/** + * Key is component id, value is function to handle whether or not item can enter. + * @type {Object boolean>} + */ +export const MOD_ITEM_FILTERS = {}; + export class ItemEjectorSystem extends GameSystemWithFilter { constructor(root) { super(root, [ItemEjectorComponent]); @@ -294,7 +300,18 @@ export class ItemEjectorSystem extends GameSystemWithFilter { } } - return false; + // it could be a custom mod case + // let's check if it is any of them + var any = false; // so that all matching components can process it + for (let id in MOD_ITEM_FILTERS) { + if (receiver.components[id]) { + let handler = MOD_ITEM_FILTERS[id]; + if (handler(item, receiver, slotIndex)) any = true; + else return false; + } + } + + return any; } /**