修正event.debugger()的判断,lib.init.parsex去除99个step的限制
This commit is contained in:
parent
9201e03e65
commit
1fa14c3c7f
43
game/game.js
43
game/game.js
|
@ -11233,32 +11233,44 @@
|
||||||
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();
|
let 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);
|
||||||
|
//判断代码中是否有debugger
|
||||||
|
let regex=/event\.debugger\(\)/;
|
||||||
|
let hasDebugger=false;
|
||||||
|
let insertDebugger=`yield code=>eval(code);`;
|
||||||
|
let debuggerSkip=0;
|
||||||
|
let debuggerResult;
|
||||||
|
while((debuggerResult=str.slice(debuggerSkip).match(regex))!=null){
|
||||||
|
let debuggerCopy=str;
|
||||||
|
debuggerCopy=debuggerCopy.slice(0,debuggerSkip+debuggerResult.index)+insertDebugger+debuggerCopy.slice(debuggerSkip+debuggerResult.index+debuggerResult[0].length,-1);
|
||||||
|
//测试是否有错误
|
||||||
|
try {
|
||||||
|
new GeneratorFunction(debuggerCopy);
|
||||||
|
str=debuggerCopy+'}';
|
||||||
|
debuggerSkip+=debuggerResult.index+insertDebugger.length;
|
||||||
|
hasDebugger=true;
|
||||||
|
}catch(error){
|
||||||
|
debuggerSkip+=debuggerResult.index+debuggerResult[0].length;
|
||||||
|
}
|
||||||
|
}
|
||||||
//func中要写步骤的话,必须要写step 0
|
//func中要写步骤的话,必须要写step 0
|
||||||
if(str.indexOf('step 0')==-1){
|
if(str.indexOf('step 0')==-1){
|
||||||
str='{if(event.step==1) {event.finish();return;}\n'+str;
|
str='{if(event.step==1) {event.finish();return;}\n'+str;
|
||||||
}else{
|
}else{
|
||||||
var skip=0;
|
let skip=0;
|
||||||
//每层最多找99个step
|
let k=0;
|
||||||
for (var k=0;k<99;k++) {
|
let result;
|
||||||
//正则表达式
|
//去除99个step的限制
|
||||||
var reg=new RegExp(`['"]step ${k}['"]`);
|
while((result=str.slice(skip).match(new RegExp(`['"]step ${k}['"]`)))!=null){
|
||||||
var result=str.slice(skip).match(reg);
|
let insertStr;
|
||||||
if(result==null) break;
|
|
||||||
var insertStr;
|
|
||||||
if(k==0){
|
if(k==0){
|
||||||
insertStr=`switch(step){case 0:`;
|
insertStr=`switch(step){case 0:`;
|
||||||
}else{
|
}else{
|
||||||
insertStr=`break;case ${k}:`;
|
insertStr=`break;case ${k}:`;
|
||||||
}
|
}
|
||||||
var copy=str;
|
let copy=str;
|
||||||
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{
|
||||||
|
@ -11269,6 +11281,7 @@
|
||||||
k--;
|
k--;
|
||||||
skip+=result.index+result[0].length;
|
skip+=result.index+result[0].length;
|
||||||
}
|
}
|
||||||
|
k++;
|
||||||
}
|
}
|
||||||
str=`if(event.step==${k}){event.finish();return;}`+str;
|
str=`if(event.step==${k}){event.finish();return;}`+str;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue