2020-08-18 18:02:39 +00:00
|
|
|
import { Vector, enumDirection } from "../../core/vector";
|
|
|
|
import { LogicGateComponent, enumLogicGateType } from "../components/logic_gate";
|
|
|
|
import { WiredPinsComponent, enumPinSlotType } from "../components/wired_pins";
|
|
|
|
import { Entity } from "../entity";
|
|
|
|
import { defaultBuildingVariant, MetaBuilding } from "../meta_building";
|
|
|
|
import { GameRoot } from "../root";
|
2020-09-29 08:52:25 +00:00
|
|
|
import { enumHubGoalRewards } from "../tutorial_goals";
|
2020-09-24 10:53:40 +00:00
|
|
|
import { MetaCutterBuilding } from "./cutter";
|
|
|
|
import { MetaPainterBuilding } from "./painter";
|
|
|
|
import { MetaRotaterBuilding } from "./rotater";
|
|
|
|
import { MetaStackerBuilding } from "./stacker";
|
2020-08-18 18:02:39 +00:00
|
|
|
|
|
|
|
/** @enum {string} */
|
|
|
|
export const enumVirtualProcessorVariants = {
|
|
|
|
rotater: "rotater",
|
|
|
|
unstacker: "unstacker",
|
2020-09-19 13:33:24 +00:00
|
|
|
stacker: "stacker",
|
|
|
|
painter: "painter",
|
2020-08-18 18:02:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @enum {string} */
|
|
|
|
export const enumVariantToGate = {
|
|
|
|
[defaultBuildingVariant]: enumLogicGateType.cutter,
|
|
|
|
[enumVirtualProcessorVariants.rotater]: enumLogicGateType.rotater,
|
|
|
|
[enumVirtualProcessorVariants.unstacker]: enumLogicGateType.unstacker,
|
2020-09-19 13:33:24 +00:00
|
|
|
[enumVirtualProcessorVariants.stacker]: enumLogicGateType.stacker,
|
|
|
|
[enumVirtualProcessorVariants.painter]: enumLogicGateType.painter,
|
2020-08-18 18:02:39 +00:00
|
|
|
};
|
|
|
|
|
2020-09-24 10:53:40 +00:00
|
|
|
const colors = {
|
|
|
|
[defaultBuildingVariant]: new MetaCutterBuilding().getSilhouetteColor(),
|
|
|
|
[enumVirtualProcessorVariants.rotater]: new MetaRotaterBuilding().getSilhouetteColor(),
|
|
|
|
[enumVirtualProcessorVariants.unstacker]: new MetaStackerBuilding().getSilhouetteColor(),
|
|
|
|
[enumVirtualProcessorVariants.stacker]: new MetaStackerBuilding().getSilhouetteColor(),
|
|
|
|
[enumVirtualProcessorVariants.painter]: new MetaPainterBuilding().getSilhouetteColor(),
|
|
|
|
};
|
|
|
|
|
2020-08-18 18:02:39 +00:00
|
|
|
export class MetaVirtualProcessorBuilding extends MetaBuilding {
|
|
|
|
constructor() {
|
|
|
|
super("virtual_processor");
|
|
|
|
}
|
|
|
|
|
2020-09-24 10:53:40 +00:00
|
|
|
getSilhouetteColor(variant) {
|
|
|
|
return colors[variant];
|
2020-08-18 18:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {GameRoot} root
|
|
|
|
*/
|
|
|
|
getIsUnlocked(root) {
|
2020-09-29 08:52:25 +00:00
|
|
|
return root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_virtual_processing);
|
2020-08-18 18:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @returns {"wires"} **/
|
|
|
|
getLayer() {
|
|
|
|
return "wires";
|
|
|
|
}
|
|
|
|
|
|
|
|
getDimensions() {
|
|
|
|
return new Vector(1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
getAvailableVariants() {
|
|
|
|
return [
|
|
|
|
defaultBuildingVariant,
|
|
|
|
enumVirtualProcessorVariants.rotater,
|
2020-09-19 13:33:24 +00:00
|
|
|
enumVirtualProcessorVariants.stacker,
|
|
|
|
enumVirtualProcessorVariants.painter,
|
2020-09-24 10:53:40 +00:00
|
|
|
enumVirtualProcessorVariants.unstacker,
|
2020-08-18 18:02:39 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
getRenderPins() {
|
|
|
|
// We already have it included
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Entity} entity
|
|
|
|
* @param {number} rotationVariant
|
|
|
|
*/
|
|
|
|
updateVariants(entity, rotationVariant, variant) {
|
|
|
|
const gateType = enumVariantToGate[variant];
|
|
|
|
entity.components.LogicGate.type = gateType;
|
|
|
|
const pinComp = entity.components.WiredPins;
|
|
|
|
switch (gateType) {
|
|
|
|
case enumLogicGateType.cutter:
|
|
|
|
case enumLogicGateType.unstacker: {
|
|
|
|
pinComp.setSlots([
|
|
|
|
{
|
|
|
|
pos: new Vector(0, 0),
|
|
|
|
direction: enumDirection.left,
|
|
|
|
type: enumPinSlotType.logicalEjector,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pos: new Vector(0, 0),
|
|
|
|
direction: enumDirection.right,
|
|
|
|
type: enumPinSlotType.logicalEjector,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pos: new Vector(0, 0),
|
|
|
|
direction: enumDirection.bottom,
|
|
|
|
type: enumPinSlotType.logicalAcceptor,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case enumLogicGateType.rotater: {
|
|
|
|
pinComp.setSlots([
|
|
|
|
{
|
|
|
|
pos: new Vector(0, 0),
|
2020-10-07 17:02:42 +00:00
|
|
|
direction: enumDirection.top,
|
2020-08-18 18:02:39 +00:00
|
|
|
type: enumPinSlotType.logicalEjector,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pos: new Vector(0, 0),
|
|
|
|
direction: enumDirection.bottom,
|
|
|
|
type: enumPinSlotType.logicalAcceptor,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
break;
|
|
|
|
}
|
2020-09-19 13:33:24 +00:00
|
|
|
case enumLogicGateType.stacker:
|
|
|
|
case enumLogicGateType.painter: {
|
|
|
|
pinComp.setSlots([
|
|
|
|
{
|
|
|
|
pos: new Vector(0, 0),
|
|
|
|
direction: enumDirection.top,
|
|
|
|
type: enumPinSlotType.logicalEjector,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pos: new Vector(0, 0),
|
|
|
|
direction: enumDirection.bottom,
|
|
|
|
type: enumPinSlotType.logicalAcceptor,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pos: new Vector(0, 0),
|
|
|
|
direction: enumDirection.right,
|
|
|
|
type: enumPinSlotType.logicalAcceptor,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
break;
|
|
|
|
}
|
2020-08-18 18:02:39 +00:00
|
|
|
default:
|
|
|
|
assertAlways("unknown logic gate type: " + gateType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the entity at the given location
|
|
|
|
* @param {Entity} entity
|
|
|
|
*/
|
|
|
|
setupEntityComponents(entity) {
|
|
|
|
entity.addComponent(
|
|
|
|
new WiredPinsComponent({
|
|
|
|
slots: [],
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
entity.addComponent(new LogicGateComponent({}));
|
|
|
|
}
|
|
|
|
}
|