对扩展自行创建武将包使用了lib.config.all.characters.push进行提示

This commit is contained in:
nonameShijian 2024-02-13 15:27:10 +08:00
parent 31402ab1de
commit 6353f42dd4
3 changed files with 60 additions and 50 deletions

View File

@ -1753,8 +1753,7 @@ export class Game extends Uninstantable {
static import(type, content, url) {
if (type == 'extension') {
const promise = game.loadExtension(content).then((name) => {
if (typeof _status.extensionLoaded == "undefined")
_status.extensionLoaded = [];
if (typeof _status.extensionLoaded == "undefined") _status.extensionLoaded = [];
_status.extensionLoaded.add(name);
return name;
});

View File

@ -28,14 +28,15 @@ export const importMode = generateImportFunction('mode', (name) => `../../mode/$
/**
* 生成导入
*
* @param {string} type
* @param { 'card' | 'character' | 'extension' | 'mode' } type
* @param {(name: string) => string} pathParser
* @returns {(name: string) => Promise<void>}
*/
function generateImportFunction(type, pathParser) {
return async (name) => {
if(type == 'extension' && !game.hasExtension(name) && !lib.config.all.stockextension.includes(name)){
await game.import(type,await createEmptyExtension(name));
if (type == 'extension' && !game.hasExtension(name) && !lib.config.all.stockextension.includes(name)) {
// @ts-ignore
await game.import(type, await createEmptyExtension(name));
return;
}
let path = pathParser(name);
@ -74,52 +75,69 @@ function generateImportFunction(type, pathParser) {
document.head.appendChild(script);
});
script.remove();
if (status === 'error') return;
if (status === 'error') {
if (type === 'character') {
console.error('如果您在扩展中使用了game.import创建武将包请将以下代码删除: lib.config.all.characters.push(\'武将包名\');');
}
return;
}
const modeContent = await import(path);
if (!modeContent.type) return;
if (modeContent.type !== type) throw new Error(`Loaded Content doesn't conform to "${type}" but "${modeContent.type}".`);
// @ts-ignore
await game.import(type, modeContent.default);
}
}
async function createEmptyExtension(name){
async function createEmptyExtension(name) {
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;
},()=>{
.then(info => info, () => {
return {
name:name,
intro:`扩展<b>《${name}》</b>尚未开启请开启后查看信息。建议扩展添加info.json以在关闭时查看信息`,
author:"未知",
diskURL:"",
forumURL:"",
version:"1.0",
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:{
return {
name: extensionInfo.name,
content: function (config, pack) { },
precontent: function () { },
config: {},
help: {},
package: {
character: {
character: {
},
translate:{
translate: {
},
},
card:{
card:{
card: {
card: {
},
translate:{
translate: {
},
list:[],
list: [],
},
skill:{
skill:{
skill: {
skill: {
},
translate:{
translate: {
},
},
intro:extensionInfo.intro?extensionInfo.intro.replace("${assetURL}",lib.assetURL):"",
author:extensionInfo.author?extensionInfo.author:"未知",
diskURL:extensionInfo.diskURL?extensionInfo.diskURL:"",
forumURL:extensionInfo.forumURL?extensionInfo.forumURL:"",
version:extensionInfo.version?extensionInfo.version:"1.0.0",
},files:{"character":[],"card":[],"skill":[],"audio":[]}}
intro: extensionInfo.intro ? extensionInfo.intro.replace("${assetURL}", lib.assetURL) : "",
author: extensionInfo.author ? extensionInfo.author : "未知",
diskURL: extensionInfo.diskURL ? extensionInfo.diskURL : "",
forumURL: extensionInfo.forumURL ? extensionInfo.forumURL : "",
version: extensionInfo.version ? extensionInfo.version : "1.0.0",
},
files: {
"character": [],
"card": [],
"skill": [],
"audio": []
}
}
}

View File

@ -301,8 +301,7 @@ export async function boot() {
}
}
if (!config.get('gameRecord'))
config.set('gameRecord', {});
if (!config.get('gameRecord')) config.set('gameRecord', {});
for (const name in pack.mode) {
if (config.get('hiddenModePack').indexOf(name) == -1) {
config.get('all').mode.push(name);
@ -435,11 +434,8 @@ export async function boot() {
extensionlist.push(config.get('plays')[name]);
}
}
var alerted = false;
for (var name = 0; name < config.get('extensions').length; name++) {
if (Reflect.get(window, 'bannedExtensions').includes(config.get('extensions')[name])) {
//if(!alerted) alert('读取某些扩展时出现问题。');
alerted = true;
continue;
}
var extcontent = localStorage.getItem(lib.configprefix + 'extension_' + config.get('extensions')[name]);
@ -462,11 +458,8 @@ export async function boot() {
}
else {
if (config.get('mode') != 'connect' || (!localStorage.getItem(lib.configprefix + 'directstart') && show_splash)) {
var alerted = false;
for (var name = 0; name < config.get('extensions').length; name++) {
if (Reflect.get(window, 'bannedExtensions').includes(config.get('extensions')[name])) {
//if(!alerted) alert('读取某些扩展时出现问题。');
alerted = true;
continue;
}
// @ts-ignore