1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-07 10:03:59 +00:00
tobspr_shapez.io/src/js/game/buildings/miner.js

73 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-05-09 14:45:23 +00:00
import { enumDirection, Vector } from "../../core/vector";
import { ItemEjectorComponent } from "../components/item_ejector";
import { MinerComponent } from "../components/miner";
import { Entity } from "../entity";
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
import { GameRoot } from "../root";
2020-05-17 12:46:33 +00:00
import { enumHubGoalRewards } from "../tutorial_goals";
import { T } from "../../translations";
import { round1Digit, round2Digits, formatItemsPerSecond } from "../../core/utils";
/** @enum {string} */
export const enumMinerVariants = { chainable: "chainable" };
2020-05-09 14:45:23 +00:00
export class MetaMinerBuilding extends MetaBuilding {
constructor() {
super("miner");
}
getSilhouetteColor() {
return "#b37dcd";
}
/**
* @param {GameRoot} root
* @param {string} variant
* @returns {Array<[string, string]>}
*/
getAdditionalStatistics(root, variant) {
const speed = root.hubGoals.getMinerBaseSpeed();
return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]];
}
2020-05-17 12:46:33 +00:00
/**
*
* @param {GameRoot} root
*/
getAvailableVariants(root) {
2020-05-17 12:46:33 +00:00
if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_miner_chainable)) {
return [defaultBuildingVariant, enumMinerVariants.chainable];
}
return super.getAvailableVariants(root);
}
2020-05-09 14:45:23 +00:00
/**
* Creates the entity at the given location
* @param {Entity} entity
* @param {GameRoot} root
2020-05-09 14:45:23 +00:00
*/
setupEntityComponents(entity, root) {
let itemBelow = null;
if (root) {
const staticComp = entity.components.StaticMapEntity;
itemBelow = root.map.getLowerLayerContentXY(staticComp.origin.x, staticComp.origin.y);
}
entity.addComponent(new MinerComponent({ minedItem: itemBelow }));
2020-05-09 14:45:23 +00:00
entity.addComponent(
new ItemEjectorComponent({
slots: [{ pos: new Vector(0, 0), direction: enumDirection.top }],
})
);
}
/**
*
* @param {Entity} entity
2020-05-16 21:48:56 +00:00
* @param {number} rotationVariant
* @param {string} variant
*/
2020-05-16 21:48:56 +00:00
updateVariants(entity, rotationVariant, variant) {
entity.components.Miner.chainable = variant === enumMinerVariants.chainable;
}
2020-05-09 14:45:23 +00:00
}