From 6353f42dd4ddd4bece9c9e74afefcfafc2eabf9d Mon Sep 17 00:00:00 2001 From: nonameShijian <2954700422@qq.com> Date: Tue, 13 Feb 2024 15:27:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=89=A9=E5=B1=95=E8=87=AA=E8=A1=8C?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=AD=A6=E5=B0=86=E5=8C=85=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E4=BA=86lib.config.all.characters.push=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/game/index.js | 3 +- noname/init/import.js | 98 +++++++++++++++++++++++++------------------ noname/init/index.js | 9 +--- 3 files changed, 60 insertions(+), 50 deletions(-) diff --git a/noname/game/index.js b/noname/game/index.js index 2a05f9e68..35ec9d233 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -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; }); diff --git a/noname/init/import.js b/noname/init/import.js index 75ee63341..97dafd47f 100644 --- a/noname/init/import.js +++ b/noname/init/import.js @@ -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} */ 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; - },()=>{ - return { - name:name, - intro:`扩展《${name}》尚未开启,请开启后查看信息。(建议扩展添加info.json以在关闭时查看信息)`, - author:"未知", - diskURL:"", - forumURL:"", - version:"1.0", - }; - }); - return {name:extensionInfo.name,content:function(config,pack){},precontent:function(){},config:{},help:{},package:{ - character:{ - character:{ + .then(info => info, () => { + return { + name: name, + intro: `扩展《${name}》尚未开启,请开启后查看信息。(建议扩展添加info.json以在关闭时查看信息)`, + author: "未知", + diskURL: "", + forumURL: "", + version: "1.0", + }; + }); + return { + name: extensionInfo.name, + content: function (config, pack) { }, + precontent: function () { }, + config: {}, + help: {}, + package: { + character: { + character: { + }, + translate: { + }, }, - translate:{ + card: { + card: { + }, + translate: { + }, + list: [], }, + skill: { + skill: { + }, + 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", }, - card:{ - card:{ - }, - translate:{ - }, - list:[], - }, - skill:{ - skill:{ - }, - 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":[]}} + files: { + "character": [], + "card": [], + "skill": [], + "audio": [] + } + } } \ No newline at end of file diff --git a/noname/init/index.js b/noname/init/index.js index 9ce7b1f8b..50dae0218 100644 --- a/noname/init/index.js +++ b/noname/init/index.js @@ -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