mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Add chainable splitter building
This commit is contained in:
parent
b7f4551487
commit
d11388812a
@ -3,6 +3,7 @@ import { enumDirection, Vector } from "../../core/vector";
|
|||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||||
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
||||||
|
import { ChainableSplitterComponent } from "../components/chainable_splitter";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
||||||
import { GameRoot, enumLayer } from "../root";
|
import { GameRoot, enumLayer } from "../root";
|
||||||
@ -11,7 +12,11 @@ import { T } from "../../translations";
|
|||||||
import { formatItemsPerSecond } from "../../core/utils";
|
import { formatItemsPerSecond } from "../../core/utils";
|
||||||
|
|
||||||
/** @enum {string} */
|
/** @enum {string} */
|
||||||
export const enumSplitterVariants = { compact: "compact", compactInverse: "compact-inverse" };
|
export const enumSplitterVariants = {
|
||||||
|
compact: "compact",
|
||||||
|
compactInverse: "compact-inverse",
|
||||||
|
chainable: "chainable",
|
||||||
|
};
|
||||||
|
|
||||||
export class MetaSplitterBuilding extends MetaBuilding {
|
export class MetaSplitterBuilding extends MetaBuilding {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -24,6 +29,7 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
|||||||
return new Vector(2, 1);
|
return new Vector(2, 1);
|
||||||
case enumSplitterVariants.compact:
|
case enumSplitterVariants.compact:
|
||||||
case enumSplitterVariants.compactInverse:
|
case enumSplitterVariants.compactInverse:
|
||||||
|
case enumSplitterVariants.chainable:
|
||||||
return new Vector(1, 1);
|
return new Vector(1, 1);
|
||||||
default:
|
default:
|
||||||
assertAlways(false, "Unknown splitter variant: " + variant);
|
assertAlways(false, "Unknown splitter variant: " + variant);
|
||||||
@ -48,14 +54,15 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
|||||||
* @param {GameRoot} root
|
* @param {GameRoot} root
|
||||||
*/
|
*/
|
||||||
getAvailableVariants(root) {
|
getAvailableVariants(root) {
|
||||||
|
let variants = [defaultBuildingVariant];
|
||||||
if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_splitter_compact)) {
|
if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_splitter_compact)) {
|
||||||
return [
|
variants.push(enumSplitterVariants.compact);
|
||||||
defaultBuildingVariant,
|
variants.push(enumSplitterVariants.compactInverse);
|
||||||
enumSplitterVariants.compact,
|
|
||||||
enumSplitterVariants.compactInverse,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
return super.getAvailableVariants(root);
|
if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_freeplay)) {
|
||||||
|
variants.push(enumSplitterVariants.chainable);
|
||||||
|
}
|
||||||
|
return variants;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,13 +92,6 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
entity.addComponent(
|
|
||||||
new ItemProcessorComponent({
|
|
||||||
inputsPerCharge: 1,
|
|
||||||
processorType: enumItemProcessorTypes.splitter,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
entity.addComponent(
|
entity.addComponent(
|
||||||
new ItemEjectorComponent({
|
new ItemEjectorComponent({
|
||||||
slots: [
|
slots: [
|
||||||
@ -102,6 +102,24 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {Entity} entity
|
||||||
|
*/
|
||||||
|
updateDefaultComponent(entity) {
|
||||||
|
if (!entity.components.ItemProcessor) {
|
||||||
|
entity.addComponent(
|
||||||
|
new ItemProcessorComponent({
|
||||||
|
inputsPerCharge: 1,
|
||||||
|
processorType: enumItemProcessorTypes.splitter,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (entity.components.ChainableSplitter) {
|
||||||
|
entity.removeComponent(ChainableSplitterComponent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
@ -111,6 +129,8 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
|||||||
updateVariants(entity, rotationVariant, variant) {
|
updateVariants(entity, rotationVariant, variant) {
|
||||||
switch (variant) {
|
switch (variant) {
|
||||||
case defaultBuildingVariant: {
|
case defaultBuildingVariant: {
|
||||||
|
this.updateDefaultComponent(entity);
|
||||||
|
|
||||||
entity.components.ItemAcceptor.setSlots([
|
entity.components.ItemAcceptor.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
@ -136,6 +156,8 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
|||||||
}
|
}
|
||||||
case enumSplitterVariants.compact:
|
case enumSplitterVariants.compact:
|
||||||
case enumSplitterVariants.compactInverse: {
|
case enumSplitterVariants.compactInverse: {
|
||||||
|
this.updateDefaultComponent(entity);
|
||||||
|
|
||||||
entity.components.ItemAcceptor.setSlots([
|
entity.components.ItemAcceptor.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
@ -161,6 +183,31 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case enumSplitterVariants.chainable: {
|
||||||
|
if (entity.components.ItemProcessor) {
|
||||||
|
entity.removeComponent(ItemProcessorComponent);
|
||||||
|
}
|
||||||
|
if (!entity.components.ChainableSplitter) {
|
||||||
|
entity.addComponent(new ChainableSplitterComponent({ chainable: true }));
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.components.ItemAcceptor.setSlots([
|
||||||
|
{
|
||||||
|
pos: new Vector(0, 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, layer: enumLayer.regular },
|
||||||
|
];
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
assertAlways(false, "Unknown painter variant: " + variant);
|
assertAlways(false, "Unknown painter variant: " + variant);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -477,6 +477,10 @@ buildings:
|
|||||||
name: Merger (compact)
|
name: Merger (compact)
|
||||||
description: Merges two conveyor belts into one.
|
description: Merges two conveyor belts into one.
|
||||||
|
|
||||||
|
chainable:
|
||||||
|
name: Balancer (chainable)
|
||||||
|
description: Evenly distributes all inputs onto all outputs. Can be chained.
|
||||||
|
|
||||||
cutter:
|
cutter:
|
||||||
default:
|
default:
|
||||||
name: &cutter Cutter
|
name: &cutter Cutter
|
||||||
|
|||||||
@ -468,6 +468,10 @@ buildings:
|
|||||||
name: 合流機 (コンパクト)
|
name: 合流機 (コンパクト)
|
||||||
description: 2本のベルトの内容を1本のベルトに合流します。
|
description: 2本のベルトの内容を1本のベルトに合流します。
|
||||||
|
|
||||||
|
chainable:
|
||||||
|
name: 連鎖分配機
|
||||||
|
description: 横に繋がれた連鎖分配機のすべての入力をすべての出力に均等に分配します。
|
||||||
|
|
||||||
cutter:
|
cutter:
|
||||||
default:
|
default:
|
||||||
name: &cutter 切断機
|
name: &cutter 切断機
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user