From 56028b8a60719af2bfae8aaaebe4d5a984446852 Mon Sep 17 00:00:00 2001 From: kuangshen04 <2832899707@qq.com> Date: Mon, 4 Mar 2024 22:48:02 +0800 Subject: [PATCH 1/6] bugfix --- noname/game/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noname/game/index.js b/noname/game/index.js index 0c20f0b62..1276645d7 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -5874,7 +5874,7 @@ export class Game extends Uninstantable { return false; } - const useCache = !lib.config.compatiblemode && !event.skill + const useCache = !lib.config.compatiblemode && !event.skill && !event.multitarget && ['button', 'card', 'target'].every(type => { if (!event[`filter${uppercaseType(type)}`]) return true; // if (typeof event[`select${uppercaseType(type)}`] === 'function') return false; From 05cbfa670124dc54ea7302375add756d9f76ba23 Mon Sep 17 00:00:00 2001 From: kuangshen04 <2832899707@qq.com> Date: Mon, 4 Mar 2024 23:19:32 +0800 Subject: [PATCH 2/6] =?UTF-8?q?uncheck=E5=A2=9E=E5=8A=A0hook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/game/index.js | 91 ++++++++++++++++++++--------------------- noname/library/index.js | 2 + 2 files changed, 46 insertions(+), 47 deletions(-) diff --git a/noname/game/index.js b/noname/game/index.js index 1276645d7..ad7ebb1a9 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -6113,48 +6113,49 @@ export class Game extends Uninstantable { } } static uncheck(...args) { - let i, j; + const event = _status.event; + const players = game.players.slice(); + if (_status.event.deadTarget) players.addArray(game.dead); + game.callHook("uncheckBegin", [event]); if (game.chess) { let shadows = ui.chessContainer.getElementsByClassName('playergrid temp'); - while (shadows.length) { - shadows[0].remove(); - } + while (shadows.length) shadows[0].remove(); } - if ((args.length == 0 || args.includes('card')) && _status.event.player) { - let cards = _status.event.player.getCards('hejsx'); - for (j = 0; j < cards.length; j++) { - cards[j].classList.remove('selected'); - cards[j].classList.remove('selectable'); - if (cards[j]._tempName) { - cards[j]._tempName.delete(); - delete cards[j]._tempName; - } - cards[j].updateTransform(); - } - ui.selected.cards.length = 0; - _status.event.player.node.equips.classList.remove('popequip'); - } - let players = game.players.slice(0); - if (_status.event.deadTarget) players.addArray(game.dead); - if ((args.length == 0 || args.includes('target'))) { - for (j = 0; j < players.length; j++) { - players[j].classList.remove('selected'); - players[j].classList.remove('selectable'); - if (players[j].instance) { - players[j].instance.classList.remove('selected'); - players[j].instance.classList.remove('selectable'); - } - } - ui.selected.targets.length = 0; - } - if ((args.length == 0 || args.includes('button')) && _status.event.dialog && _status.event.dialog.buttons) { - for (let j = 0; j < _status.event.dialog.buttons.length; j++) { - _status.event.dialog.buttons[j].classList.remove('selectable'); - _status.event.dialog.buttons[j].classList.remove('selected'); - } + if (args.length === 0) args = ['button', 'card', 'target']; + _status.event.player.node.equips.classList.remove('popequip'); + + if (args.includes('button') && event.dialog && event.dialog.buttons) { + event.dialog.buttons.forEach(button => { + button.classList.remove('selectable'); + button.classList.remove('selected'); + }); ui.selected.buttons.length = 0; } - if (args.length == 0) { + if (args.includes('card') && event.player) { + const cards = event.player.getCards('hejsx'); + cards.forEach(card => { + card.classList.remove('selected'); + card.classList.remove('selectable'); + if (card._tempName) { + card._tempName.delete(); + delete card._tempName; + } + card.updateTransform(); + }); + ui.selected.cards.length = 0; + } + if (args.includes('target')) { + players.forEach(target => { + target.classList.remove('selected'); + target.classList.remove('selectable'); + if (target.instance) { + target.instance.classList.remove('selected'); + target.instance.classList.remove('selectable'); + } + }); + ui.selected.targets.length = 0; + } + if (args.length === 3) { ui.arena.classList.remove('selecting'); ui.arena.classList.remove('tempnoe'); _status.imchoosing = false; @@ -6162,20 +6163,16 @@ export class Game extends Uninstantable { _status.mousedragging = null; _status.mousedragorigin = null; - while (ui.touchlines.length) { - ui.touchlines.shift().delete(); - } + ui.touchlines.forEach(i => i.delete()); + ui.touchlines.length = 0; } ui.canvas.width = ui.arena.offsetWidth; ui.canvas.height = ui.arena.offsetHeight; - for (let i = 0; i < players.length; i++) { - players[i].unprompt(); - } - for (let i = 0; i < _status.dragline.length; i++) { - if (_status.dragline[i]) _status.dragline[i].remove(); - } - ui.arena.classList.remove('dragging'); + players.forEach(i => i.unprompt()); + _status.dragline.forEach(i => i && i.remove()); _status.dragline.length = 0; + ui.arena.classList.remove('dragging'); + game.callHook("uncheckEnd", [event]); } /** * @param { Player } player1 diff --git a/noname/library/index.js b/noname/library/index.js index f7ff023bb..8d3c74fcc 100644 --- a/noname/library/index.js +++ b/noname/library/index.js @@ -328,6 +328,8 @@ export class Library extends Uninstantable { //game.check美化 checkBegin: [], checkEnd: [], + uncheckBegin: [], + uncheckEnd: [], }; /** From 1936eb4cffe2aacb81401cfc4c1afd360d454412 Mon Sep 17 00:00:00 2001 From: kuangshen04 <2832899707@qq.com> Date: Mon, 4 Mar 2024 23:38:28 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0lib.hooks=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/library/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/noname/library/index.js b/noname/library/index.js index 8d3c74fcc..205cad988 100644 --- a/noname/library/index.js +++ b/noname/library/index.js @@ -146,6 +146,11 @@ export class Library extends Uninstantable { } //函数钩子 + /** + * 你可以往这里加入{钩子名:函数数组},并在数组里增加你的自定义函数 + * 这样当某个地方调用game.callHook(钩子名,[...函数参数])时,就会按顺序将对应数组中的每个函数运行一遍(传参为callHook的第二个参数)。 + * 你可以将hook机制类比为event.trigger(),但是这里只能放同步代码 + */ static hooks = { // 本体势力的颜色 addGroup: [(id, _short, _name, config) => { From d13891670511af72f6c51661d97f100dcbf2176c Mon Sep 17 00:00:00 2001 From: kuangshen04 <2832899707@qq.com> Date: Tue, 5 Mar 2024 19:46:37 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E8=BF=9B=E4=B8=80=E6=AD=A5=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0hook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/game/index.js | 142 ++++++++++++++++------------------------ noname/library/index.js | 42 +++++++++++- 2 files changed, 97 insertions(+), 87 deletions(-) diff --git a/noname/game/index.js b/noname/game/index.js index ad7ebb1a9..ae472c2f2 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -1881,12 +1881,12 @@ export class Game extends Uninstantable { config: objectConfig } try{ - if (precontent) { - _status.extension = name; - - await (gnc.is.generatorFunc(precontent) ? gnc.of(precontent) : precontent).call(object, config); - delete _status.extension; - } + if (precontent) { + _status.extension = name; + + await (gnc.is.generatorFunc(precontent) ? gnc.of(precontent) : precontent).call(object, config); + delete _status.extension; + } }catch(e1){ console.log(`加载《${name}》扩展的precontent时出现错误。`,e1); if(!lib.config.extension_alert) alert(`加载《${name}》扩展的precontent时出现错误。\n该错误本身可能并不影响扩展运行。您可以在“设置→通用→无视扩展报错”中关闭此弹窗。\n${decodeURI(e1.stack)}`); @@ -5891,19 +5891,10 @@ export class Game extends Uninstantable { game.Check.skill(event); - player.node.equips.classList.remove('popequip'); - if (event.filterCard && lib.config.popequip && !_status.nopopequip && get.is.phoneLayout() && - typeof event.position === 'string' && event.position.includes('e') && - player.node.equips.querySelector('.card.selectable')) { - player.node.equips.classList.add('popequip'); - auto_confirm = false; - } - - _status.multitarget = false; - const skillinfo = get.info(_status.event.skill); + const skillinfo = get.info(event.skill)||{}; if (_status.event.multitarget) _status.multitarget = true; - else if (_status.event.name === 'chooseToUse' && skillinfo) { + else if (_status.event.name === 'chooseToUse') { if (skillinfo.multitarget && !skillinfo.multiline) _status.multitarget = true; if (skillinfo.viewAs && typeof skillinfo.viewAs !== 'function') { const cardinfo = get.info(get.card()); @@ -5913,6 +5904,13 @@ export class Game extends Uninstantable { } } + player.node.equips.classList.remove('popequip'); + if (event.filterCard && lib.config.popequip && !_status.nopopequip && get.is.phoneLayout() && + typeof event.position === 'string' && event.position.includes('e') && + player.node.equips.querySelector('.card.selectable')) { + player.node.equips.classList.add('popequip'); + auto_confirm = false; + } if (event.isMine() && game.chess && get.config('show_distance') && game.me) { const players = game.players.slice(); @@ -5928,7 +5926,22 @@ export class Game extends Uninstantable { }); } - if (event.isMine()) game.Check.confirm(event, { ok, auto, auto_confirm }); + let confirm = ''; + if (ok && (!event.filterOk || event.filterOk())) confirm += 'o'; + if (!event.forced && !event.fakeforce && get.noSelected()) confirm += 'c'; + if (event.isMine()) game.Check.confirm(event, confirm); + + game.callHook("checkEnd", [event]); + + if (event.isMine() && confirm.includes('o') + && auto && (auto_confirm || skillinfo.direct) && !_status.touchnocheck + && !_status.mousedown && (!_status.mousedragging || !_status.mouseleft)) { + if (ui.confirm) ui.confirm.close(); + if (event.skillDialog === true) event.skillDialog = false; + ui.click.ok(); + _status.mousedragging = null; + if (skillinfo.preservecancel) ui.create.confirm('c'); + } // if (ui.confirm && ui.confirm.lastChild.link == 'cancel') { // if (_status.event.type == 'phase' && !_status.event.skill) { @@ -5938,12 +5951,10 @@ export class Game extends Uninstantable { // ui.confirm.lastChild.innerHTML = '取消'; // } // } - - game.callHook("checkEnd", [event]); return ok; } static Check = class extends Uninstantable { - static processSelection({ type, items, event, useCache, isSelectable, custom }) { + static processSelection({ type, items, event, useCache, isSelectable }) { let ok = true, auto; let selectableItems = false; const uppercaseType = (type) => type[0].toUpperCase() + type.slice(1); @@ -5997,7 +6008,7 @@ export class Game extends Uninstantable { if (item.classList.contains('selectable')) selectableItems = true; else if (item.classList.contains('selected')) item.classList.add('selectable'); - if (custom) custom(item); + game.callHook(`check${uppercaseType(type)}`, [item, event]); }); if (event[`${type}Required`] && uiSelected.length === 0) ok = false; @@ -6010,7 +6021,7 @@ export class Game extends Uninstantable { static button(event, useCache) { const player = event.player; const buttons = event.dialog.buttons; - const isSelectable = button => { + const isSelectable = (button, event) => { if (!lib.filter.buttonIncluded(button)) return false; if (button.classList.contains('unselectable')) return false; return event.filterButton(button, player); @@ -6019,21 +6030,14 @@ export class Game extends Uninstantable { } static card(event, useCache) { const player = event.player; - const players = game.players.slice(); - if (event.deadTarget) players.addArray(game.dead); const cards = player.getCards(event.position); - const isSelectable = card => { + const isSelectable = (card, event) => { if (card.classList.contains('uncheck')) return false; if (player.isOut()) return false; if (!lib.filter.cardRespondable(card, player)) return false; return event.filterCard(card, player); } - const custom = lib.config.cardtempname === 'off' ? null : card => { - if (get.name(card) === card.name && get.is.sameNature(get.nature(card), card.nature, true)) return; - const node = ui.create.cardTempName(card); - if (lib.config.cardtempname !== 'default') node.classList.remove('vertical'); - } - return game.Check.processSelection({ type: 'card', items: cards, event, useCache, isSelectable, custom }); + return game.Check.processSelection({ type: 'card', items: cards, event, useCache, isSelectable }); } static target(event, useCache) { const player = event.player; @@ -6045,17 +6049,7 @@ export class Game extends Uninstantable { if (target.isOut()) return false; return event.filterTarget(card, player, target); } - const custom = target => { - if (!target.instance) return; - ['selected', 'selectable'].forEach(className => { - if (target.classList.contains(className)) { - target.instance.classList.add(className); - } else { - target.instance.classList.remove(className); - } - }); - } - return game.Check.processSelection({ type: 'target', items: targets, event, useCache, isSelectable, custom }); + return game.Check.processSelection({ type: 'target', items: targets, event, useCache, isSelectable }); } static skill(event) { if (ui.skills) ui.skills.close(); @@ -6081,53 +6075,36 @@ export class Game extends Uninstantable { if (globalSkills.length) ui.create.skills2(globalSkills); if (equipSkills.length) ui.create.skills3(equipSkills); } - static confirm(event, { ok, auto, auto_confirm }) { - const skillinfo = get.info(event.skill) || {}; - if (ok && (!event.filterOk || event.filterOk()) - && auto && (auto_confirm || skillinfo.direct) - && (!_status.mousedragging || !_status.mouseleft) && !_status.mousedown && !_status.touchnocheck) { - if (ui.confirm && !skillinfo.preservecancel) { - ui.confirm.close(); - } - if (!ui.confirm && skillinfo.preservecancel) { - ui.create.confirm('c'); - } - if (event.skillDialog === true) event.skillDialog = false; - ui.click.ok(); - _status.mousedragging = null; + static confirm(event, confirm) { + ui.arena.classList.add('selecting'); + if (event.filterTarget && (!event.filterCard || !event.position || (typeof event.position == 'string' && !event.position.includes('e')))) { + ui.arena.classList.add('tempnoe'); } - else { - ui.arena.classList.add('selecting'); - if (event.filterTarget && (!event.filterCard || !event.position || (typeof event.position == 'string' && !event.position.includes('e')))) { - ui.arena.classList.add('tempnoe'); - } - game.countChoose(); - if (!_status.noconfirm && !_status.event.noconfirm - && (_status.mouseleft || !_status.mousedown)) { - let str = ''; - if (ok && (!event.filterOk || event.filterOk())) str += 'o'; - if (!event.forced && !event.fakeforce && get.noSelected()) str += 'c'; - ui.create.confirm(str); - } + game.countChoose(); + if (!_status.noconfirm && !_status.event.noconfirm && (_status.mouseleft || !_status.mousedown)) { + ui.create.confirm(confirm); } } } static uncheck(...args) { + if (args.length === 0) args = ['button', 'card', 'target']; const event = _status.event; const players = game.players.slice(); if (_status.event.deadTarget) players.addArray(game.dead); - game.callHook("uncheckBegin", [event]); + + game.callHook("uncheckBegin", [event, args]); + if (game.chess) { - let shadows = ui.chessContainer.getElementsByClassName('playergrid temp'); - while (shadows.length) shadows[0].remove(); + const shadows = Array.from(ui.chessContainer.querySelectorAll('.playergrid.temp')); + shadows.forEach(i => i.remove()); } - if (args.length === 0) args = ['button', 'card', 'target']; - _status.event.player.node.equips.classList.remove('popequip'); + if(event.player) event.player.node.equips.classList.remove('popequip'); if (args.includes('button') && event.dialog && event.dialog.buttons) { event.dialog.buttons.forEach(button => { button.classList.remove('selectable'); button.classList.remove('selected'); + game.callHook("uncheckButton", [button, event]); }); ui.selected.buttons.length = 0; } @@ -6136,11 +6113,8 @@ export class Game extends Uninstantable { cards.forEach(card => { card.classList.remove('selected'); card.classList.remove('selectable'); - if (card._tempName) { - card._tempName.delete(); - delete card._tempName; - } - card.updateTransform(); + card.updateTransform(false); + game.callHook("uncheckCard", [card, event]); }); ui.selected.cards.length = 0; } @@ -6148,10 +6122,7 @@ export class Game extends Uninstantable { players.forEach(target => { target.classList.remove('selected'); target.classList.remove('selectable'); - if (target.instance) { - target.instance.classList.remove('selected'); - target.instance.classList.remove('selectable'); - } + game.callHook("uncheckTarget", [target, event]); }); ui.selected.targets.length = 0; } @@ -6172,7 +6143,8 @@ export class Game extends Uninstantable { _status.dragline.forEach(i => i && i.remove()); _status.dragline.length = 0; ui.arena.classList.remove('dragging'); - game.callHook("uncheckEnd", [event]); + + game.callHook("uncheckEnd", [event, args]); } /** * @param { Player } player1 diff --git a/noname/library/index.js b/noname/library/index.js index 205cad988..672760fc5 100644 --- a/noname/library/index.js +++ b/noname/library/index.js @@ -330,11 +330,47 @@ export class Library extends Uninstantable { game.dynamicStyle.addObject(result2); } }], - //game.check美化 + //game.check checkBegin: [], checkEnd: [], + checkButton: [], + checkCard: [ + function updateTempname(card, event) { + if (lib.config.cardtempname === 'off') return; + if (get.name(card) === card.name && get.is.sameNature(get.nature(card), card.nature, true)) return; + const node = ui.create.cardTempName(card); + if (lib.config.cardtempname !== 'default') node.classList.remove('vertical'); + }, + ], + checkTarget: [ + function updateInstance(target, event) { + if (!target.instance) return; + ['selected', 'selectable'].forEach(className => { + if (target.classList.contains(className)) { + target.instance.classList.add(className); + } else { + target.instance.classList.remove(className); + } + }); + }, + ], uncheckBegin: [], uncheckEnd: [], + uncheckButton: [], + uncheckCard: [ + function removeTempname(card, event) { + if (!card._tempName) return; + card._tempName.delete(); + delete card._tempName; + }, + ], + uncheckTarget: [ + function removeInstance(target, event) { + if (!target.instance) return; + target.instance.classList.remove('selected'); + target.instance.classList.remove('selectable'); + }, + ], }; /** @@ -7926,7 +7962,9 @@ export class Library extends Uninstantable { let type; try { type = typeof obj[text]; - } catch {} + } catch { + void 0; + } if (type == 'function') { className += 'function'; } From 8c7ee6601122d0546b9506a8c1dd765363198062 Mon Sep 17 00:00:00 2001 From: kuangshen04 <2832899707@qq.com> Date: Tue, 5 Mar 2024 19:53:06 +0800 Subject: [PATCH 5/6] bugfix --- noname/game/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/noname/game/index.js b/noname/game/index.js index ae472c2f2..a6856e3ec 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -5926,8 +5926,9 @@ export class Game extends Uninstantable { }); } + ok = ok && (!event.filterOk || event.filterOk()); let confirm = ''; - if (ok && (!event.filterOk || event.filterOk())) confirm += 'o'; + if (ok) confirm += 'o'; if (!event.forced && !event.fakeforce && get.noSelected()) confirm += 'c'; if (event.isMine()) game.Check.confirm(event, confirm); From f1ea8d710edf2f304778b88b847b1fce67b26e38 Mon Sep 17 00:00:00 2001 From: kuangshen04 <2832899707@qq.com> Date: Tue, 5 Mar 2024 20:28:32 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=8B=86=E5=88=86hook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/game/index.js | 12 +----------- noname/library/index.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/noname/game/index.js b/noname/game/index.js index a6856e3ec..5407f0c13 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -5932,17 +5932,7 @@ export class Game extends Uninstantable { if (!event.forced && !event.fakeforce && get.noSelected()) confirm += 'c'; if (event.isMine()) game.Check.confirm(event, confirm); - game.callHook("checkEnd", [event]); - - if (event.isMine() && confirm.includes('o') - && auto && (auto_confirm || skillinfo.direct) && !_status.touchnocheck - && !_status.mousedown && (!_status.mousedragging || !_status.mouseleft)) { - if (ui.confirm) ui.confirm.close(); - if (event.skillDialog === true) event.skillDialog = false; - ui.click.ok(); - _status.mousedragging = null; - if (skillinfo.preservecancel) ui.create.confirm('c'); - } + game.callHook("checkEnd", [event, { ok, auto, auto_confirm }]); // if (ui.confirm && ui.confirm.lastChild.link == 'cancel') { // if (_status.event.type == 'phase' && !_status.event.skill) { diff --git a/noname/library/index.js b/noname/library/index.js index 672760fc5..4f9813f6b 100644 --- a/noname/library/index.js +++ b/noname/library/index.js @@ -332,7 +332,20 @@ export class Library extends Uninstantable { }], //game.check checkBegin: [], - checkEnd: [], + checkEnd: [ + function autoConfirm(event, { ok, auto, auto_confirm }) { + if (!event.isMine()) return; + const skillinfo = get.info(event.skill) || {}; + if (ok && auto && (auto_confirm || skillinfo.direct) && !_status.touchnocheck + && !_status.mousedown && (!_status.mousedragging || !_status.mouseleft)) { + if (ui.confirm) ui.confirm.close(); + if (event.skillDialog === true) event.skillDialog = false; + ui.click.ok(); + _status.mousedragging = null; + if (skillinfo.preservecancel) ui.create.confirm('c'); + } + } + ], checkButton: [], checkCard: [ function updateTempname(card, event) {