1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2024-10-27 20:34:29 +00:00
tobspr_shapez.io/src/js/game/buildings/wire_tunnel.js

88 lines
2.1 KiB
JavaScript
Raw Normal View History

import { Vector } from "../../core/vector";
import { Entity } from "../entity";
2020-08-15 14:16:17 +00:00
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
2020-08-15 16:39:08 +00:00
import { GameRoot } from "../root";
import { WireTunnelComponent } from "../components/wire_tunnel";
2020-08-15 14:16:17 +00:00
import { generateMatrixRotations } from "../../core/utils";
/** @enum {string} */
export const enumWireTunnelVariants = {
coating: "coating",
};
const wireTunnelOverlayMatrices = {
[defaultBuildingVariant]: generateMatrixRotations([0, 1, 0, 1, 1, 1, 0, 1, 0]),
[enumWireTunnelVariants.coating]: generateMatrixRotations([0, 1, 0, 0, 1, 0, 0, 1, 0]),
};
export class MetaWireTunnelBuilding extends MetaBuilding {
constructor() {
super("wire_tunnel");
}
getSilhouetteColor() {
2020-08-15 14:16:17 +00:00
return "#777a86";
}
/**
* @param {GameRoot} root
*/
getIsUnlocked(root) {
// @todo
return true;
}
2020-08-15 14:16:17 +00:00
/**
*
* @param {number} rotation
* @param {number} rotationVariant
* @param {string} variant
* @param {Entity} entity
*/
getSpecialOverlayRenderMatrix(rotation, rotationVariant, variant, entity) {
return wireTunnelOverlayMatrices[variant][rotation];
}
getIsRotateable(variant) {
return variant !== defaultBuildingVariant;
}
getDimensions() {
return new Vector(1, 1);
}
2020-08-15 14:16:17 +00:00
getAvailableVariants() {
return [defaultBuildingVariant, enumWireTunnelVariants.coating];
}
2020-08-15 16:39:08 +00:00
/** @returns {"wires"} **/
getLayer() {
2020-08-15 16:39:08 +00:00
return "wires";
}
2020-08-15 14:16:17 +00:00
getRotateAutomaticallyWhilePlacing() {
return true;
}
getStayInPlacementMode() {
return true;
}
/**
* Creates the entity at the given location
* @param {Entity} entity
*/
setupEntityComponents(entity) {
2020-08-15 14:16:17 +00:00
entity.addComponent(new WireTunnelComponent({}));
}
/**
* @param {Entity} entity
* @param {number} rotationVariant
* @param {string} variant
*/
updateVariants(entity, rotationVariant, variant) {
entity.components.WireTunnel.multipleDirections = variant === defaultBuildingVariant;
}
}