🔘 nubs
nubs is a user-input system for web games.
⚡ live demo! nubs.benevolent.games
👂 nubs listens to keyboards, mice, gamepads, etc
📝 nubs has ui for users to edit their own key bindings
📣 nubs emits nub_action
events, based on inputs and user bindings
🕹️ nubs has mobile-friendly virtual devices, like thumbsticks and buttons
👼 a project by benevolent.games
💖 free and open source
nubs installation
first, you have to get nubs installed onto your web page.
choose ONE path — the easy way, or the hard way:
- the easy way (for html enthusiasts)
- the advanced way (for web developers)
- install nubs npm package
npm install @benev/nubs
- import nubs elements, register them to the dom
import {getElements, themeElements, registerElements, themeCss} from "@benev/nubs"
registerElements(
themeElements(
themeCss,
getElements(),
)
)
nubs usage
now that nubs is installed onto your web page, you can start using nub elements.
- let's insert some cool nub elements into your html
<body>
- wrap your nub elements inside a
context
<nub-context
default-bindings="
👼 Cool Default Bindings
🖱 look :: lookmouse
🕹️ look :: lookstick
🕹️ move :: movestick
*️⃣ forward :: KeyW ArrowUp
*️⃣ backward :: KeyS ArrowDown
*️⃣ leftward :: KeyA ArrowLeft
*️⃣ rightward :: KeyD ArrowRight
*️⃣ jump :: Space
*️⃣ use :: KeyF Mouse3
*️⃣ primary :: Mouse1
*️⃣ secondary :: Mouse2
">
<nub-real-keyboard></nub-real-keyboard>
<nub-real-mouse name=lookmouse></nub-real-mouse>
<nub-stick name=movestick></nub-stick>
<nub-stick name=lookstick></nub-stick>
</nub-context>
- nub-context is for grouping nub inputs
- the context will only listen to inputs nested under it
- the context may contain virtual devices and editing ui
nub-real-*
elements render nothing and do not appear
- nub-context introduces key
bindings
- bindings define the associations between "inputs" and "actions"
- nub-context has ui that allows users to edit their
bindings
- an example input might be
KeyW
- an example action might be
forward
- in most cases, you probably want your app to listen to
nub_action
events like forward
rather than the specific keys
bindings
has its own funny little text format
- it uses emojis unironically, to indicate nub types
- it's just sugar for a JSON format that operates under the hood
- it's intended for users to be able to copy-paste these bindings files, to easily share them over discord or whatever
nub elements documentation
coming soon lol
<nub-context>
<nub-real-mouse>
<nub-real-keyboard>
<nub-stick>
<nub-gridboard>
<nub-editor>