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";
|
2020-05-16 20:45:40 +00:00
|
|
|
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.";
|
|
|
|
}
|
|
|
|
|
2020-05-16 20:45:40 +00:00
|
|
|
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) {
|
2020-05-16 20:45:40 +00:00
|
|
|
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 }],
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2020-05-16 20:45:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Entity} entity
|
|
|
|
* @param {*} variant
|
|
|
|
*/
|
|
|
|
updateVariant(entity, variant) {
|
|
|
|
entity.components.Miner.chainable = variant === enumMinerVariants.chainable;
|
|
|
|
}
|
2020-05-09 14:45:23 +00:00
|
|
|
}
|