Merge pull request #316 from nofficalfs/PR-Purify-ImportFix

[Purify] `game.import` fused of `lib.gnc`.
This commit is contained in:
Spmario233 2023-09-11 19:04:19 +08:00 committed by GitHub
commit 4dcec776da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 21 deletions

View File

@ -8337,15 +8337,23 @@
if(!arrayLengths.length) return previousValue+1; if(!arrayLengths.length) return previousValue+1;
return previousValue+Math.min(...arrayLengths); return previousValue+Math.min(...arrayLengths);
},0); },0);
const packLoaded=()=>{ const packLoaded=gnc.async(function*(){
toLoad--; toLoad--;
if(toLoad) return; if(toLoad) return;
if(_status.importing){
let promises=lib.creation.a;
for(const type in _status.importing){
promises.addArray(_status.importing[type])
}
yield Promise.allSettled(promises);
delete _status.importing;
}
if(_status.windowLoaded){ if(_status.windowLoaded){
delete _status.windowLoaded; delete _status.windowLoaded;
lib.init.onload(); lib.init.onload();
} }
else _status.packLoaded=true; else _status.packLoaded=true;
}; });
if(localStorage.getItem(`${lib.configprefix}playback`)){ if(localStorage.getItem(`${lib.configprefix}playback`)){
toLoad++; toLoad++;
lib.init.js(`${lib.assetURL}mode`,lib.config.mode,packLoaded,packLoaded); lib.init.js(`${lib.assetURL}mode`,lib.config.mode,packLoaded,packLoaded);
@ -9733,7 +9741,7 @@
try{ try{
_status.extension=lib.extensions[i][0]; _status.extension=lib.extensions[i][0];
_status.evaluatingExtension=lib.extensions[i][3]; _status.evaluatingExtension=lib.extensions[i][3];
if (typeof lib.extensions[i][1]=="function") yield lib.extensions[i][1](lib.extensions[i][2],lib.extensions[i][4]); if (typeof lib.extensions[i][1]=="function") yield gnc.await(lib.extensions[i][1](lib.extensions[i][2],lib.extensions[i][4]));
if(lib.extensions[i][4]){ if(lib.extensions[i][4]){
if(lib.extensions[i][4].character){ if(lib.extensions[i][4].character){
for(var j in lib.extensions[i][4].character.character){ for(var j in lib.extensions[i][4].character.character){
@ -33488,30 +33496,30 @@
} }
}, },
import:function(type,content){ import:function(type,content){
const asyncFn=gnc.async(function*(){ if(type=='extension'){
if(type=='extension'){ if(typeof _status.extensionLoading=="undefined")_status.extensionLoading=[];
yield game.loadExtension(content); const promise=game.loadExtension(content);
} _status.extensionLoading.add(promise);
else{ return promise;
if(!lib.imported[type]){ }
lib.imported[type]={}; else{
} if(!lib.imported[type])lib.imported[type]={};
var content2=yield content(lib,game,ui,get,ai,_status); if(typeof _status.importing=="undefined")_status.importing={};
if(!_status.importing[type])_status.importing[type]=[];
const promise=gnc.await(content(lib,game,ui,get,ai,_status)).then(content2=>{
if(content2.name){ if(content2.name){
lib.imported[type][content2.name]=content2; lib.imported[type][content2.name]=content2;
delete content2.name; delete content2.name;
} }
} });
}); _status.importing[type].add(promise);
if(typeof _status.extensionLoading=="undefined")_status.extensionLoading=[]; return promise;
const promise=asyncFn(); }
_status.extensionLoading.add(promise);
return promise;
}, },
loadExtension:gnc.async(function*(obj){ loadExtension:gnc.async(function*(obj){
var noeval=false; var noeval=false;
if(typeof obj=='function'){ if(typeof obj=='function'){
obj=yield obj(lib,game,ui,get,ai,_status); obj=yield gnc.await(obj(lib,game,ui,get,ai,_status));
noeval=true; noeval=true;
} }
lib.extensionMenu['extension_'+obj.name]={ lib.extensionMenu['extension_'+obj.name]={
@ -33629,7 +33637,7 @@
} }
if(obj.precontent){ if(obj.precontent){
_status.extension=obj.name; _status.extension=obj.name;
yield obj.precontent(cfg); yield gnc.await(obj.precontent(cfg));
delete _status.extension; delete _status.extension;
} }
if(obj.content){ if(obj.content){

View File

@ -134,7 +134,7 @@ game.import('mode',function(lib,game,ui,get,ai,_status){
step4(); step4();
} }
}; };
var step4=lib.genAsync(function*(){ var step4=lib.gnc.async(function*(){
clear(); clear();
ui.window.classList.add('noclick_important'); ui.window.classList.add('noclick_important');
ui.click.configMenu(); ui.click.configMenu();