199 lines
6.7 KiB
JavaScript
199 lines
6.7 KiB
JavaScript
import { enumDirection, Vector } from "../../core/vector";
|
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
|
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
|
import { Entity } from "../entity";
|
|
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
|
import { GameRoot } from "../root";
|
|
import { enumHubGoalRewards } from "../tutorial_goals";
|
|
import { T } from "../../translations";
|
|
import { formatItemsPerSecond } from "../../core/utils";
|
|
import { BeltUnderlaysComponent } from "../components/belt_underlays";
|
|
|
|
/** @enum {string} */
|
|
export const enumSplitterVariants = {
|
|
compact: "compact",
|
|
compactInverse: "compact-inverse",
|
|
compactMerge: "compact-merge",
|
|
compactMergeInverse: "compact-merge-inverse",
|
|
};
|
|
|
|
export class MetaSplitterBuilding extends MetaBuilding {
|
|
constructor() {
|
|
super("splitter");
|
|
}
|
|
|
|
getDimensions(variant) {
|
|
switch (variant) {
|
|
case defaultBuildingVariant:
|
|
return new Vector(2, 1);
|
|
case enumSplitterVariants.compact:
|
|
case enumSplitterVariants.compactInverse:
|
|
case enumSplitterVariants.compactMerge:
|
|
case enumSplitterVariants.compactMergeInverse:
|
|
return new Vector(1, 1);
|
|
default:
|
|
assertAlways(false, "Unknown splitter variant: " + variant);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {GameRoot} root
|
|
* @param {string} variant
|
|
* @returns {Array<[string, string]>}
|
|
*/
|
|
getAdditionalStatistics(root, variant) {
|
|
const speed = root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.splitter);
|
|
return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]];
|
|
}
|
|
|
|
getSilhouetteColor() {
|
|
return "#444";
|
|
}
|
|
|
|
/**
|
|
* @param {GameRoot} root
|
|
*/
|
|
getAvailableVariants(root) {
|
|
let available = [defaultBuildingVariant];
|
|
|
|
if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_splitter_compact)) {
|
|
available.push(enumSplitterVariants.compact, enumSplitterVariants.compactInverse);
|
|
}
|
|
|
|
if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_merger_compact)) {
|
|
available.push(enumSplitterVariants.compactMerge, enumSplitterVariants.compactMergeInverse);
|
|
}
|
|
|
|
return available;
|
|
}
|
|
|
|
/**
|
|
* @param {GameRoot} root
|
|
*/
|
|
getIsUnlocked(root) {
|
|
return root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_splitter);
|
|
}
|
|
|
|
/**
|
|
* Creates the entity at the given location
|
|
* @param {Entity} entity
|
|
*/
|
|
setupEntityComponents(entity) {
|
|
entity.addComponent(
|
|
new ItemAcceptorComponent({
|
|
slots: [], // set later
|
|
})
|
|
);
|
|
|
|
entity.addComponent(
|
|
new ItemProcessorComponent({
|
|
inputsPerCharge: 1,
|
|
processorType: enumItemProcessorTypes.splitter,
|
|
})
|
|
);
|
|
|
|
entity.addComponent(
|
|
new ItemEjectorComponent({
|
|
slots: [], // set later
|
|
renderFloatingItems: false,
|
|
})
|
|
);
|
|
|
|
entity.addComponent(new BeltUnderlaysComponent({ underlays: [] }));
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {Entity} entity
|
|
* @param {number} rotationVariant
|
|
* @param {string} variant
|
|
*/
|
|
updateVariants(entity, rotationVariant, variant) {
|
|
switch (variant) {
|
|
case defaultBuildingVariant: {
|
|
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 },
|
|
{ pos: new Vector(1, 0), direction: enumDirection.top },
|
|
]);
|
|
|
|
entity.components.BeltUnderlays.underlays = [
|
|
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
|
{ pos: new Vector(1, 0), direction: enumDirection.top },
|
|
];
|
|
|
|
break;
|
|
}
|
|
case enumSplitterVariants.compact:
|
|
case enumSplitterVariants.compactInverse: {
|
|
entity.components.ItemAcceptor.setSlots([
|
|
{
|
|
pos: new Vector(0, 0),
|
|
directions: [enumDirection.bottom],
|
|
},
|
|
{
|
|
pos: new Vector(0, 0),
|
|
directions: [
|
|
variant === enumSplitterVariants.compactInverse
|
|
? enumDirection.left
|
|
: enumDirection.right,
|
|
],
|
|
},
|
|
]);
|
|
|
|
entity.components.ItemEjector.setSlots([
|
|
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
|
]);
|
|
|
|
entity.components.BeltUnderlays.underlays = [
|
|
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
|
];
|
|
|
|
break;
|
|
}
|
|
case enumSplitterVariants.compactMerge:
|
|
case enumSplitterVariants.compactMergeInverse: {
|
|
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(0, 0),
|
|
direction:
|
|
variant === enumSplitterVariants.compactMergeInverse
|
|
? enumDirection.left
|
|
: enumDirection.right,
|
|
},
|
|
]);
|
|
|
|
entity.components.BeltUnderlays.underlays = [
|
|
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
|
];
|
|
|
|
break;
|
|
}
|
|
default:
|
|
assertAlways(false, "Unknown splitter variant: " + variant);
|
|
}
|
|
}
|
|
}
|