From eaa46ec914ea700c5f3930a2ac46aa4145c5f54e Mon Sep 17 00:00:00 2001 From: isaisstillalive Date: Tue, 30 Jun 2020 00:25:13 +0900 Subject: [PATCH] Add chainable splitter system mock --- src/js/game/game_system_manager.js | 6 +++++ src/js/game/systems/chainable_splitter.js | 33 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/js/game/systems/chainable_splitter.js diff --git a/src/js/game/game_system_manager.js b/src/js/game/game_system_manager.js index 144380b2..64577a77 100644 --- a/src/js/game/game_system_manager.js +++ b/src/js/game/game_system_manager.js @@ -13,6 +13,7 @@ import { HubSystem } from "./systems/hub"; import { StaticMapEntitySystem } from "./systems/static_map_entity"; import { ItemAcceptorSystem } from "./systems/item_acceptor"; import { StorageSystem } from "./systems/storage"; +import { ChainableSplitterSystem } from "./systems/chainable_splitter"; import { EnergyGeneratorSystem } from "./systems/energy_generator"; import { WiredPinsSystem } from "./systems/wired_pins"; @@ -58,6 +59,9 @@ export class GameSystemManager { /** @type {StorageSystem} */ storage: null, + /** @type {ChainableSplitterSystem} */ + chainableSplitter: null, + /** @type {EnergyGeneratorSystem} */ energyGenerator: null, @@ -90,6 +94,8 @@ export class GameSystemManager { add("storage", StorageSystem); + add("chainableSplitter", ChainableSplitterSystem); + add("itemProcessor", ItemProcessorSystem); add("itemEjector", ItemEjectorSystem); diff --git a/src/js/game/systems/chainable_splitter.js b/src/js/game/systems/chainable_splitter.js new file mode 100644 index 00000000..1bd44c36 --- /dev/null +++ b/src/js/game/systems/chainable_splitter.js @@ -0,0 +1,33 @@ +import { GameSystemWithFilter } from "../game_system_with_filter"; +import { ChainableSplitterComponent } from "../components/chainable_splitter"; +import { Entity } from "../entity"; +import { DrawParameters } from "../../core/draw_parameters"; +import { formatBigNumber, lerp } from "../../core/utils"; +import { Loader } from "../../core/loader"; +import { enumLayer } from "../root"; + +export class ChainableSplitterSystem extends GameSystemWithFilter { + constructor(root) { + super(root, [ChainableSplitterComponent]); + } + + update() { + for (let i = 0; i < this.allEntities.length; ++i) { + const entity = this.allEntities[i]; + const splitterComp = entity.components.ChainableSplitter; + + if (splitterComp.inputItem === null) { + continue; + } + + const ejectorComp = entity.components.ItemEjector; + + const nextSlot = ejectorComp.getFirstFreeSlot(enumLayer.regular); + if (nextSlot !== null) { + if (ejectorComp.tryEject(nextSlot, splitterComp.inputItem)) { + splitterComp.inputItem = null; + } + } + } + } +}