From fc216fc8526b896a37066a18f514aa24b5d7f348 Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Mon, 9 Oct 2023 08:07:02 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9Array.prototype.addArray?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/game/game.js b/game/game.js index d9063bf2f..6bfef6ec6 100644 --- a/game/game.js +++ b/game/game.js @@ -8486,9 +8486,23 @@ configurable:true, enumerable:false, writable:true, + //与原来参数的对比: + //数据多,比原来的函数快 + //数据少,比原来的函数稍慢 value:function(){ - for(const arr of arguments){ - for(const item of arr) this.add(item); + if(arguments.length>0){ + //参数去重,防止出现addArray(arr ,arr ,arr)的问题 + let args=[...new Set(arguments)]; + //展开参数数组,并再次去除所有重复元素(没测试过concat的性能) + let all=Array.from( + new Set( + args.reduce((previous,current)=>previous.concat(current)) + ) + ) + //与this去重 + .filter(v=>!this.includes(v)); + //添加元素 + this.push(...all); } return this; } From 6659d861d4e7458eb4d9e4492e7a3e71ba9db1c2 Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Mon, 9 Oct 2023 09:27:02 +0800 Subject: [PATCH 2/5] =?UTF-8?q?addArray=E5=8E=BB=E9=87=8D=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/game/game.js b/game/game.js index 6bfef6ec6..ba6f9e00d 100644 --- a/game/game.js +++ b/game/game.js @@ -8493,14 +8493,16 @@ if(arguments.length>0){ //参数去重,防止出现addArray(arr ,arr ,arr)的问题 let args=[...new Set(arguments)]; - //展开参数数组,并再次去除所有重复元素(没测试过concat的性能) + //this -> Set + let unique=new Set(this); + //展开参数数组,并再次去除所有重复元素(concat(arr)和push(...arr)好像差不多) let all=Array.from( new Set( args.reduce((previous,current)=>previous.concat(current)) ) ) //与this去重 - .filter(v=>!this.includes(v)); + .filter(v=>!unique.has(v)); //添加元素 this.push(...all); } From 5a5f196471c080520e329a18f7cf4d0ae2a8dc4d Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Wed, 11 Oct 2023 09:31:13 +0800 Subject: [PATCH 3/5] =?UTF-8?q?content=E5=87=BD=E6=95=B0=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?debugger=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 78 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/game/game.js b/game/game.js index 4efa13d6e..5549060b9 100644 --- a/game/game.js +++ b/game/game.js @@ -11135,10 +11135,18 @@ }, parsex:function(item){ //by 诗笺、Tipx-L + /** + * @param {Function} func + */ function Legacy(func){ //Remove all comments //移除所有注释 var str=func.toString().replace(/((?:(?:^[ \t]*)?(?:\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\/(?:[ \t]*\r?\n(?=[ \t]*(?:\r?\n|\/\*|\/\/)))?|\/\/(?:[^\\]|\\(?:\r?\n)?)*?(?:\r?\n(?=[ \t]*(?:\r?\n|\/\*|\/\/))|(?=\r?\n))))+)|("(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|(?:\r?\n|[\s\S])[^\/"'\\\s]*)/mg,'$2').trim(); + //判断代码中是否有debugger + var regex=/event\.debugger\(\)/g; + var hasDebugger=regex.test(str); + var insertDebugger=`yield code=>eval(code);`; + str=str.replaceAll(regex,insertDebugger); //获取第一个 { 后的所有字符 str=str.slice(str.indexOf('{')+1); //func中要写步骤的话,必须要写step 0 @@ -11162,7 +11170,7 @@ copy=copy.slice(0,skip+result.index)+insertStr+copy.slice(skip+result.index+result[0].length); //测试是否有错误 try{ - new Function(copy); + new (hasDebugger?GeneratorFunction:Function)(copy); str=copy; skip+=result.index+insertStr.length; }catch(error){ @@ -11172,7 +11180,7 @@ } str=`if(event.step==${k}){event.finish();return;}`+str; } - return (new Function('event','step','source','player','target','targets', + return (new (hasDebugger?GeneratorFunction:Function)('event','step','source','player','target','targets', 'card','cards','skill','forced','num','trigger','result', '_status','lib','game','ui','get','ai',str)); } @@ -39051,9 +39059,36 @@ else{ if(_status.withError||lib.config.compatiblemode||(_status.connectMode&&!lib.config.debug)){ try{ - event.content(event,step,source,player,target,targets, - card,cards,skill,forced,num,trigger,result, - _status,lib,game,ui,get,ai); + if(event.content instanceof GeneratorFunction){ + if(!event.debugging){ + if(event.generatorContent) event.generatorContent.return(); + event.generatorContent=event.content(event,step,source,player,target,targets, + card,cards,skill,forced,num,trigger,result, + _status,lib,game,ui,get,ai); + }else{ + delete event.debugging; + } + var next=event.generatorContent.next(); + if(typeof next.value=='function'&&next.value.toString()=='code=>eval(code)'){ + //TODO:触发debugger + var inputCallback=inputResult=>{ + if(inputResult===false){ + event.debugging=true; + game.resume2(); + }else{ + alert(get.stringify(next.value(inputResult))); + game.prompt('','debugger调试',inputCallback); + } + } + game.prompt('','debugger调试',inputCallback); + return game.pause2(); + } + if(event.finished) event.generatorContent.return(); + }else{ + event.content(event,step,source,player,target,targets, + card,cards,skill,forced,num,trigger,result, + _status,lib,game,ui,get,ai); + } } catch(e){ game.print('游戏出错:'+event.name); @@ -39062,9 +39097,36 @@ } } else{ - event.content(event,step,source,player,target,targets, - card,cards,skill,forced,num,trigger,result, - _status,lib,game,ui,get,ai); + if(event.content instanceof GeneratorFunction){ + if(!event.debugging){ + if(event.generatorContent) event.generatorContent.return(); + event.generatorContent=event.content(event,step,source,player,target,targets, + card,cards,skill,forced,num,trigger,result, + _status,lib,game,ui,get,ai); + }else{ + delete event.debugging; + } + var next=event.generatorContent.next(); + if(typeof next.value=='function'&&next.value.toString()=='code=>eval(code)'){ + //TODO:触发debugger + var inputCallback=inputResult=>{ + if(inputResult===false){ + event.debugging=true; + game.resume2(); + }else{ + alert(get.stringify(next.value(inputResult))); + game.prompt('','debugger调试',inputCallback); + } + } + game.prompt('','debugger调试',inputCallback); + return game.pause2(); + } + if(event.finished) event.generatorContent.return(); + }else{ + event.content(event,step,source,player,target,targets, + card,cards,skill,forced,num,trigger,result, + _status,lib,game,ui,get,ai); + } } } event.clearStepCache(); From 9a7ac8132523290cd689dfebfcd0b58b68b6c883 Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Wed, 11 Oct 2023 09:41:04 +0800 Subject: [PATCH 4/5] =?UTF-8?q?game.prompt=E8=BE=93=E5=85=A5=E6=A1=86?= =?UTF-8?q?=E5=81=9C=E6=AD=A2=E5=86=92=E6=B3=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/game/game.js b/game/game.js index 5549060b9..e8f4dc478 100644 --- a/game/game.js +++ b/game/game.js @@ -37476,14 +37476,16 @@ else if(e.keyCode==27){ clickCancel(); } + e.stopPropagation(); } - input.onkeyup=function(){ + input.onkeyup=function(e){ if(input.value){ confirmNode.classList.remove('disabled'); } else{ confirmNode.classList.remove('disabled'); } + e.stopPropagation(); } input.focus(); } From 493266d0c389b377d52aa5606bb1cbd1f633e2e5 Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Wed, 11 Oct 2023 09:55:57 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=9B=9E=E6=BB=9Aaddarray?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/game/game.js b/game/game.js index 29edb2a08..60fc30ae1 100644 --- a/game/game.js +++ b/game/game.js @@ -8497,25 +8497,9 @@ configurable:true, enumerable:false, writable:true, - //与原来参数的对比: - //数据多,比原来的函数快 - //数据少,比原来的函数稍慢 value:function(){ - if(arguments.length>0){ - //参数去重,防止出现addArray(arr ,arr ,arr)的问题 - let args=[...new Set(arguments)]; - //this -> Set - let unique=new Set(this); - //展开参数数组,并再次去除所有重复元素(concat(arr)和push(...arr)好像差不多) - let all=Array.from( - new Set( - args.reduce((previous,current)=>previous.concat(current)) - ) - ) - //与this去重 - .filter(v=>!unique.has(v)); - //添加元素 - this.push(...all); + for(const arr of arguments){ + for(const item of arr) this.add(item); } return this; }