diff --git a/ChangeLog.md b/ChangeLog.md index 46c1065..1744a4e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,7 @@ +### v1.2.1 / 2024-02-25 + + - String の非推奨のメソッドを変更: substr() → slice() + ## v1.2.0 / 2024-02-03 - #5 麻雀サーバーに関する処理を追加 diff --git a/lib/board.js b/lib/board.js index f888a39..8b1665e 100644 --- a/lib/board.js +++ b/lib/board.js @@ -86,7 +86,7 @@ module.exports = class Board { this.lunban = dapai.l; this.shoupai[dapai.l].dapai(dapai.p, false); this.he[dapai.l].dapai(dapai.p); - this._lizhi = dapai.p.substr(-1) == '*'; + this._lizhi = dapai.p.slice(-1) == '*'; } fulou(fulou) { diff --git a/lib/game.js b/lib/game.js index 74c7364..268e6c9 100644 --- a/lib/game.js +++ b/lib/game.js @@ -72,7 +72,7 @@ module.exports = class Game { } say(name, l) { - if (this._view) this._view.say(name, l); + if (this._view) this._view.say(name, l); } stop(callback = ()=>{}) { @@ -298,12 +298,12 @@ module.exports = class Game { if (this._diyizimo) { if (! dapai.match(/^z[1234]/)) this._fengpai = false; - if (this._dapai && this._dapai.substr(0,2) != dapai.substr(0,2)) + if (this._dapai && this._dapai.slice(0,2) != dapai.slice(0,2)) this._fengpai = false; } else this._fengpai = false; - if (dapai.substr(-1) == '*') { + if (dapai.slice(-1) == '*') { this._lizhi[model.lunban] = this._diyizimo ? 2 : 1; this._yifa[model.lunban] = this._rule['一発あり']; } @@ -448,8 +448,8 @@ module.exports = class Game { let menfeng = this._hule.length ? this._hule.shift() : model.lunban; let rongpai = menfeng == model.lunban ? null : (this._hule_option == 'qianggang' - ? this._gang[0] + this._gang.substr(-1) - : this._dapai.substr(0,2) + ? this._gang[0] + this._gang.slice(-1) + : this._dapai.slice(0,2) ) + '_+=-'[(4 + model.lunban - menfeng) % 4]; let shoupai = model.shoupai[menfeng].clone(); let fubaopai = shoupai.lizhi ? model.shan.fubaopai : null; @@ -728,7 +728,7 @@ module.exports = class Game { else if (reply.dapai) { let dapai = reply.dapai.replace(/\*$/,''); if (this.get_dapai().find(p => p == dapai)) { - if (reply.dapai.substr(-1) == '*' && this.allow_lizhi(dapai)) { + if (reply.dapai.slice(-1) == '*' && this.allow_lizhi(dapai)) { this.say('lizhi', model.lunban); return this.delay(()=>this.dapai(reply.dapai)); } @@ -770,7 +770,7 @@ module.exports = class Game { return this.delay(()=>this.hule()); } - if (this._dapai.substr(-1) == '*') { + if (this._dapai.slice(-1) == '*') { model.defen[model.player_id[model.lunban]] -= 1000; model.lizhibang++; @@ -872,7 +872,7 @@ module.exports = class Game { this._hule.push(l); } else { - let p = this._gang[0] + this._gang.substr(-1); + let p = this._gang[0] + this._gang.slice(-1); let shoupai = model.shoupai[l].clone().zimo(p); if (Majiang.Util.xiangting(shoupai) == -1) this._neng_rong[l] = false; @@ -969,7 +969,7 @@ module.exports = class Game { } else { let p = (this._status == 'gang' - ? this._gang[0] + this._gang.substr(-1) + ? this._gang[0] + this._gang.slice(-1) : this._dapai ) + '_+=-'[(4 + model.lunban - l) % 4]; let hupai = model.shoupai[l].lizhi diff --git a/lib/he.js b/lib/he.js index 5ade8e2..e654e9e 100644 --- a/lib/he.js +++ b/lib/he.js @@ -23,7 +23,7 @@ module.exports = class He { if (! Majiang.Shoupai.valid_mianzi(m)) throw new Error(m); let p = m[0] + m.match(/\d(?=[\+\=\-])/), d = m.match(/[\+\=\-]/); if (! d) throw new Error(m); - if (this._pai[this._pai.length - 1].substr(0,2) != p) + if (this._pai[this._pai.length - 1].slice(0,2) != p) throw new Error(m); this._pai[this._pai.length - 1] += d; return this; diff --git a/lib/hule.js b/lib/hule.js index 4e63d71..682ec7f 100644 --- a/lib/hule.js +++ b/lib/hule.js @@ -116,7 +116,7 @@ function hule_mianzi_qidui(shoupai, hulepai) { for (let n = 1; n < bingpai.length; n++) { if (bingpai[n] == 0) continue; if (bingpai[n] == 2) { - let m = (s+n == hulepai.substr(0,2)) + let m = (s+n == hulepai.slice(0,2)) ? s+n+n + hulepai[2] + '!' : s+n+n; mianzi.push(m); @@ -140,14 +140,14 @@ function hule_mianzi_guoshi(shoupai, hulepai) { let nn = (s == 'z') ? [1,2,3,4,5,6,7] :[1,9]; for (let n of nn) { if (bingpai[n] == 2) { - let m = (s+n == hulepai.substr(0,2)) + let m = (s+n == hulepai.slice(0,2)) ? s+n+n + hulepai[2] + '!' : s+n+n; mianzi.unshift(m); n_duizi++; } else if (bingpai[n] == 1) { - let m = (s+n == hulepai.substr(0,2)) + let m = (s+n == hulepai.slice(0,2)) ? s+n + hulepai[2] + '!' : s+n; mianzi.push(m); @@ -177,7 +177,7 @@ function hule_mianzi_jiulian(shoupai, hulepai) { } } if (mianzi.length != 14) return []; - mianzi += hulepai.substr(1) + '!'; + mianzi += hulepai.slice(1) + '!'; return [ [mianzi] ]; } @@ -684,7 +684,7 @@ function hule(shoupai, rongpai, param) { if (rongpai) { if (! rongpai.match(/[\+\=\-]$/)) throw new Error(rongpai); - rongpai = rongpai.substr(0,2) + rongpai.substr(-1); + rongpai = rongpai.slice(0,2) + rongpai.slice(-1); } let max; diff --git a/lib/index.js b/lib/index.js index f44e5f6..6eaa890 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,5 @@ /*! - * @kobalab/majiang-core v1.2.0 + * @kobalab/majiang-core v1.2.1 * * Copyright(C) 2021 Satoshi Kobayashi * Released under the MIT license diff --git a/lib/player.js b/lib/player.js index f569bbc..767c438 100644 --- a/lib/player.js +++ b/lib/player.js @@ -115,7 +115,7 @@ module.exports = class Player { this._diyizimo = false; if (gang.l != this._menfeng && ! gang.m.match(/^[mpsz]\d{4}$/)) { - let s = gang.m[0], n = +gang.m.substr(-1)||5; + let s = gang.m[0], n = +gang.m.slice(-1)||5; if (this.hulepai.find(p=> p == s+n)) this._neng_rong = false; } } diff --git a/lib/shoupai.js b/lib/shoupai.js index fb6e849..3ebcd4f 100644 --- a/lib/shoupai.js +++ b/lib/shoupai.js @@ -84,7 +84,7 @@ module.exports = class Shoupai { } shoupai._zimo = shoupai._zimo || zimo || null; - shoupai._lizhi = bingpai.substr(-1) == '*'; + shoupai._lizhi = bingpai.slice(-1) == '*'; return shoupai; } @@ -194,7 +194,7 @@ module.exports = class Shoupai { let s = p[0], n = +p[1]; this.decrease(s, n); this._zimo = null; - if (p.substr(-1) == '*') this._lizhi = true; + if (p.slice(-1) == '*') this._lizhi = true; return this; } @@ -224,11 +224,11 @@ module.exports = class Shoupai { this._fulou.push(m); } else if (m.match(/\d{3}[\+\=\-]\d$/)) { - let m1 = m.substr(0,5); + let m1 = m.slice(0,5); let i = this._fulou.findIndex(m2 => m1 == m2); if (i < 0) throw new Error([this, m]); this._fulou[i] = m; - this.decrease(s, m.substr(-1)); + this.decrease(s, m.slice(-1)); } else throw new Error([this, m]); this._zimo = null; @@ -381,7 +381,7 @@ module.exports = class Shoupai { else { if (this._lizhi) continue; for (let m of this._fulou) { - if (m.replace(/0/g,'5').substr(0,4) == s+n+n+n) { + if (m.replace(/0/g,'5').slice(0,4) == s+n+n+n) { if (n == 5 && bingpai[0] > 0) mianzi.push(m+0); else mianzi.push(m+n); } diff --git a/package-lock.json b/package-lock.json index d915ba6..6924545 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kobalab/majiang-core", - "version": "1.2.0", + "version": "1.2.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@kobalab/majiang-core", - "version": "1.2.0", + "version": "1.2.1", "license": "MIT", "devDependencies": { "mocha": "^10.2.0", diff --git a/package.json b/package.json index 628aa0a..1586272 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kobalab/majiang-core", - "version": "1.2.0", + "version": "1.2.1", "description": "麻雀基本ライブラリ", "publishConfig": { "access": "public"