@benev/nubs
Version:
user-input system for web games
34 lines (26 loc) • 637 B
text/typescript
import {Waiting} from "../types/waiting.js"
import {KeycapView} from "../views/keycap.js"
export function renderKeycap({
waiting,
currentlyWaitingForThisEffect,
onClickRebind,
}: {
currentlyWaitingForThisEffect: boolean
waiting: undefined | Waiting
onClickRebind: (keyIndex: number) => void
}) {
return (code: string[], keyIndex: number) => KeycapView({
keyIndex,
code: code.length ? code.join(" ") : "-",
isWaiting: (
currentlyWaitingForThisEffect &&
waiting?.keyIndex === keyIndex
),
onClickRebind(event) {
if (!waiting) {
event.preventDefault()
onClickRebind(keyIndex)
}
},
})
}