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/wired_pins.js
2020-08-12 20:11:24 +02:00

72 lines
1.7 KiB
JavaScript

import { enumDirection, Vector } from "../../core/vector";
import { BaseItem } from "../base_item";
import { Component } from "../component";
/** @enum {string} */
export const enumPinSlotType = {
logicalEjector: "logicalEjector",
logicalAcceptor: "logicalAcceptor",
};
/** @typedef {{
* pos: Vector,
* type: enumPinSlotType,
* direction: enumDirection
* }} WirePinSlotDefinition */
/** @typedef {{
* pos: Vector,
* type: enumPinSlotType,
* direction: enumDirection,
* value: BaseItem
* }} WirePinSlot */
export class WiredPinsComponent extends Component {
static getId() {
return "WiredPins";
}
/**
*
* @param {object} param0
* @param {Array<WirePinSlotDefinition>} param0.slots
*/
constructor({ slots = [] }) {
super();
this.setSlots(slots);
}
duplicateWithoutContents() {
const slots = [];
for (let i = 0; i < this.slots.length; ++i) {
const slot = this.slots[i];
slots.push({
pos: slot.pos.copy(),
type: slot.type,
direction: slot.direction,
});
}
return new WiredPinsComponent({ slots });
}
/**
* Sets the slots of this building
* @param {Array<WirePinSlotDefinition>} slots
*/
setSlots(slots) {
/** @type {Array<WirePinSlot>} */
this.slots = [];
for (let i = 0; i < slots.length; ++i) {
const slotData = slots[i];
this.slots.push({
pos: slotData.pos,
type: slotData.type,
direction: slotData.direction,
value: null,
});
}
}
}