Merge pull request #346 from nofficalfs/PR-Experimentalize-Content
[Experimentalize] `parsex`支持更多参数
This commit is contained in:
commit
76e058159f
79
game/game.js
79
game/game.js
|
@ -10235,8 +10235,9 @@
|
||||||
localStorage.removeItem(lib.configprefix+'background');
|
localStorage.removeItem(lib.configprefix+'background');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
parsex:function(item){
|
||||||
//by 诗笺、Tipx-L
|
//by 诗笺、Tipx-L
|
||||||
parsex:function(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();
|
||||||
|
@ -10276,6 +10277,61 @@
|
||||||
return (new Function('event','step','source','player','target','targets',
|
return (new 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));
|
||||||
|
}
|
||||||
|
switch(typeof item){
|
||||||
|
case "object":
|
||||||
|
if(Array.isArray(item)){
|
||||||
|
let lastEvent=null;
|
||||||
|
return (event,step,source,player,target,targets,card,cards,skill,forced,num,trigger,result,_status,lib,game,ui,get,ai)=>{
|
||||||
|
if(step>=item.length) return event.finish();
|
||||||
|
var current=item[step];
|
||||||
|
lastEvent=current(event,{
|
||||||
|
event:event,
|
||||||
|
step:step,
|
||||||
|
source:source,
|
||||||
|
player:player,
|
||||||
|
target:target,
|
||||||
|
targets:targets,
|
||||||
|
card:card,
|
||||||
|
cards:cards,
|
||||||
|
skill:skill,
|
||||||
|
forced:forced,
|
||||||
|
num:num,
|
||||||
|
trigger:trigger,
|
||||||
|
result:result
|
||||||
|
},(lastEvent&&("result" in lastEvent))?lastEvent.result:null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// TODO: Parse Common Object
|
||||||
|
throw new Error("NYI: Parse Common Object");
|
||||||
|
}
|
||||||
|
case "function":
|
||||||
|
if (gnc.is.generatorFunc(item)) {
|
||||||
|
let gen,lastEvent;
|
||||||
|
return (event,step,source,player,target,targets,card,cards,skill,forced,num,trigger,result,_status,lib,game,ui,get,ai)=>{
|
||||||
|
if(!gen)gen=item(event,{
|
||||||
|
event:event,
|
||||||
|
step:step,
|
||||||
|
source:source,
|
||||||
|
player:player,
|
||||||
|
target:target,
|
||||||
|
targets:targets,
|
||||||
|
card:card,
|
||||||
|
cards:cards,
|
||||||
|
skill:skill,
|
||||||
|
forced:forced,
|
||||||
|
num:num,
|
||||||
|
trigger:trigger,
|
||||||
|
result:result
|
||||||
|
});
|
||||||
|
var res=gen.next((lastEvent&&("result" in lastEvent))?lastEvent.result:null);
|
||||||
|
if(res.done) event.finish();
|
||||||
|
else lastEvent=res.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else return Legacy(item);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
eval:function(func){
|
eval:function(func){
|
||||||
if(typeof func=='function'){
|
if(typeof func=='function'){
|
||||||
|
@ -28603,16 +28659,19 @@
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
setContent:function(name){
|
setContent:function(item){
|
||||||
if(typeof name=='function'){
|
switch(typeof item){
|
||||||
this.content=lib.init.parsex(name);
|
case "object":
|
||||||
|
case "function":
|
||||||
|
this.content=lib.init.parsex(item);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if(!lib.element.content[item]._parsed){
|
||||||
|
lib.element.content[item]=lib.init.parsex(lib.element.content[item]);
|
||||||
|
lib.element.content[item]._parsed=true;
|
||||||
}
|
}
|
||||||
else{
|
this.content=lib.element.content[item];
|
||||||
if(!lib.element.content[name]._parsed){
|
break;
|
||||||
lib.element.content[name]=lib.init.parsex(lib.element.content[name]);
|
|
||||||
lib.element.content[name]._parsed=true;
|
|
||||||
}
|
|
||||||
this.content=lib.element.content[name];
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue