Make chained miner default and the only option after unlocking it
This commit is contained in:
parent
c6eb1dad04
commit
091ffd1031
|
@ -1,78 +1,78 @@
|
||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { enumDirection, Vector } from "../../core/vector";
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||||
import { MinerComponent } from "../components/miner";
|
import { MinerComponent } from "../components/miner";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
||||||
import { GameRoot } from "../root";
|
import { GameRoot } from "../root";
|
||||||
import { enumHubGoalRewards } from "../tutorial_goals";
|
import { enumHubGoalRewards } from "../tutorial_goals";
|
||||||
import { T } from "../../translations";
|
import { T } from "../../translations";
|
||||||
import { formatItemsPerSecond } from "../../core/utils";
|
import { formatItemsPerSecond } from "../../core/utils";
|
||||||
|
|
||||||
/** @enum {string} */
|
/** @enum {string} */
|
||||||
export const enumMinerVariants = { chainable: "chainable" };
|
export const enumMinerVariants = { chainable: "chainable" };
|
||||||
|
|
||||||
const overlayMatrix = [1, 1, 1, 1, 0, 1, 1, 1, 1];
|
const overlayMatrix = [1, 1, 1, 1, 0, 1, 1, 1, 1];
|
||||||
|
|
||||||
export class MetaMinerBuilding extends MetaBuilding {
|
export class MetaMinerBuilding extends MetaBuilding {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("miner");
|
super("miner");
|
||||||
}
|
}
|
||||||
|
|
||||||
getSilhouetteColor() {
|
getSilhouetteColor() {
|
||||||
return "#b37dcd";
|
return "#b37dcd";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {GameRoot} root
|
* @param {GameRoot} root
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
* @returns {Array<[string, string]>}
|
* @returns {Array<[string, string]>}
|
||||||
*/
|
*/
|
||||||
getAdditionalStatistics(root, variant) {
|
getAdditionalStatistics(root, variant) {
|
||||||
const speed = root.hubGoals.getMinerBaseSpeed();
|
const speed = root.hubGoals.getMinerBaseSpeed();
|
||||||
return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]];
|
return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {GameRoot} root
|
* @param {GameRoot} root
|
||||||
*/
|
*/
|
||||||
getAvailableVariants(root) {
|
getAvailableVariants(root) {
|
||||||
if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_miner_chainable)) {
|
if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_miner_chainable)) {
|
||||||
return [defaultBuildingVariant, enumMinerVariants.chainable];
|
return [enumMinerVariants.chainable];
|
||||||
}
|
}
|
||||||
return super.getAvailableVariants(root);
|
return super.getAvailableVariants(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} rotation
|
* @param {number} rotation
|
||||||
* @param {number} rotationVariant
|
* @param {number} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
*/
|
*/
|
||||||
getSpecialOverlayRenderMatrix(rotation, rotationVariant, variant, entity) {
|
getSpecialOverlayRenderMatrix(rotation, rotationVariant, variant, entity) {
|
||||||
return overlayMatrix;
|
return overlayMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the entity at the given location
|
* Creates the entity at the given location
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
*/
|
*/
|
||||||
setupEntityComponents(entity) {
|
setupEntityComponents(entity) {
|
||||||
entity.addComponent(new MinerComponent({}));
|
entity.addComponent(new MinerComponent({}));
|
||||||
entity.addComponent(
|
entity.addComponent(
|
||||||
new ItemEjectorComponent({
|
new ItemEjectorComponent({
|
||||||
slots: [{ pos: new Vector(0, 0), direction: enumDirection.top }],
|
slots: [{ pos: new Vector(0, 0), direction: enumDirection.top }],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {number} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant, variant) {
|
updateVariants(entity, rotationVariant, variant) {
|
||||||
entity.components.Miner.chainable = variant === enumMinerVariants.chainable;
|
entity.components.Miner.chainable = variant === enumMinerVariants.chainable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -457,11 +457,11 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
||||||
this.currentVariant.set(defaultBuildingVariant);
|
this.currentVariant.set(defaultBuildingVariant);
|
||||||
} else {
|
} else {
|
||||||
const availableVariants = metaBuilding.getAvailableVariants(this.root);
|
const availableVariants = metaBuilding.getAvailableVariants(this.root);
|
||||||
const index = availableVariants.indexOf(this.currentVariant.get());
|
let index = availableVariants.indexOf(this.currentVariant.get());
|
||||||
assert(
|
if (index < 0) {
|
||||||
index >= 0,
|
index = 0;
|
||||||
"Current variant was invalid: " + this.currentVariant.get() + " out of " + availableVariants
|
console.warn("Invalid variant selected:", this.currentVariant.get());
|
||||||
);
|
}
|
||||||
const newIndex = (index + 1) % availableVariants.length;
|
const newIndex = (index + 1) % availableVariants.length;
|
||||||
const newVariant = availableVariants[newIndex];
|
const newVariant = availableVariants[newIndex];
|
||||||
this.setVariant(newVariant);
|
this.setVariant(newVariant);
|
||||||
|
@ -595,7 +595,17 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
||||||
this.abortDragging();
|
this.abortDragging();
|
||||||
this.root.hud.signals.selectedPlacementBuildingChanged.dispatch(metaBuilding);
|
this.root.hud.signals.selectedPlacementBuildingChanged.dispatch(metaBuilding);
|
||||||
if (metaBuilding) {
|
if (metaBuilding) {
|
||||||
const variant = this.preferredVariants[metaBuilding.getId()] || defaultBuildingVariant;
|
const availableVariants = metaBuilding.getAvailableVariants(this.root);
|
||||||
|
const preferredVariant = this.preferredVariants[metaBuilding.getId()];
|
||||||
|
|
||||||
|
// Choose last stored variant if possible, otherwise the default one
|
||||||
|
let variant;
|
||||||
|
if (!preferredVariant || !availableVariants.includes(preferredVariant)) {
|
||||||
|
variant = availableVariants[0];
|
||||||
|
} else {
|
||||||
|
variant = preferredVariant;
|
||||||
|
}
|
||||||
|
|
||||||
this.currentVariant.set(variant);
|
this.currentVariant.set(variant);
|
||||||
|
|
||||||
this.fakeEntity = new Entity(null);
|
this.fakeEntity = new Entity(null);
|
||||||
|
|
Reference in New Issue