Merge pull request #840 from universe-st/PR-Branch

未开启扩展不执行代码
This commit is contained in:
Spmario233 2024-01-22 22:33:49 +08:00 committed by GitHub
commit 8ffed050e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 1 deletions

View File

@ -34,6 +34,10 @@ export const importMode = generateImportFunction('mode', (name) => `../../mode/$
*/ */
function generateImportFunction(type, pathParser) { function generateImportFunction(type, pathParser) {
return async (name) => { return async (name) => {
if(type == 'extension' && !game.hasExtension(name)){
await game.import(type,createEmptyExtension(name));
return;
}
const path = pathParser(name); const path = pathParser(name);
// 通过浏览器自带的script标签导入可直接获取报错信息且不会影响JS运行 // 通过浏览器自带的script标签导入可直接获取报错信息且不会影响JS运行
// 此时代码内容也将缓存在浏览器中故再次import后将不会重新执行代码内容测试下来如此 // 此时代码内容也将缓存在浏览器中故再次import后将不会重新执行代码内容测试下来如此
@ -53,3 +57,32 @@ function generateImportFunction(type, pathParser) {
await game.import(type, modeContent.default); await game.import(type, modeContent.default);
} }
} }
function createEmptyExtension(name){
return {name:name,content:function(config,pack){},precontent:function(){},config:{},help:{},package:{
character:{
character:{
},
translate:{
},
},
card:{
card:{
},
translate:{
},
list:[],
},
skill:{
skill:{
},
translate:{
},
},
intro:`扩展《${name}》尚未开启,请开启后查看信息。`,
author:"未知",
diskURL:"",
forumURL:"",
version:"1.0",
},files:{"character":[],"card":[],"skill":[],"audio":[]}}
}

View File

@ -499,7 +499,7 @@ export async function boot() {
} }
// await Promise.allSettled(_status.extensionLoading); // await Promise.allSettled(_status.extensionLoading);
_status.extensionLoaded.filter(Boolean).forEach((name) => { _status.extensionLoaded.filter(name=>game.hasExtension(name)).forEach((name) => {
lib.announce.publish("Noname.Init.Extension.onLoad", name); lib.announce.publish("Noname.Init.Extension.onLoad", name);
lib.announce.publish(`Noname.Init.Extension.${name}.onLoad`, void 0); lib.announce.publish(`Noname.Init.Extension.${name}.onLoad`, void 0);
}); });