You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
6.7 KiB
199 lines
6.7 KiB
4 years ago
|
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} */
|
||
4 years ago
|
export const enumBalancerVariants = {
|
||
|
merger: "merger",
|
||
|
mergerInverse: "merger-inverse",
|
||
|
splitter: "splitter",
|
||
|
splitterInverse: "splitter-inverse",
|
||
4 years ago
|
};
|
||
|
|
||
4 years ago
|
export class MetaBalancerBuilding extends MetaBuilding {
|
||
4 years ago
|
constructor() {
|
||
4 years ago
|
super("balancer");
|
||
4 years ago
|
}
|
||
|
|
||
|
getDimensions(variant) {
|
||
|
switch (variant) {
|
||
|
case defaultBuildingVariant:
|
||
|
return new Vector(2, 1);
|
||
4 years ago
|
case enumBalancerVariants.merger:
|
||
|
case enumBalancerVariants.mergerInverse:
|
||
|
case enumBalancerVariants.splitter:
|
||
|
case enumBalancerVariants.splitterInverse:
|
||
4 years ago
|
return new Vector(1, 1);
|
||
|
default:
|
||
4 years ago
|
assertAlways(false, "Unknown balancer variant: " + variant);
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param {GameRoot} root
|
||
|
* @param {string} variant
|
||
|
* @returns {Array<[string, string]>}
|
||
|
*/
|
||
|
getAdditionalStatistics(root, variant) {
|
||
4 years ago
|
const speed = root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.balancer);
|
||
4 years ago
|
return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]];
|
||
|
}
|
||
|
|
||
|
getSilhouetteColor() {
|
||
|
return "#444";
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param {GameRoot} root
|
||
|
*/
|
||
|
getAvailableVariants(root) {
|
||
|
let available = [defaultBuildingVariant];
|
||
|
|
||
4 years ago
|
if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_merger)) {
|
||
|
available.push(enumBalancerVariants.merger, enumBalancerVariants.mergerInverse);
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_splitter)) {
|
||
|
available.push(enumBalancerVariants.splitter, enumBalancerVariants.splitterInverse);
|
||
4 years ago
|
}
|
||
|
|
||
|
return available;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param {GameRoot} root
|
||
|
*/
|
||
|
getIsUnlocked(root) {
|
||
4 years ago
|
return root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_balancer);
|
||
4 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* 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,
|
||
4 years ago
|
processorType: enumItemProcessorTypes.balancer,
|
||
4 years ago
|
})
|
||
|
);
|
||
|
|
||
|
entity.addComponent(
|
||
|
new ItemEjectorComponent({
|
||
|
slots: [], // set later
|
||
4 years ago
|
renderFloatingItems: false,
|
||
4 years ago
|
})
|
||
|
);
|
||
|
|
||
|
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;
|
||
|
}
|
||
4 years ago
|
case enumBalancerVariants.merger:
|
||
|
case enumBalancerVariants.mergerInverse: {
|
||
4 years ago
|
entity.components.ItemAcceptor.setSlots([
|
||
|
{
|
||
|
pos: new Vector(0, 0),
|
||
|
directions: [enumDirection.bottom],
|
||
|
},
|
||
|
{
|
||
|
pos: new Vector(0, 0),
|
||
|
directions: [
|
||
4 years ago
|
variant === enumBalancerVariants.mergerInverse
|
||
4 years ago
|
? 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;
|
||
|
}
|
||
4 years ago
|
case enumBalancerVariants.splitter:
|
||
|
case enumBalancerVariants.splitterInverse: {
|
||
4 years ago
|
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:
|
||
4 years ago
|
variant === enumBalancerVariants.splitterInverse
|
||
4 years ago
|
? enumDirection.left
|
||
|
: enumDirection.right,
|
||
|
},
|
||
|
]);
|
||
|
|
||
|
entity.components.BeltUnderlays.underlays = [
|
||
|
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
||
|
];
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
default:
|
||
4 years ago
|
assertAlways(false, "Unknown balancer variant: " + variant);
|
||
4 years ago
|
}
|
||
|
}
|
||
|
}
|