2020-06-24 20:23:10 +00:00
|
|
|
import { Component } from "../component";
|
2020-06-28 17:34:10 +00:00
|
|
|
import { Vector, enumDirection } from "../../core/vector";
|
2020-06-24 20:23:10 +00:00
|
|
|
import { types } from "../../savegame/serialization";
|
|
|
|
|
|
|
|
/** @enum {string} */
|
|
|
|
export const enumPinSlotType = {
|
2020-06-28 17:34:10 +00:00
|
|
|
positiveEnergyEjector: "positiveEnergyEjector",
|
|
|
|
negativeEnergyEjector: "negativeEnergyEjector",
|
|
|
|
positiveEnergyAcceptor: "positiveEnergyAcceptor",
|
2020-06-28 18:28:46 +00:00
|
|
|
negativeEnergyAcceptor: "negativeEnergyAcceptor",
|
2020-06-24 20:23:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @typedef {{
|
|
|
|
* pos: Vector,
|
2020-06-28 17:34:10 +00:00
|
|
|
* type: enumPinSlotType,
|
|
|
|
* direction: enumDirection
|
2020-06-24 20:23:10 +00:00
|
|
|
* }} WirePinSlotDefinition */
|
|
|
|
|
|
|
|
/** @typedef {{
|
|
|
|
* pos: Vector,
|
|
|
|
* type: enumPinSlotType,
|
2020-06-28 17:34:10 +00:00
|
|
|
* direction: enumDirection
|
2020-06-24 20:23:10 +00:00
|
|
|
* }} WirePinSlot */
|
|
|
|
|
|
|
|
export class WiredPinsComponent extends Component {
|
|
|
|
static getId() {
|
|
|
|
return "WiredPins";
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSchema() {
|
|
|
|
return {
|
|
|
|
slots: types.array(
|
|
|
|
types.structured({
|
|
|
|
pos: types.vector,
|
|
|
|
type: types.enum(enumPinSlotType),
|
|
|
|
})
|
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {object} param0
|
|
|
|
* @param {Array<WirePinSlotDefinition>} param0.slots
|
|
|
|
*/
|
2020-06-28 09:44:30 +00:00
|
|
|
constructor({ slots = [] }) {
|
2020-06-24 20:23:10 +00:00
|
|
|
super();
|
|
|
|
this.setSlots(slots);
|
|
|
|
}
|
|
|
|
|
2020-07-05 14:56:01 +00:00
|
|
|
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 });
|
|
|
|
}
|
|
|
|
|
2020-06-24 20:23:10 +00:00
|
|
|
/**
|
|
|
|
* 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,
|
2020-06-28 17:34:10 +00:00
|
|
|
direction: slotData.direction,
|
2020-06-24 20:23:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|