1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2024-10-27 20:34:29 +00:00
tobspr_shapez.io/src/js/game/components/miner.js

65 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-05-09 14:45:23 +00:00
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";
const chainBufferSize = 3;
2020-05-09 14:45:23 +00:00
export class MinerComponent extends Component {
static getId() {
return "Miner";
}
static getSchema() {
return {
lastMiningTime: types.ufloat,
chainable: types.bool,
minedItem: types.nullable(types.obj(gItemRegistry)),
itemChainBuffer: types.array(types.obj(gItemRegistry)),
2020-05-09 14:45:23 +00:00
};
}
2020-05-27 12:30:59 +00:00
duplicateWithoutContents() {
return new MinerComponent({
chainable: this.chainable,
2020-06-16 20:21:45 +00:00
minedItem: this.minedItem,
2020-05-27 12:30:59 +00:00
});
}
2020-05-09 14:45:23 +00:00
/**
2020-06-16 20:21:45 +00:00
* @param {{chainable?: boolean, minedItem?: BaseItem}} param0
2020-05-09 14:45:23 +00:00
*/
constructor({ chainable = false, minedItem = null }) {
2020-05-09 14:45:23 +00:00
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.minedItem = minedItem;
}
/**
*
* @param {BaseItem} item
*/
tryAcceptChainedItem(item) {
if (this.itemChainBuffer.length > chainBufferSize) {
// Well, this one is full
return false;
}
this.itemChainBuffer.push(item);
return true;
2020-05-09 14:45:23 +00:00
}
}