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

Add chainable splitter component

This commit is contained in:
isaisstillalive 2020-06-29 23:50:44 +09:00
parent 8667739e5e
commit b7f4551487
4 changed files with 62 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import { UndergroundBeltComponent } from "./components/underground_belt";
import { UnremovableComponent } from "./components/unremovable";
import { HubComponent } from "./components/hub";
import { StorageComponent } from "./components/storage";
import { ChainableSplitterComponent } from "./components/chainable_splitter";
import { EnergyGeneratorComponent } from "./components/energy_generator";
import { WiredPinsComponent } from "./components/wired_pins";
@ -25,6 +26,7 @@ export function initComponentRegistry() {
gComponentRegistry.register(UnremovableComponent);
gComponentRegistry.register(HubComponent);
gComponentRegistry.register(StorageComponent);
gComponentRegistry.register(ChainableSplitterComponent);
gComponentRegistry.register(EnergyGeneratorComponent);
gComponentRegistry.register(WiredPinsComponent);

View File

@ -0,0 +1,46 @@
import { globalConfig } from "../../core/config";
import { types } from "../../savegame/serialization";
import { Component } from "../component";
import { BaseItem } from "../base_item";
import { gItemRegistry } from "../../core/global_registries";
export class ChainableSplitterComponent extends Component {
static getId() {
return "ChainableSplitter";
}
static getSchema() {
return {
chainable: types.bool,
inputItem: types.nullable(types.obj(gItemRegistry)),
ejected: types.bool,
};
}
duplicateWithoutContents() {
return new ChainableSplitterComponent({
chainable: this.chainable,
});
}
constructor({ chainable = false }) {
super();
this.chainable = chainable;
this.inputItem = null;
this.ejected = false;
}
/**
* Tries to take the item
* @param {BaseItem} item
*/
tryTakeItem(item) {
if (this.inputItem !== null) {
return false;
}
this.inputItem = item;
return true;
}
}

View File

@ -10,6 +10,7 @@ import { UndergroundBeltComponent } from "./components/underground_belt";
import { UnremovableComponent } from "./components/unremovable";
import { HubComponent } from "./components/hub";
import { StorageComponent } from "./components/storage";
import { ChainableSplitterComponent } from "./components/chainable_splitter";
import { EnergyGeneratorComponent } from "./components/energy_generator";
import { WiredPinsComponent } from "./components/wired_pins";
/* typehints:end */
@ -55,6 +56,9 @@ export class EntityComponentStorage {
/** @type {StorageComponent} */
this.Storage;
/** @type {ChainableSplitterComponent} */
this.ChainableSplitter;
/** @type {EnergyGeneratorComponent} */
this.EnergyGenerator;

View File

@ -306,6 +306,16 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
return false;
}
const chainableSplitterComp = receiver.components.ChainableSplitter;
if (chainableSplitterComp) {
// Its an chainable splitter ..
if (chainableSplitterComp.tryTakeItem(item)) {
return true;
}
// Chainable splitter can have nothing else
return false;
}
const energyGeneratorComp = receiver.components.EnergyGenerator;
if (energyGeneratorComp) {
if (energyGeneratorComp.tryTakeItem(item, slotIndex)) {