1.0.18 • Published 2 years ago

h-input v1.0.18

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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 = 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) } } }

1.0.18

2 years ago

1.0.17

2 years ago

1.0.9

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

6 years ago

1.0.1

6 years ago