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:
30
src/js/game/components/constant_signal.js
Normal file
30
src/js/game/components/constant_signal.js
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user