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/wired_pins.js

86 lines
2.1 KiB

import { enumDirection, Vector } from "../../core/vector";
import { BaseItem } from "../base_item";
import { Component } from "../component";
import { types } from "../../savegame/serialization";
import { typeItemSingleton } from "../item_resolver";
/** @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,
* linkedNetwork: import("../systems/wire").WireNetwork
* }} WirePinSlot */
export class WiredPinsComponent extends Component {
static getId() {
return "WiredPins";
}
static getSchema() {
return {
slots: types.array(
types.structured({
value: types.nullable(typeItemSingleton),
})
),
};
}
/**
*
* @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,
linkedNetwork: null,
});
}
}
}