# h-input

> Typescript input helpers

Latest version **1.0.18** (published 2021-12-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install h-input
pnpm add h-input
yarn add h-input
bun add h-input
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.18 |
| Published | 2021-12-12 |
| First published | 2018-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 128.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | benjaminjackman |
| Maintainers | benjaminjackman |
| Keywords | ash9g, typescript |

## Links

- npm: https://www.npmjs.com/package/h-input
- npm.io page: https://npm.io/package/h-input

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.18 (latest) — 2021-12-12
- 1.0.17 — 2021-12-12
- 1.0.15 — 2021-12-12
- 1.0.14 — 2021-12-12
- 1.0.13 — 2021-12-12
- 1.0.9 — 2021-12-12
- 1.0.8 — 2019-01-18
- 1.0.7 — 2019-01-18
- 1.0.6 — 2019-01-18
- 1.0.5 — 2018-12-08
- 1.0.4 — 2018-12-06
- 1.0.3 — 2018-08-23
- 1.0.1 — 2018-08-23

## README

import {SnInputCmd, SnInputCmds} from "engine/input/SnInputs";
import {SnGame} from "engine/SnGame";
import {SynthButtonCodes} from "m/h-input/gamepad/SynthButtonCodes";
import {InputCls} from "m/h-input/Input";
import {InputBind, InputBinder} from "m/h-input/InputBinder";
import {RenderableTerminal} from "m/h-term/Terminal";
import {KeyCodes} from "m/wip/KeyCodes";

export class SnUserInterface {
  
  
  game?: SnGame
  terminal?: RenderableTerminal
  running: boolean = false
  input: InputCls = new InputCls()
  inputBinder: InputBinder<SnInputCmd> = new InputBinder(this.input)

  constructor() {}

  setGame(game: SnGame) {
    this.game = game
  }

  setTerminal(terminal: RenderableTerminal): any {
    this.terminal = terminal
  }


  addInputs() {
    //TODO: HTML Prevent Default!
    this.inputBinder.addBinds(
      InputBinder.createMovementBinds({
        U: SnInputCmds.U,
        D: SnInputCmds.D,
        L: SnInputCmds.L,
        R: SnInputCmds.R,
      }),
    )
    this.inputBinder.addBind(
      new InputBind(
        SnInputCmds.EndTurn,
        InputBinder.key(KeyCodes.Enter),
        InputBinder.btn(SynthButtonCodes.Start),
      ),
    )
    this.inputBinder.addBind(
      new InputBind(
        SnInputCmds.NextActor,
        InputBinder.key(KeyCodes.Tab),
        InputBinder.btn(SynthButtonCodes.RB),
      )
    )
    this.inputBinder.addBind(
      new InputBind(
        SnInputCmds.PrevActor,
        InputBinder.key(KeyCodes.Tab,{shift: true}),
        InputBinder.btn(SynthButtonCodes.LB),
      )
    )

  }

  startInput() {
    this.input.start()
    this.addInputs()
  }

  stopInput() {
    this.input.stop()
  }

  startLoop() {
    this.running = true
    requestAnimationFrame(this.gameLoop)
  }


  singleLoop = (time: number) => {
    this.input.beginUpdate()
    this.inputBinder.beginUpdate()
    if (this.game ) {
      if (this.inputBinder.getCommands().length > 0) {
      //Displatch the commands
      this.game.handleCommands(this.inputBinder.getCommands())
      }
      if (this.terminal) {
        this.game.render(this.terminal)
        this.terminal.render()    
      }
      
    }
    this.inputBinder.endUpdate()
    this.input.endUpdate()

  }

  gameLoop = (time: number) => {
    this.singleLoop(time)
    if (this.running) {
      requestAnimationFrame(this.gameLoop)
    }
  }
}

---
_Source: https://npm.io/package/h-input · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
