1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Refactor entity cloning (#671)

This commit is contained in:
Exund
2020-09-19 21:41:48 +02:00
committed by GitHub
parent 1f3991301d
commit c4f2379010
20 changed files with 39 additions and 127 deletions

View File

@@ -40,10 +40,6 @@ export class BeltComponent extends Component {
return "Belt";
}
duplicateWithoutContents() {
return new BeltComponent({ direction: this.direction });
}
/**
*
* @param {object} param0

View File

@@ -8,10 +8,6 @@ export class BeltReaderComponent extends Component {
return "BeltReader";
}
duplicateWithoutContents() {
return new BeltReaderComponent();
}
static getSchema() {
return {
lastItem: types.nullable(typeItemSingleton),

View File

@@ -30,21 +30,6 @@ export class BeltUnderlaysComponent extends Component {
return "BeltUnderlays";
}
duplicateWithoutContents() {
const beltUnderlaysCopy = [];
for (let i = 0; i < this.underlays.length; ++i) {
const underlay = this.underlays[i];
beltUnderlaysCopy.push({
pos: underlay.pos.copy(),
direction: underlay.direction,
});
}
return new BeltUnderlaysComponent({
underlays: beltUnderlaysCopy,
});
}
/**
* @param {object} param0
* @param {Array<BeltUnderlayTile>=} param0.underlays Where to render belt underlays

View File

@@ -15,8 +15,12 @@ export class ConstantSignalComponent extends Component {
};
}
duplicateWithoutContents() {
return new ConstantSignalComponent({ signal: this.signal });
/**
* Copy the current state to another component
* @param {ConstantSignalComponent} otherComponent
*/
copyAdditionalStateTo(otherComponent) {
otherComponent.signal = this.signal;
}
/**

View File

@@ -4,8 +4,4 @@ export class DisplayComponent extends Component {
static getId() {
return "Display";
}
duplicateWithoutContents() {
return new DisplayComponent();
}
}

View File

@@ -28,22 +28,6 @@ export class ItemAcceptorComponent extends Component {
return "ItemAcceptor";
}
duplicateWithoutContents() {
const slotsCopy = [];
for (let i = 0; i < this.slots.length; ++i) {
const slot = this.slots[i];
slotsCopy.push({
pos: slot.pos.copy(),
directions: slot.directions.slice(),
filter: slot.filter,
});
}
return new ItemAcceptorComponent({
slots: slotsCopy,
});
}
/**
*
* @param {object} param0

View File

@@ -35,22 +35,6 @@ export class ItemEjectorComponent extends Component {
};
}
duplicateWithoutContents() {
const slotsCopy = [];
for (let i = 0; i < this.slots.length; ++i) {
const slot = this.slots[i];
slotsCopy.push({
pos: slot.pos.copy(),
direction: slot.direction,
});
}
return new ItemEjectorComponent({
slots: slotsCopy,
renderFloatingItems: this.renderFloatingItems,
});
}
/**
*
* @param {object} param0

View File

@@ -48,14 +48,6 @@ export class ItemProcessorComponent extends Component {
};
}
duplicateWithoutContents() {
return new ItemProcessorComponent({
processorType: this.type,
processingRequirement: this.processingRequirement,
inputsPerCharge: this.inputsPerCharge,
});
}
/**
*
* @param {object} param0

View File

@@ -12,8 +12,12 @@ export class LeverComponent extends Component {
};
}
duplicateWithoutContents() {
return new LeverComponent({ toggled: this.toggled });
/**
* Copy the current state to another component
* @param {LeverComponent} otherComponent
*/
copyAdditionalStateTo(otherComponent) {
otherComponent.toggled = this.toggled;
}
/**

View File

@@ -22,10 +22,6 @@ export class LogicGateComponent extends Component {
return "LogicGate";
}
duplicateWithoutContents() {
return new LogicGateComponent({ type: this.type });
}
/**
*
* @param {object} param0

View File

@@ -19,12 +19,6 @@ export class MinerComponent extends Component {
};
}
duplicateWithoutContents() {
return new MinerComponent({
chainable: this.chainable,
});
}
constructor({ chainable = false }) {
super();
this.lastMiningTime = 0;

View File

@@ -63,7 +63,11 @@ export class StaticMapEntityComponent extends Component {
return getBuildingDataFromCode(this.code).metaInstance;
}
duplicateWithoutContents() {
/**
* Copy the current state to another component
* @param {Component} otherComponent
*/
copyAdditionalStateTo(otherComponent) {
return new StaticMapEntityComponent({
origin: this.origin.copy(),
rotation: this.rotation,

View File

@@ -17,10 +17,6 @@ export class StorageComponent extends Component {
};
}
duplicateWithoutContents() {
return new StorageComponent({ maximumStorage: this.maximumStorage });
}
/**
* @param {object} param0
* @param {number=} param0.maximumStorage How much this storage can hold

View File

@@ -29,13 +29,6 @@ export class UndergroundBeltComponent extends Component {
};
}
duplicateWithoutContents() {
return new UndergroundBeltComponent({
mode: this.mode,
tier: this.tier,
});
}
/**
*
* @param {object} param0

View File

@@ -13,10 +13,6 @@ export class WireComponent extends Component {
return "Wire";
}
duplicateWithoutContents() {
return new WireComponent({ type: this.type });
}
/**
* @param {object} param0
* @param {enumWireType=} param0.type

View File

@@ -5,10 +5,6 @@ export class WireTunnelComponent extends Component {
return "WireTunnel";
}
duplicateWithoutContents() {
return new WireTunnelComponent({ multipleDirections: this.multipleDirections });
}
/**
* @param {object} param0
* @param {boolean=} param0.multipleDirections

View File

@@ -49,20 +49,6 @@ export class WiredPinsComponent extends Component {
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