Merge pull request #907 from universe-st/PR-Branch-240203

在扩展关闭时读取info.json获取扩展基本信息
This commit is contained in:
Spmario233 2024-02-04 10:45:45 +08:00 committed by GitHub
commit a5bc83a73a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 8 deletions

View File

@ -35,7 +35,7 @@ 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) && !lib.config.all.stockextension.includes(name)){ if(type == 'extension' && !game.hasExtension(name) && !lib.config.all.stockextension.includes(name)){
await game.import(type,createEmptyExtension(name)); await game.import(type,await createEmptyExtension(name));
return; return;
} }
let path = pathParser(name); let path = pathParser(name);
@ -72,8 +72,21 @@ function generateImportFunction(type, pathParser) {
} }
} }
function createEmptyExtension(name){ async function createEmptyExtension(name){
return {name:name,content:function(config,pack){},precontent:function(){},config:{},help:{},package:{ const extensionInfo = await lib.init.promises.json(`${lib.assetURL}extension/${name}/info.json`)//await import(`../../extension/${name}/info.json`,{assert:{type:'json'}})
.then(info=>{
return info;
},()=>{
return {
name:name,
intro:`扩展<b>《${name}》</b>尚未开启请开启后查看信息。建议扩展添加info.json以在关闭时查看信息`,
author:"未知",
diskURL:"",
forumURL:"",
version:"1.0",
};
});
return {name:extensionInfo.name,content:function(config,pack){},precontent:function(){},config:{},help:{},package:{
character:{ character:{
character:{ character:{
}, },
@ -93,10 +106,10 @@ function createEmptyExtension(name){
translate:{ translate:{
}, },
}, },
intro:`扩展《${name}》尚未开启,请开启后查看信息。`, intro:extensionInfo.intro?extensionInfo.intro.replace("${assetURL}",lib.assetURL):"",
author:"未知", author:extensionInfo.author?extensionInfo.author:"未知",
diskURL:"", diskURL:extensionInfo.diskURL?extensionInfo.diskURL:"",
forumURL:"", forumURL:extensionInfo.forumURL?extensionInfo.forumURL:"",
version:"1.0", version:extensionInfo.version?extensionInfo.version:"1.0.0",
},files:{"character":[],"card":[],"skill":[],"audio":[]}} },files:{"character":[],"card":[],"skill":[],"audio":[]}}
} }

View File

@ -787,4 +787,14 @@ export class LibInit extends Uninstantable {
} }
return str; return str;
} }
/**
* 在返回当前加载的esm模块相对位置
* @param {*} url 传入import.meta.url
*/
static getCurrentFileLocation(url){
let head = window.location.href.slice(0,window.location.href.lastIndexOf('/')+1);
let ret = url.replace(head,'');
return decodeURIComponent(ret);
}
} }