对扩展自行创建武将包使用了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) { static import(type, content, url) {
if (type == 'extension') { if (type == 'extension') {
const promise = game.loadExtension(content).then((name) => { const promise = game.loadExtension(content).then((name) => {
if (typeof _status.extensionLoaded == "undefined") if (typeof _status.extensionLoaded == "undefined") _status.extensionLoaded = [];
_status.extensionLoaded = [];
_status.extensionLoaded.add(name); _status.extensionLoaded.add(name);
return 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 * @param {(name: string) => string} pathParser
* @returns {(name: string) => Promise<void>} * @returns {(name: string) => Promise<void>}
*/ */
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,await createEmptyExtension(name)); // @ts-ignore
await game.import(type, await createEmptyExtension(name));
return; return;
} }
let path = pathParser(name); let path = pathParser(name);
@ -74,52 +75,69 @@ function generateImportFunction(type, pathParser) {
document.head.appendChild(script); document.head.appendChild(script);
}); });
script.remove(); 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); const modeContent = await import(path);
if (!modeContent.type) return; if (!modeContent.type) return;
if (modeContent.type !== type) throw new Error(`Loaded Content doesn't conform to "${type}" but "${modeContent.type}".`); 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); 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'}}) const extensionInfo = await lib.init.promises.json(`${lib.assetURL}extension/${name}/info.json`)//await import(`../../extension/${name}/info.json`,{assert:{type:'json'}})
.then(info=>{ .then(info => info, () => {
return info;
},()=>{
return { return {
name:name, name: name,
intro:`扩展<b>《${name}》</b>尚未开启请开启后查看信息。建议扩展添加info.json以在关闭时查看信息`, intro: `扩展<b>《${name}》</b>尚未开启请开启后查看信息。建议扩展添加info.json以在关闭时查看信息`,
author:"未知", author: "未知",
diskURL:"", diskURL: "",
forumURL:"", forumURL: "",
version:"1.0", version: "1.0",
}; };
}); });
return {name:extensionInfo.name,content:function(config,pack){},precontent:function(){},config:{},help:{},package:{ return {
character:{ name: extensionInfo.name,
character:{ 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):"", intro: extensionInfo.intro ? extensionInfo.intro.replace("${assetURL}", lib.assetURL) : "",
author:extensionInfo.author?extensionInfo.author:"未知", author: extensionInfo.author ? extensionInfo.author : "未知",
diskURL:extensionInfo.diskURL?extensionInfo.diskURL:"", diskURL: extensionInfo.diskURL ? extensionInfo.diskURL : "",
forumURL:extensionInfo.forumURL?extensionInfo.forumURL:"", forumURL: extensionInfo.forumURL ? extensionInfo.forumURL : "",
version:extensionInfo.version?extensionInfo.version:"1.0.0", version: extensionInfo.version ? extensionInfo.version : "1.0.0",
},files:{"character":[],"card":[],"skill":[],"audio":[]}} },
files: {
"character": [],
"card": [],
"skill": [],
"audio": []
}
}
} }

View File

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