1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Add constant signal emitters

This commit is contained in:
tobspr
2020-08-12 21:05:32 +02:00
parent c7b3cc1675
commit f4ac6dfe03
31 changed files with 1095 additions and 773 deletions

View File

@@ -0,0 +1,30 @@
import { gItemRegistry } from "../../core/global_registries";
import { types } from "../../savegame/serialization";
import { Component } from "../component";
import { BaseItem } from "../base_item";
export class ConstantSignalComponent extends Component {
static getId() {
return "ConstantSignal";
}
static getSchema() {
return {
signal: types.nullable(types.obj(gItemRegistry)),
};
}
duplicateWithoutContents() {
return new ConstantSignalComponent({ signal: this.signal });
}
/**
*
* @param {object} param0
* @param {BaseItem=} param0.signal The signal to store
*/
constructor({ signal = null }) {
super();
this.signal = signal;
}
}

View File

@@ -87,25 +87,7 @@ export class ItemAcceptorComponent extends Component {
*/
canAcceptItem(slotIndex, item) {
const slot = this.slots[slotIndex];
return this.filterMatches(slot.filter, item);
}
/**
* Returns if the given filter matches
* @param {enumItemType|null} filter
* @param {BaseItem} item
*/
filterMatches(filter, item) {
if (!filter) {
return true;
}
const itemType = item.getItemType();
if (filter === enumItemType.genericEnergy) {
return itemType === enumItemType.positiveEnergy || itemType === enumItemType.negativeEnergy;
}
return itemType === filter;
return !slot.filter || slot.filter === item.getItemType();
}
/**