Files
VibemakerSandbox/app/src/ui/ControlsHelp.jsx
T
chenlin c72f5da12c feat: release v0.5 with shared interactive arenas and textured RP1
Unify lighting and line-colour controls across robots, replace the football with a shared layout of draggable physical props, and import the supplied RP1 GLBs without changing trained physics or policies.

Include reproducible visual import/provenance, regression coverage and verification records. Verified 66 unit tests, 55 browser tests and production-build checks.
2026-10-30 14:14:03 +08:00

143 lines
4.2 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 (
<Box
component="aside"
aria-label="Keyboard controls"
sx={{
position: "fixed",
right: 24,
top: 20,
zIndex: 12,
maxWidth: 300,
maxHeight: "calc(100vh - 140px)",
overflowY: "auto",
color: "#faf8f2",
background: "rgba(8,8,12,.82)",
border: "1px solid #777",
fontFamily: "monospace",
fontSize: 12,
p: 1.5,
}}
>
<button
type="button"
aria-expanded={open}
onClick={() => useGame.setState({ helpOpen: !open })}
style={{
font: "inherit",
background: "none",
border: 0,
color: "inherit",
cursor: "pointer",
padding: 0,
}}
>
Keyboard controls {open ? "−" : "+"}
</button>
{open && (
<Box sx={{ display: "grid", gap: 1, mt: 1.5 }}>
{bindings.map((row) => {
const clickable = ![
"move_forward",
"move_backward",
"turn_left",
"turn_right",
"reset",
"pause",
].includes(row.action);
return (
<Box
key={row.action}
component={clickable ? "button" : "div"}
type={clickable ? "button" : undefined}
disabled={
clickable
? row.disabled ||
(row.action === "chaseToggle" ? blocked : disabled)
: undefined
}
onClick={
clickable
? () => 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" },
}}
>
<strong style={{ color: neutral ? "#83bfff" : "#ff9a55" }}>
{row.codes.map((c) => caps[c] ?? labels[c] ?? c).join(" / ")}
</strong>
<br />
{row.label}
</Box>
);
})}
<div>
Mouse drag: orbit · wheel: zoom
{physicalDrag && (
<>
<br />
Drag robot / geometry: apply force
</>
)}
</div>
{license && (
<details>
<summary>Asset license</summary>
<small>{license}</small>
</details>
)}
</Box>
)}
</Box>
);
}