Added hotkeys to components/modes

This commit is contained in:
thepaperpilot 2022-12-21 22:34:16 -06:00
parent 54510cefa4
commit df432e45ef

View file

@ -31,6 +31,8 @@ import { render } from "util/vue";
import { createCollapsibleModifierSections } from "data/common"; import { createCollapsibleModifierSections } from "data/common";
import Modal from "components/Modal.vue"; import Modal from "components/Modal.vue";
import { createBar, GenericBar } from "features/bars/bar"; import { createBar, GenericBar } from "features/bars/bar";
import HotkeyVue from "components/Hotkey.vue";
import { createHotkey, GenericHotkey } from "features/hotkey";
const id = "factory"; const id = "factory";
@ -112,18 +114,21 @@ const factory = createLayer(id, () => {
const FACTORY_COMPONENTS = { const FACTORY_COMPONENTS = {
cursor: { cursor: {
imageSrc: cursor, imageSrc: cursor,
key: "Escape",
name: "Cursor", name: "Cursor",
description: "Use this to move.", description: "Use this to move.",
tick: 0 tick: 0
}, },
rotate: { rotate: {
imageSrc: rotate, imageSrc: rotate,
key: "t",
name: "Rotate", name: "Rotate",
description: "Use this to rotate components.", description: "Use this to rotate components.",
tick: 0 tick: 0
}, },
conveyor: { conveyor: {
imageSrc: conveyor, imageSrc: conveyor,
key: "0",
name: "Conveyor", name: "Conveyor",
description: "Moves items at 1 block per second.", description: "Moves items at 1 block per second.",
energyCost: 1, energyCost: 1,
@ -139,6 +144,7 @@ const factory = createLayer(id, () => {
}, },
wood: { wood: {
imageSrc: wood, imageSrc: wood,
key: "1",
name: "Wood Machine", name: "Wood Machine",
description: "Produces 1 wood every 1 second.", description: "Produces 1 wood every 1 second.",
energyCost: 10, energyCost: 10,
@ -151,6 +157,7 @@ const factory = createLayer(id, () => {
}, },
cloth: { cloth: {
imageSrc: cloth, imageSrc: cloth,
key: "2",
name: "Cloth Machine", name: "Cloth Machine",
description: "Produces 1 cloth every 1 second.", description: "Produces 1 cloth every 1 second.",
energyCost: 10, energyCost: 10,
@ -163,6 +170,7 @@ const factory = createLayer(id, () => {
}, },
dye: { dye: {
imageSrc: dye, imageSrc: dye,
key: "3",
name: "Dye Machine", name: "Dye Machine",
description: "Produces 1 dye every 1 second.", description: "Produces 1 dye every 1 second.",
energyCost: 10, energyCost: 10,
@ -175,6 +183,7 @@ const factory = createLayer(id, () => {
}, },
metal: { metal: {
imageSrc: metal, imageSrc: metal,
key: "4",
name: "Metal Machine", name: "Metal Machine",
description: "Produces 1 metal every 1 second.", description: "Produces 1 metal every 1 second.",
energyCost: 10, energyCost: 10,
@ -187,6 +196,7 @@ const factory = createLayer(id, () => {
}, },
plastic: { plastic: {
imageSrc: plastic, imageSrc: plastic,
key: "5",
name: "Plastic Machine", name: "Plastic Machine",
description: "Produces 1 plastic every 1 second.", description: "Produces 1 plastic every 1 second.",
energyCost: 10, energyCost: 10,
@ -199,6 +209,7 @@ const factory = createLayer(id, () => {
}, },
blocks: { blocks: {
imageSrc: block, imageSrc: block,
key: "shift+1",
name: "Wooden Block Maker", name: "Wooden Block Maker",
description: "Turns 2 wood into 1 wooden block every second.", description: "Turns 2 wood into 1 wooden block every second.",
energyCost: 20, energyCost: 20,
@ -216,6 +227,7 @@ const factory = createLayer(id, () => {
}, },
clothes: { clothes: {
imageSrc: clothes, imageSrc: clothes,
key: "shift+2",
name: "Clothes Maker", name: "Clothes Maker",
description: "Turns 2 cloth and 1 dye into 1 clothe every second.", description: "Turns 2 cloth and 1 dye into 1 clothe every second.",
energyCost: 20, energyCost: 20,
@ -236,6 +248,7 @@ const factory = createLayer(id, () => {
}, },
trucks: { trucks: {
imageSrc: truck, imageSrc: truck,
key: "shift+3",
name: "Trucks Maker", name: "Trucks Maker",
description: "Turns 2 metal and 1 plastic into 1 truck every second.", description: "Turns 2 metal and 1 plastic into 1 truck every second.",
energyCost: 20, energyCost: 20,
@ -265,6 +278,18 @@ const factory = createLayer(id, () => {
metal: metal metal: metal
} as Record<string, string>; } as Record<string, string>;
const hotkeys = (Object.keys(FACTORY_COMPONENTS) as FactoryCompNames[]).reduce((acc, comp) => {
acc[comp] = createHotkey(() => ({
key: FACTORY_COMPONENTS[comp].key,
description: "Select " + FACTORY_COMPONENTS[comp].name,
onPress() {
compSelected.value = comp;
},
enabled: main.days[day - 1].opened
}));
return acc;
}, {} as Record<FactoryCompNames, GenericHotkey>);
type FactoryCompNames = type FactoryCompNames =
| "cursor" | "cursor"
| "rotate" | "rotate"
@ -301,6 +326,7 @@ const factory = createLayer(id, () => {
interface FactoryComponentDeclaration { interface FactoryComponentDeclaration {
tick: number; tick: number;
key: string;
imageSrc: string; imageSrc: string;
name: string; name: string;
description: string; description: string;
@ -902,6 +928,7 @@ const factory = createLayer(id, () => {
minWidth: 700, minWidth: 700,
generalTabCollapsed, generalTabCollapsed,
components, components,
hotkeys,
display: jsx(() => ( display: jsx(() => (
<> <>
<div> <div>
@ -952,7 +979,10 @@ const factory = createLayer(id, () => {
> >
{whatIsHovered.value === "" ? undefined : ( {whatIsHovered.value === "" ? undefined : (
<> <>
<h3>{FACTORY_COMPONENTS[whatIsHovered.value].name}</h3> <h3>
{FACTORY_COMPONENTS[whatIsHovered.value].name}{" "}
<HotkeyVue hotkey={hotkeys[whatIsHovered.value]} />
</h3>
<br /> <br />
{FACTORY_COMPONENTS[whatIsHovered.value].description} {FACTORY_COMPONENTS[whatIsHovered.value].description}
{FACTORY_COMPONENTS[whatIsHovered.value].energyCost ?? 0 ? ( {FACTORY_COMPONENTS[whatIsHovered.value].energyCost ?? 0 ? (