mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-02-19 06:19:19 +00:00
Add Serializer/Deserializer
This commit is contained in:
parent
b0cc9539d7
commit
f88b3f668f
@ -11,7 +11,12 @@ import { T } from "../../translations";
|
||||
import { formatItemsPerSecond } from "../../core/utils";
|
||||
|
||||
/** @enum {string} */
|
||||
export const enumSplitterVariants = { compact: "compact", compactInverse: "compact-inverse" };
|
||||
export const enumSplitterVariants = {
|
||||
compact: "compact",
|
||||
compactInverse: "compact-inverse",
|
||||
serializer: "serializer",
|
||||
deserializer: "deserializer",
|
||||
};
|
||||
|
||||
export class MetaSplitterBuilding extends MetaBuilding {
|
||||
constructor() {
|
||||
@ -21,6 +26,8 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
||||
getDimensions(variant) {
|
||||
switch (variant) {
|
||||
case defaultBuildingVariant:
|
||||
case enumSplitterVariants.serializer:
|
||||
case enumSplitterVariants.deserializer:
|
||||
return new Vector(2, 1);
|
||||
case enumSplitterVariants.compact:
|
||||
case enumSplitterVariants.compactInverse:
|
||||
@ -53,6 +60,8 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
||||
defaultBuildingVariant,
|
||||
enumSplitterVariants.compact,
|
||||
enumSplitterVariants.compactInverse,
|
||||
enumSplitterVariants.serializer,
|
||||
enumSplitterVariants.deserializer,
|
||||
];
|
||||
}
|
||||
return super.getAvailableVariants(root);
|
||||
@ -132,6 +141,9 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
||||
{ pos: new Vector(1, 0), direction: enumDirection.top },
|
||||
];
|
||||
|
||||
entity.components.ItemProcessor.inputsPerCharge = 1;
|
||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.splitter;
|
||||
|
||||
break;
|
||||
}
|
||||
case enumSplitterVariants.compact:
|
||||
@ -159,6 +171,57 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
||||
];
|
||||
|
||||
entity.components.ItemProcessor.inputsPerCharge = 1;
|
||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.splitter;
|
||||
|
||||
break;
|
||||
}
|
||||
case enumSplitterVariants.serializer: {
|
||||
entity.components.ItemAcceptor.setSlots([
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
directions: [enumDirection.bottom],
|
||||
},
|
||||
{
|
||||
pos: new Vector(1, 0),
|
||||
directions: [enumDirection.bottom],
|
||||
},
|
||||
]);
|
||||
|
||||
entity.components.ItemEjector.setSlots([
|
||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
||||
]);
|
||||
|
||||
entity.components.ItemAcceptor.beltUnderlays = [
|
||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
||||
];
|
||||
|
||||
entity.components.ItemProcessor.inputsPerCharge = 2;
|
||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.serializer;
|
||||
|
||||
break;
|
||||
}
|
||||
case enumSplitterVariants.deserializer: {
|
||||
entity.components.ItemAcceptor.setSlots([
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
directions: [enumDirection.bottom],
|
||||
},
|
||||
]);
|
||||
|
||||
entity.components.ItemEjector.setSlots([
|
||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
||||
{ pos: new Vector(1, 0), direction: enumDirection.top },
|
||||
]);
|
||||
|
||||
entity.components.ItemAcceptor.beltUnderlays = [
|
||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
||||
{ pos: new Vector(1, 0), direction: enumDirection.top },
|
||||
];
|
||||
|
||||
entity.components.ItemProcessor.inputsPerCharge = 1;
|
||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.deserializer;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@ -6,6 +6,8 @@ import { Component } from "../component";
|
||||
/** @enum {string} */
|
||||
export const enumItemProcessorTypes = {
|
||||
splitter: "splitter",
|
||||
serializer: "serializer",
|
||||
deserializer: "deserializer",
|
||||
cutter: "cutter",
|
||||
cutterQuad: "cutterQuad",
|
||||
rotater: "rotater",
|
||||
|
||||
@ -403,6 +403,8 @@ export class HubGoals extends BasicSerializableObject {
|
||||
case enumItemProcessorTypes.hub:
|
||||
return 1e30;
|
||||
case enumItemProcessorTypes.splitter:
|
||||
case enumItemProcessorTypes.serializer:
|
||||
case enumItemProcessorTypes.deserializer:
|
||||
return globalConfig.beltSpeedItemsPerSecond * this.upgradeImprovements.belt * 2;
|
||||
|
||||
case enumItemProcessorTypes.mixer:
|
||||
|
||||
@ -120,6 +120,35 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
break;
|
||||
}
|
||||
|
||||
// SERIALIZER
|
||||
case enumItemProcessorTypes.serializer: {
|
||||
trackProduction = false;
|
||||
const availableSlots = entity.components.ItemAcceptor.slots.length;
|
||||
|
||||
for (let i = 0; i < availableSlots; ++i) {
|
||||
console.log(i);
|
||||
console.log(itemsBySlot[i]);
|
||||
outItems.push(itemsBySlot[i]);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// DESERIALIZER
|
||||
case enumItemProcessorTypes.deserializer: {
|
||||
trackProduction = false;
|
||||
const availableSlots = entity.components.ItemEjector.slots.length;
|
||||
|
||||
let nextSlot = processorComp.nextOutputSlot++ % availableSlots;
|
||||
for (let i = 0; i < items.length; ++i) {
|
||||
outItems.push({
|
||||
item: items[i].item,
|
||||
requiredSlot: (nextSlot + i) % availableSlots,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// CUTTER
|
||||
case enumItemProcessorTypes.cutter: {
|
||||
const inputItem = /** @type {ShapeItem} */ (items[0].item);
|
||||
|
||||
@ -472,6 +472,14 @@ buildings:
|
||||
name: Merger (compact)
|
||||
description: Merges two conveyor belts into one.
|
||||
|
||||
serializer:
|
||||
name: Serializer
|
||||
description: Serializes two conveyor belts into one.
|
||||
|
||||
deserializer:
|
||||
name: Deserializer
|
||||
description: Deserializes one conveyor belts into two.
|
||||
|
||||
cutter:
|
||||
default:
|
||||
name: &cutter Cutter
|
||||
|
||||
@ -468,6 +468,14 @@ buildings:
|
||||
name: 合流機 (コンパクト)
|
||||
description: 2本のベルトの内容を1本のベルトに合流します。
|
||||
|
||||
serializer:
|
||||
name: 整列合流機
|
||||
description: 2本のベルトの内容を順番に1本のベルトに合流します。
|
||||
|
||||
deserializer:
|
||||
name: 整列分配機
|
||||
description: 1本のベルトの内容を順番に2本のベルトに分配します。
|
||||
|
||||
cutter:
|
||||
default:
|
||||
name: &cutter 切断機
|
||||
|
||||
Loading…
Reference in New Issue
Block a user