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

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
This commit is contained in:
ZygZagGaming 2022-02-07 20:33:18 -05:00
parent 86b104080f
commit 3425cb149d
2 changed files with 35 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import { BaseItem } from "./base_item";
import { Entity } from "./entity"; import { Entity } from "./entity";
import { typeItemSingleton } from "./item_resolver"; import { typeItemSingleton } from "./item_resolver";
import { GameRoot } from "./root"; import { GameRoot } from "./root";
import { MOD_ITEM_FILTERS } from "./systems/item_ejector";
const logger = createLogger("belt_path"); const logger = createLogger("belt_path");
@ -315,7 +316,7 @@ export class BeltPath extends BasicSerializableObject {
const systems = this.root.systemMgr.systems; const systems = this.root.systemMgr.systems;
const hubGoals = this.root.hubGoals; 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; const itemProcessorComp = entity.components.ItemProcessor;
if (itemProcessorComp) { 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 // Following code will be compiled out outside of dev versions

View File

@ -14,6 +14,12 @@ import { MapChunkView } from "../map_chunk_view";
const logger = createLogger("systems/ejector"); const logger = createLogger("systems/ejector");
/**
* Key is component id, value is function to handle whether or not item can enter.
* @type {Object<string, (item: BaseItem, reciever: Entity, slot: number) => boolean>}
*/
export const MOD_ITEM_FILTERS = {};
export class ItemEjectorSystem extends GameSystemWithFilter { export class ItemEjectorSystem extends GameSystemWithFilter {
constructor(root) { constructor(root) {
super(root, [ItemEjectorComponent]); 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;
} }
/** /**