Skip to content

Commit

Permalink
Merge branch 'release/v0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
kobalab committed Oct 30, 2022
2 parents 769d46b + 25c1402 commit 359e5ad
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
7 changes: 7 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v0.4.0 2022-10-31

- Majiang.Game
- メソッド set handler() を追加
- メソッド jieju() に set handler() で設定した関数を呼び出す処理を追加
- 起家の設定方法を簡潔な記述に変更

### v0.3.1 / 2022-10-25

- 脆弱性警告に対応
Expand Down
9 changes: 7 additions & 2 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 @@ -162,8 +166,7 @@ module.exports = class Game {

kaiju(qijia) {

this._model.qijia = (qijia == null) ? Math.floor(Math.random() * 4)
: qijia;
this._model.qijia = qijia ?? Math.floor(Math.random() * 4);

this._max_jushu = this._rule['場数'] == 0 ? 0
: this._rule['場数'] * 4 - 1;
Expand Down Expand Up @@ -682,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
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* @kobalab/majiang-core v0.3.1
* @kobalab/majiang-core v0.4.0
*
* Copyright(C) 2021 Satoshi Kobayashi
* Released under the MIT license
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kobalab/majiang-core",
"version": "0.3.1",
"version": "0.4.0",
"description": "麻雀基本ライブラリ",
"publishConfig": {
"access": "public"
Expand Down
12 changes: 9 additions & 3 deletions test/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ suite('Majiang.Game', ()=>{

test('起家が設定されること', ()=>{
MSG =[];
game.kaiju(1);
assert.equal(game._model.qijia, 1);
game.kaiju(0);
assert.equal(game._model.qijia, 0);
});
test('牌譜が初期化されること', ()=>{
assert.equal(game._paipu.title, game._model.title);
Expand All @@ -294,7 +294,7 @@ suite('Majiang.Game', ()=>{
rule: game._rule,
title: game._model.title,
player: game._model.player,
qijia: 1
qijia: 0
}
};
assert.deepEqual(MSG[id], msg);
Expand Down 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 359e5ad

Please sign in to comment.