logo

Babylon.js Market

Unlock

Install with the CLI:

bjs download PokerInput

PokerInput

Tap F to fold, V to call, R to raise — but only when it's actually your turn. PokerInput turns the keyboard into the same bus intent the HUD buttons emit, gated so a stray keypress between turns does nothing.

What it does

PokerInput is the human seat's keyboard. A keypress should fire an action only when it's the player's turn AND that action is on the table — so the core (PokerInput.core) owns two pure things: a configurable KeyboardEvent.code → intent map, and a tiny turn-gate state machine.

resolveKey(code, gate, bindings) is the whole decision. The deal code always resolves to a deal — ungated, since the director ignores a deal when it isn't awaiting one. An action code resolves only when that action is in the live allowed set. Everything else swallows the key.

The gate is fed by the PACED prompt poker.display.actionRequired from the TurnPacer — not the raw poker.actionRequired — so the keyboard goes live only after the opponents have visibly acted. openGate records the seat and its offered actions; the gate closes the instant the human's turn ends: a paced poker.display.turn handoff, the director's poker.currentTurn going null or to another seat, a poker.actionTaken for the human, or the key the System itself just submitted.

The thin PokerInputSystem is the driver. It attaches a window keydown listener in onInitialize (guarded by typeof window, detached in onShutdown — the PlayerInput pattern), feeds those signals into the gate, and emits poker.actionSubmitted { type } for a legal action key — the exact event PokerBetting consumes from the HUD buttons — or pokerTable.deal {} for the deal key. No 3D imports: only the browser keyboard and the bus.

Use it in a scene

Seat one PokerInput per table and name the human's seat id.

A scene is just data — a list of entities, each with its components. At startup the SceneLoader turns this JSON into a live world; edit the file and reload to rebuild it.

Build it from scratch with the bjs CLI:

  1. 1Scaffold a project
    npm create @babylonjsmarket/arcade@latest my-game

    World, renderer, and dev server — ready to run.

  2. 2Install dependencies
    cd my-game && npm install
  3. 3Add PokerInput
    bjs download PokerInput

    Copies its source into src/ so the scene resolves.

    First time? Run bjs login once.

  4. 4Paste the scene into src/scenes/arcade-room.ts and run
    npm run dev

    SceneLoader builds the world from the JSON; reload to rebuild.

JSON
{
  "UI": {
    "components": {
      "PokerInput": { "humanSeatId": "player" }
    }
  }
}

It wires itself — once the TurnPacer's prompt reaches the human, the keys go live.

Default keys

KeyAction
Ffold
Ccheck
V / Entercall
Rraise
Bbet
Aall-in
Spacedeal the next hand (ungated)

The reference game maps Space to bet; here Space is reserved for the deal, so bet moves to B.

Props

PropTypeDefaultMeaning
enabledbooleantrueWhether the seat accepts keyboard input.
humanSeatIdstring"player"The seat this input drives — only its paced prompt opens the gate.
keyBindingsPartial<PokerKeyBindings>defaultsA { actions, deal } override, merged on top of the defaults.

Events

DirectionEventPayloadMeaning
outpoker.actionSubmitted{ type }A legal action key fired (same event the HUD buttons emit).
outpokerTable.deal{}The deal key — deal the next hand.
inpoker.display.actionRequired{ playerId, options? }Paced human prompt; opens the gate for the human seat.
inpoker.display.turn{ playerId }Paced handoff; closes the gate when it moves off the human.
inpoker.currentTurn{ playerId }Director's live turn; closes the gate on null / another seat.
inpoker.actionTaken{ playerId, action }Closes the gate when the human's own action lands.

Notes

  • The Component holds the serializable config; the System holds the live gate. So serialize() round-trips { enabled, humanSeatId, keyBindings } and nothing transient.
  • enabled is the inherited Component accessor (it emits the enabled/disabled events on change) — the constructor assigns through the setter rather than shadowing it.
  • After a legal action emits, the System closes the gate immediately, so the same key can't double-submit before the next paced prompt arrives.

More like this

PokerBetting
PokerMultiplayer
PokerTableDirector
TurnPacer
CardFan
DeckDealer
FlightIntent
Flipper
Jump
KeyboardInput
KeyboardMover
PinballBuilderInput
PlayerFlightInput
PlayerInput
PlayerInputBridge
Plunger
PokerAI
PokerAIBill
PokerAICali
PokerAIRandy
PokerAIShark
PokerAISurge
PokerAITilt
PokerHUD
PokerHandEval
PokerSeating
PokerTableCards

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search