Gaboa
8/31/2017 - 10:29 AM

OldKeyboard

export class OldKeyboard {

    constructor({
        game,
        level
    }) {

        this.game = game;
        this.level = level;

        this.enabled = true;
        this.up$ = this.game.keyboard$
            .map(next => String(next).toLowerCase())
            .filter(next => next === 'arrowup');
        this.down$ = this.game.keyboard$
            .map(next => String(next).toLowerCase())
            .filter(next => next === 'arrowdown');
        this.left$ = this.game.keyboard$
            .map(next => String(next).toLowerCase())
            .filter(next => next === 'arrowleft');
        this.right$ = this.game.keyboard$
            .map(next => String(next).toLowerCase())
            .filter(next => next === 'arrowright');
        this.space$ = this.game.keyboard$
            .map(next => String(next).toLowerCase())
            .filter(next => next === 'space');

        // Roll on Space
        this.space$
            .filter(evt => this.enabled)
            .subscribe(evt => {
                this.game.request.sendRoll({
                    level: this.level.getCurrentLevel(),
                    value: this.level.getCurrentValue()
                });
                this.level.machine.screen.roll();
            });

        // Bet level
        this.up$
            .filter(evt => this.enabled)
            .subscribe(next => this.level.machine.balance.changeLevelUp());
        this.down$
            .filter(evt => this.enabled)
            .subscribe(next => this.level.machine.balance.changeLevelDown());

        // Coin value
        this.left$
            .filter(evt => this.enabled)
            .subscribe(next => this.level.machine.balance.changeValueDown());
        this.right$
            .filter(evt => this.enabled)
            .subscribe(next => this.level.machine.balance.changeValueUp());

    }

}