content函数增加debugger功能
This commit is contained in:
parent
debf1edb99
commit
5a5f196471
66
game/game.js
66
game/game.js
|
@ -11135,10 +11135,18 @@
|
||||||
},
|
},
|
||||||
parsex:function(item){
|
parsex:function(item){
|
||||||
//by 诗笺、Tipx-L
|
//by 诗笺、Tipx-L
|
||||||
|
/**
|
||||||
|
* @param {Function} func
|
||||||
|
*/
|
||||||
function Legacy(func){
|
function Legacy(func){
|
||||||
//Remove all comments
|
//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();
|
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);
|
str=str.slice(str.indexOf('{')+1);
|
||||||
//func中要写步骤的话,必须要写step 0
|
//func中要写步骤的话,必须要写step 0
|
||||||
|
@ -11162,7 +11170,7 @@
|
||||||
copy=copy.slice(0,skip+result.index)+insertStr+copy.slice(skip+result.index+result[0].length);
|
copy=copy.slice(0,skip+result.index)+insertStr+copy.slice(skip+result.index+result[0].length);
|
||||||
//测试是否有错误
|
//测试是否有错误
|
||||||
try{
|
try{
|
||||||
new Function(copy);
|
new (hasDebugger?GeneratorFunction:Function)(copy);
|
||||||
str=copy;
|
str=copy;
|
||||||
skip+=result.index+insertStr.length;
|
skip+=result.index+insertStr.length;
|
||||||
}catch(error){
|
}catch(error){
|
||||||
|
@ -11172,7 +11180,7 @@
|
||||||
}
|
}
|
||||||
str=`if(event.step==${k}){event.finish();return;}`+str;
|
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',
|
'card','cards','skill','forced','num','trigger','result',
|
||||||
'_status','lib','game','ui','get','ai',str));
|
'_status','lib','game','ui','get','ai',str));
|
||||||
}
|
}
|
||||||
|
@ -39051,10 +39059,37 @@
|
||||||
else{
|
else{
|
||||||
if(_status.withError||lib.config.compatiblemode||(_status.connectMode&&!lib.config.debug)){
|
if(_status.withError||lib.config.compatiblemode||(_status.connectMode&&!lib.config.debug)){
|
||||||
try{
|
try{
|
||||||
|
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,
|
event.content(event,step,source,player,target,targets,
|
||||||
card,cards,skill,forced,num,trigger,result,
|
card,cards,skill,forced,num,trigger,result,
|
||||||
_status,lib,game,ui,get,ai);
|
_status,lib,game,ui,get,ai);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch(e){
|
catch(e){
|
||||||
game.print('游戏出错:'+event.name);
|
game.print('游戏出错:'+event.name);
|
||||||
game.print(e.toString());
|
game.print(e.toString());
|
||||||
|
@ -39062,11 +39097,38 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
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,
|
event.content(event,step,source,player,target,targets,
|
||||||
card,cards,skill,forced,num,trigger,result,
|
card,cards,skill,forced,num,trigger,result,
|
||||||
_status,lib,game,ui,get,ai);
|
_status,lib,game,ui,get,ai);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
event.clearStepCache();
|
event.clearStepCache();
|
||||||
event.step++;
|
event.step++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue