Skip to content

Commit

Permalink
メソッド jieju() から呼び出すハンドラを設定できるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
kobalab committed Oct 30, 2022
1 parent f8a3a6c commit 47b691e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ module.exports = class Game {
this._speed = 3;
this._wait = 0;
this._timeout_id;

this._handler;
}

get model() { return this._model }
Expand All @@ -53,6 +55,8 @@ module.exports = class Game {
set speed(speed) { this._speed = speed }
set wait(wait) { this._wait = wait }

set handler(callback) { this._handler = callback }

add_paipu(paipu) {
this._paipu.log[this._paipu.log.length - 1].push(paipu);
}
Expand Down Expand Up @@ -681,6 +685,8 @@ module.exports = class Game {
this.call_players('jieju', msg, this._wait);

if (this._view) this._view.summary(this._paipu);

if (this._handler) this._handler();
}

get_reply(l) {
Expand Down
6 changes: 6 additions & 0 deletions test/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,12 @@ suite('Majiang.Game', ()=>{
assert.deepEqual(game._paipu.rank, [3,4,1,2]);
assert.deepEqual(game._paipu.point, ['-15','-35','45','5']);
});

test('ハンドラがある場合、それを呼び出すこと', (done)=>{
const game = init_game();
game.handler = done;
game.jieju();
});
});

suite('reply_kaiju()', ()=>{
Expand Down

0 comments on commit 47b691e

Please sign in to comment.