mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Further progress on the energy generator / wires, fix translations
This commit is contained in:
34
src/js/game/components/energy_consumer.js
Normal file
34
src/js/game/components/energy_consumer.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Component } from "../component";
|
||||
import { types } from "../../savegame/serialization";
|
||||
import { Vector } from "../../core/vector";
|
||||
|
||||
export class EnergyConsumerComponent extends Component {
|
||||
static getId() {
|
||||
return "EnergyConsumer";
|
||||
}
|
||||
|
||||
static getSchema() {
|
||||
return {
|
||||
bufferSize: types.uint,
|
||||
perCharge: types.uint,
|
||||
stored: types.uint,
|
||||
batteryPosition: types.vector,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {object} param0
|
||||
* @param {number} param0.bufferSize How much energy this consumer can store
|
||||
* @param {number} param0.perCharge How much energy this consumer needs per charge
|
||||
* @param {Vector} param0.batteryPosition world space render offset of the battery icon
|
||||
*/
|
||||
constructor({ bufferSize = 3, perCharge = 1, batteryPosition = new Vector() }) {
|
||||
super();
|
||||
this.bufferSize = bufferSize;
|
||||
this.perCharge = perCharge;
|
||||
this.batteryPosition = batteryPosition;
|
||||
|
||||
this.stored = 0;
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,6 @@ import { ShapeItem } from "../items/shape_item";
|
||||
|
||||
const maxQueueSize = 20;
|
||||
|
||||
export const ENERGY_GENERATOR_EJECT_SLOT = 0;
|
||||
export const ENERGY_GENERATOR_ACCEPT_SLOT = 4;
|
||||
|
||||
export class EnergyGeneratorComponent extends Component {
|
||||
static getId() {
|
||||
return "EnergyGenerator";
|
||||
@@ -24,8 +21,9 @@ export class EnergyGeneratorComponent extends Component {
|
||||
*
|
||||
* @param {object} param0
|
||||
* @param {string} param0.requiredKey Which shape this generator needs, can be null if not computed yet
|
||||
* @param {number} param0.acceptorSlotIndex
|
||||
*/
|
||||
constructor({ requiredKey }) {
|
||||
constructor({ requiredKey, acceptorSlotIndex = 0 }) {
|
||||
super();
|
||||
this.requiredKey = requiredKey;
|
||||
|
||||
@@ -34,6 +32,12 @@ export class EnergyGeneratorComponent extends Component {
|
||||
* @type {number}
|
||||
*/
|
||||
this.itemsInQueue = 0;
|
||||
|
||||
/**
|
||||
* Stores which slot accepts the waste
|
||||
* @type {number}
|
||||
*/
|
||||
this.acceptorSlotIndex = acceptorSlotIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +46,7 @@ export class EnergyGeneratorComponent extends Component {
|
||||
* @param {number} slot
|
||||
*/
|
||||
tryTakeItem(item, slot) {
|
||||
if (slot === ENERGY_GENERATOR_ACCEPT_SLOT) {
|
||||
if (slot === this.acceptorSlotIndex) {
|
||||
// this is the acceptor slot on the wires layer
|
||||
// just destroy it
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user