You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tobspr_shapez.io/src/js/game/components/miner.js

59 lines
1.3 KiB

4 years ago
import { types } from "../../savegame/serialization";
import { BaseItem } from "../base_item";
import { Component } from "../component";
import { typeItemSingleton } from "../item_resolver";
const chainBufferSize = 3;
4 years ago
export class MinerComponent extends Component {
static getId() {
return "Miner";
}
static getSchema() {
// cachedMinedItem is not serialized.
4 years ago
return {
lastMiningTime: types.ufloat,
itemChainBuffer: types.array(typeItemSingleton),
4 years ago
};
}
duplicateWithoutContents() {
return new MinerComponent({
chainable: this.chainable,
});
}
constructor({ chainable = false }) {
4 years ago
super();
this.lastMiningTime = 0;
this.chainable = chainable;
/**
* Stores items from other miners which were chained to this
* miner.
* @type {Array<BaseItem>}
*/
this.itemChainBuffer = [];
/**
* @type {BaseItem}
*/
this.cachedMinedItem = null;
}
/**
*
* @param {BaseItem} item
*/
tryAcceptChainedItem(item) {
if (this.itemChainBuffer.length > chainBufferSize) {
// Well, this one is full
return false;
}
this.itemChainBuffer.push(item);
return true;
4 years ago
}
}