Merge pull request #507 from nonameShijian/PR-Branch

content函数增加debugger功能
This commit is contained in:
Spmario233 2023-10-11 11:08:04 +08:00 committed by GitHub
commit 3732985952
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 73 additions and 9 deletions

View File

@ -11130,10 +11130,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
@ -11157,7 +11165,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){
@ -11167,7 +11175,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));
}
@ -37521,14 +37529,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();
}
@ -39104,9 +39114,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);
@ -39115,9 +39152,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();