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

71 lines
1.9 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";
/** @enum {string} */
export const enumMinerVariants = { chainable: "chainable" };
2020-05-09 14:45:23 +00:00
export class MetaMinerBuilding extends MetaBuilding {
constructor() {
super("miner");
}
getName() {
return "Extract";
}
getSilhouetteColor() {
return "#b37dcd";
}
getDescription() {
return "Place over a shape or color to extract it. Six extractors fill exactly one belt.";
}
getAvailableVariants(root) {
return [defaultBuildingVariant, enumMinerVariants.chainable];
}
/**
* @param {GameRoot} root
* @param {object} param0
* @param {Vector} param0.origin
* @param {number} param0.rotation
* @param {number} param0.rotationVariant
* @param {string} param0.variant
*/
performAdditionalPlacementChecks(root, { origin, rotation, rotationVariant, variant }) {
// Make sure its placed above a resource
const lowerLayer = root.map.getLowerLayerContentXY(origin.x, origin.y);
if (!lowerLayer) {
return false;
}
return true;
}
2020-05-09 14:45:23 +00:00
/**
* Creates the entity at the given location
* @param {Entity} entity
*/
setupEntityComponents(entity) {
entity.addComponent(new MinerComponent({}));
2020-05-09 14:45:23 +00:00
entity.addComponent(
new ItemEjectorComponent({
slots: [{ pos: new Vector(0, 0), direction: enumDirection.top }],
})
);
}
/**
*
* @param {Entity} entity
* @param {*} variant
*/
updateVariant(entity, variant) {
entity.components.Miner.chainable = variant === enumMinerVariants.chainable;
}
2020-05-09 14:45:23 +00:00
}