From 9ac2a0b1465c00649c30244527c7e2edab10426a Mon Sep 17 00:00:00 2001 From: Rintim Date: Mon, 18 Sep 2023 17:49:05 +0800 Subject: [PATCH 1/5] =?UTF-8?q?[2023/09/18:=20=E2=91=A2]=20Add=20prework.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New `game.import` uses `document.currentScript` to determine the code caller. If the script is not `game.js`, we put the result to `_status` for `game.js` to wait, otherwise return the promise directly. --- game/game.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/game/game.js b/game/game.js index 47b1ee89f..439b9c543 100644 --- a/game/game.js +++ b/game/game.js @@ -29,6 +29,7 @@ } } } + const GameJS=document.currentScript; const GeneratorFunction=(function*(){}).constructor; // gnc: GeNCoroutine const gnc={ @@ -166,6 +167,8 @@ hook:{globaltrigger:{},globalskill:{}}, //函数钩子 hooks:{ + // getCurrentScript用到的接口 + _getCurrentScript:()=>null, // 本体势力的颜色 addGroup:[(id,_short,_name,config)=>{ if("color" in config&&config.color!=null){ @@ -32578,8 +32581,8 @@ '妹子,交个朋友吧', ], other:{ - bool:(item)=>Boolean(item), - ignore:()=>{} + getCurrentScript:()=>document.currentScript||lib.hooks._getCurrentScript(), + ignore:()=>void 0 } }; const game={ From 0a2ab57ab8cb712cb90a4bee6a0af14d0af1e376 Mon Sep 17 00:00:00 2001 From: Rintim Date: Mon, 18 Sep 2023 18:49:56 +0800 Subject: [PATCH 2/5] =?UTF-8?q?[2023/09/18:=20=E2=91=A2]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/game/game.js b/game/game.js index 439b9c543..669255709 100644 --- a/game/game.js +++ b/game/game.js @@ -168,7 +168,7 @@ //函数钩子 hooks:{ // getCurrentScript用到的接口 - _getCurrentScript:()=>null, + _getCurrentScript:(_url)=>null, // 本体势力的颜色 addGroup:[(id,_short,_name,config)=>{ if("color" in config&&config.color!=null){ @@ -7278,31 +7278,31 @@ } }, comparator:{ - e:function(){ + equals:function(){ if(arguments.length==0) return false; if(arguments.length==1) return true; for(let i=1;i[], set:()=>null }); - Object.defineProperty(lib.creation,"o",{ + Object.defineProperty(lib.creation,"object",{ enumerable:true, get:()=>({}), set:()=>null }); - Object.defineProperty(lib.creation,"no",{ + Object.defineProperty(lib.creation,"nullObject",{ enumerable:true, get:()=>Object.create(null), set:()=>null }); - Object.defineProperty(lib.creation,"s",{ + Object.defineProperty(lib.creation,"string",{ enumerable:true, get:()=>"", set:()=>null @@ -32581,7 +32581,7 @@ '妹子,交个朋友吧', ], other:{ - getCurrentScript:()=>document.currentScript||lib.hooks._getCurrentScript(), + getCurrentScript:(url)=>document.currentScript||lib.hooks._getCurrentScript(url), ignore:()=>void 0 } }; @@ -32622,15 +32622,15 @@ //基于钩子的添加势力方法 addGroup:(id,short,name,config)=>{ if(!id) throw new TypeError(); - if(lib.comparator.te(short,"object")){ + if(lib.comparator.typeEquals(short,"object")){ config=short; short=null; } - if(lib.comparator.te(name,"object")){ + if(lib.comparator.typeEquals(name,"object")){ config=name; name=null; } - if(!lib.comparator.te(short,"string")&&short){ + if(!lib.comparator.typeEquals(short,"string")&&short){ name=short; } lib.group.add(id); @@ -33799,25 +33799,26 @@ } } }, - import:function(type,content){ + import:function(type,content,url){ + const currentScript = lib.other.getCurrentScript(url); if(type=='extension'){ - if(typeof _status.extensionLoading=="undefined")_status.extensionLoading=[]; const promise=game.loadExtension(content); + if(lib.comparator.equalAny(currentScript, null, GameJS)) return promise; + if(typeof _status.extensionLoading=="undefined")_status.extensionLoading=[]; _status.extensionLoading.add(promise); - return promise; } else{ if(!lib.imported[type])lib.imported[type]={}; - if(typeof _status.importing=="undefined")_status.importing={}; - if(!_status.importing[type])_status.importing[type]=[]; const promise=Promise.resolve((gnc.is.generator(content)?gnc.of(content):content)(lib,game,ui,get,ai,_status)).then(content2=>{ if(content2.name){ lib.imported[type][content2.name]=content2; delete content2.name; } }); + if(lib.comparator.equalAny(currentScript, null, GameJS)) return promise; + if(typeof _status.importing=="undefined")_status.importing={}; + if(!_status.importing[type])_status.importing[type]=[]; _status.importing[type].add(promise); - return promise; } }, loadExtension:gnc.of(function*(obj){ @@ -34107,9 +34108,7 @@ var str=zip.file('extension.js').asText(); if(str===""||undefined) throw('你导入的不是扩展!请选择正确的文件'); _status.importingExtension=true; - eval(str); - yield Promise.allSettled(_status.extensionLoading); - delete _status.extensionLoading; + yield eval(str); _status.importingExtension=false; if(!game.importedPack) throw('err'); var extname=game.importedPack.name; From 6b55691d394f23478e9f0245f4250de920442d6e Mon Sep 17 00:00:00 2001 From: Rintim Date: Mon, 18 Sep 2023 19:11:02 +0800 Subject: [PATCH 3/5] =?UTF-8?q?[2023/09/18:=20=E2=91=A2]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/game/game.js b/game/game.js index 669255709..2b51c38a8 100644 --- a/game/game.js +++ b/game/game.js @@ -9727,7 +9727,7 @@ _status.extension=lib.extensions[i][0]; _status.evaluatingExtension=lib.extensions[i][3]; if (typeof lib.extensions[i][1]=="function") - yield (gnc.is.coroutine(lib.extensions[i][1])?gnc.of(lib.extensions[i][1]):lib.extensions[i][1])(lib.extensions[i][2],lib.extensions[i][4]); + yield (gnc.is.coroutine(lib.extensions[i][1])?gnc.of(lib.extensions[i][1]):lib.extensions[i][1]).call(lib.extensions[i],lib.extensions[i][2],lib.extensions[i][4]); if(lib.extensions[i][4]){ if(lib.extensions[i][4].character){ for(var j in lib.extensions[i][4].character.character){ @@ -10019,8 +10019,7 @@ js:(path,file,onload,onerror)=>{ if(path[path.length-1]=='/') path=path.slice(0,path.length-1); if(path==`${lib.assetURL}mode`&&lib.config.all.stockmode.indexOf(file)==-1){ - lib.init[`setMode_${file}`](); - onload(); + lib.genAwait(lib.init[`setMode_${file}`]()).then(onload); return; } if(Array.isArray(file)){ @@ -33942,7 +33941,7 @@ } if(obj.precontent){ _status.extension=obj.name; - yield (gnc.is.generatorFunc(obj.precontent)?gnc.of(obj.precontent):obj.precontent)(cfg); + yield (gnc.is.generatorFunc(obj.precontent)?gnc.of(obj.precontent):obj.precontent).call(obj,cfg); delete _status.extension; } if(obj.content){ @@ -36591,12 +36590,12 @@ splash:imgsrc, fromextension:true } - lib.init['setMode_'+name]=function(){ - game.import('mode',function(lib,game,ui,get,ai,_status){ + lib.init['setMode_'+name]=gnc.of(function*(){ + yield game.import('mode',function(lib,game,ui,get,ai,_status){ info.name=name; return info; }); - } + }); if(!lib.config.extensionInfo[extname]){ lib.config.extensionInfo[extname]={}; } @@ -38299,7 +38298,8 @@ }, loadModeAsync:function(name,callback){ window.game=game; - var script=lib.init.js(lib.assetURL+'mode',name,function(){ + var script=lib.init.js(lib.assetURL+'mode',name,gnc.of(function*(){ + yield Promise.allSettled(_status.importing.mode); if(!lib.config.dev) delete window.game; script.remove(); var content=lib.imported.mode[name]; @@ -38308,7 +38308,7 @@ delete lib.imported.mode; } callback(content); - }); + })); }, switchMode:function(name,configx){ if(!lib.layoutfixed.contains(name)){ @@ -38322,7 +38322,8 @@ } } window.game=game; - var script=lib.init.js(lib.assetURL+'mode',name,function(){ + var script=lib.init.js(lib.assetURL+'mode',name,gnc.of(function*(){ + yield Promise.allSettled(_status.importing.mode); if(!lib.config.dev) delete window.game; script.remove(); var mode=lib.imported.mode; @@ -38497,7 +38498,7 @@ game.loop(); }); } - }); + })); }, loadMode:function(mode){ var next=game.createEvent('loadMode',false); From 0be236560a68c66dfdaf441394a64a391ef420dc Mon Sep 17 00:00:00 2001 From: Rintim Date: Mon, 18 Sep 2023 19:11:25 +0800 Subject: [PATCH 4/5] =?UTF-8?q?[2023/09/18:=20=E2=91=A2]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game.js b/game/game.js index 2b51c38a8..1b46390f0 100644 --- a/game/game.js +++ b/game/game.js @@ -1,5 +1,5 @@ "use strict"; -(()=>{ +{ if(!localStorage.getItem('gplv3_noname_alerted')){ if(confirm('①无名杀是一款基于GPLv3协议的开源软件!\n你可以在遵守GPLv3协议的基础上任意使用,修改并转发《无名杀》,以及所有基于《无名杀》开发的拓展。\n点击“确定”即代表您认可并接受GPLv3协议↓️\nhttps://www.gnu.org/licenses/gpl-3.0.html\n②无名杀官方发布地址仅有GitHub仓库!\n其他所有的所谓“无名杀”社群(包括但不限于绝大多数“官方”QQ群、QQ频道等)均为玩家自发组织,与无名杀官方无关!')){ localStorage.setItem('gplv3_noname_alerted',true); @@ -59059,4 +59059,4 @@ get:get }; lib.init.init(); -})(); +} From 01044af9313c226e8c7ef66f1e7b4a78b1fc345d Mon Sep 17 00:00:00 2001 From: Rintim Date: Mon, 18 Sep 2023 19:20:25 +0800 Subject: [PATCH 5/5] =?UTF-8?q?[2023/09/18:=20=E2=91=A3]=20Revert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/game/game.js b/game/game.js index 1b46390f0..c41382d8a 100644 --- a/game/game.js +++ b/game/game.js @@ -29,7 +29,6 @@ } } } - const GameJS=document.currentScript; const GeneratorFunction=(function*(){}).constructor; // gnc: GeNCoroutine const gnc={ @@ -167,8 +166,6 @@ hook:{globaltrigger:{},globalskill:{}}, //函数钩子 hooks:{ - // getCurrentScript用到的接口 - _getCurrentScript:(_url)=>null, // 本体势力的颜色 addGroup:[(id,_short,_name,config)=>{ if("color" in config&&config.color!=null){ @@ -32580,7 +32577,6 @@ '妹子,交个朋友吧', ], other:{ - getCurrentScript:(url)=>document.currentScript||lib.hooks._getCurrentScript(url), ignore:()=>void 0 } }; @@ -33799,12 +33795,11 @@ } }, import:function(type,content,url){ - const currentScript = lib.other.getCurrentScript(url); if(type=='extension'){ const promise=game.loadExtension(content); - if(lib.comparator.equalAny(currentScript, null, GameJS)) return promise; if(typeof _status.extensionLoading=="undefined")_status.extensionLoading=[]; _status.extensionLoading.add(promise); + return promise; } else{ if(!lib.imported[type])lib.imported[type]={}; @@ -33814,10 +33809,10 @@ delete content2.name; } }); - if(lib.comparator.equalAny(currentScript, null, GameJS)) return promise; if(typeof _status.importing=="undefined")_status.importing={}; if(!_status.importing[type])_status.importing[type]=[]; _status.importing[type].add(promise); + return promise; } }, loadExtension:gnc.of(function*(obj){ @@ -34107,7 +34102,9 @@ var str=zip.file('extension.js').asText(); if(str===""||undefined) throw('你导入的不是扩展!请选择正确的文件'); _status.importingExtension=true; - yield eval(str); + eval(str); + yield Promise.allSettled(_status.extensionLoading); + delete _status.extensionLoading; _status.importingExtension=false; if(!game.importedPack) throw('err'); var extname=game.importedPack.name;