import { useEffect, useState } from "react"; import Box from "@mui/material/Box"; import { useGame, gameApi } from "../store.js"; import { readLayoutMap, resolveKeycaps } from "./keyboard-layout.js"; const caps = { ArrowUp: "↑", ArrowDown: "↓", ArrowLeft: "←", ArrowRight: "→", Space: "Space", Escape: "Esc", }; export default function ControlsHelp() { const open = useGame((s) => s.helpOpen), bindings = useGame((s) => s.inputBindings), neutral = useGame((s) => s.presentationTheme === "neutral"), physicalDrag = useGame((s) => s.runtimeCapabilities.physicalDrag), blocked = useGame((s) => s.runtimePhase !== "ready"); const disabled = useGame( (s) => s.runtimePhase !== "ready" || s.paused || s.fallen, ), license = useGame((s) => s.robotLicense); const [map, setMap] = useState(null); useEffect(() => { let cancelled = false; const update = async () => { const next = await readLayoutMap(); if (!cancelled) setMap(next); }; update(); navigator.keyboard?.addEventListener?.("layoutchange", update); return () => { cancelled = true; navigator.keyboard?.removeEventListener?.("layoutchange", update); }; }, []); const { labels } = resolveKeycaps( bindings.flatMap((b) => b.codes.filter((c) => c.startsWith("Key"))), map, ); return ( {open && ( {bindings.map((row) => { const clickable = ![ "move_forward", "move_backward", "turn_left", "turn_right", "reset", "pause", ].includes(row.action); return ( gameApi.triggerAction?.(row.action) : undefined } sx={{ font: "inherit", color: "inherit", textAlign: "left", background: "none", border: 0, p: 0, cursor: clickable ? "pointer" : "default", "&:disabled": { opacity: 0.45 }, "&:focus-visible": { outline: "2px solid #83bfff" }, }} > {row.codes.map((c) => caps[c] ?? labels[c] ?? c).join(" / ")}
{row.label}
); })}
Mouse drag: orbit · wheel: zoom {physicalDrag && ( <>
Drag robot / geometry: apply force )}
{license && (
Asset license {license}
)}
)}
); }