gamja/components/help.js

59 lines
1 KiB
JavaScript
Raw Normal View History

import { html, Component } from "../lib/index.js";
import { keybindings } from "../keybindings.js";
2021-03-08 11:25:00 -05:00
import commands from "../commands.js";
function KeyBindingsHelp() {
var l = keybindings.map((binding) => {
var keys = [];
if (binding.ctrlKey) {
keys.psuh("Ctrl");
}
if (binding.altKey) {
keys.push("Alt");
}
keys.push(binding.key);
keys = keys.map((name, i) => {
return html`
${i > 0 ? "+" : null}
<kbd>${name}</kbd>
`;
});
return html`
<dt>${keys}</dt>
<dd>${binding.description}</dd>
`;
});
return html`<dl>${l}</dl>`;
}
2021-03-08 11:25:00 -05:00
function CommandsHelp() {
var l = Object.keys(commands).map((name) => {
var cmd = commands[name];
var usage = "/" + name;
if (cmd.usage) {
usage += " " + cmd.usage;
}
return html`
<dt><strong><code>${usage}</code></strong></dt>
<dd>${cmd.description}</dd>
`;
});
return html`<dl>${l}</dl>`;
}
export default function Help() {
return html`
<h3>Key bindings</h3>
<${KeyBindingsHelp}/>
2021-03-08 11:25:00 -05:00
<h3>Commands</h3>
<${CommandsHelp}/>
`;
}