refactor: info improve.

This commit is contained in:
Ansolve 2024-01-04 18:12:39 +08:00
parent 19431cf8ee
commit 903ce71ad7
No known key found for this signature in database
GPG Key ID: 2F2873AC9538CC2D
1 changed files with 7 additions and 3 deletions

View File

@ -2,21 +2,25 @@ import { Game as game } from '../game/index.js';
/**
* @param {string} name - 卡牌包名
* @returns {Promise<void>}
*/
export const importCardPack = generateImportFunction('card', (name) => `../../card/${name}.js`)
/**
* @param {string} name - 武将包名
* @returns {Promise<void>}
*/
export const importCharacterPack = generateImportFunction('character', (name) => `../../character/${name}.js`)
/**
* @param {string} name - 扩展名
* @returns {Promise<void>}
*/
export const importExtension = generateImportFunction('extension', (name) => `../../extension/${name}/extension.js`)
/**
* @param {string} name - 模式名
* @param {string} name - 模式名
* @returns {Promise<void>}
*/
export const importMode = generateImportFunction('mode', (name) => `../../mode/${name}.js`)
@ -28,11 +32,11 @@ export const importMode = generateImportFunction('mode', (name) => `../../mode/$
* @returns {(name: string) => Promise<void>}
*/
function generateImportFunction(type, pathParser) {
return async function (name) {
return async (name) => {
try {
const modeContent = await import(pathParser(name));
if (!modeContent.type) return;
if (modeContent.type !== type) throw new Error(`Loaded Content doesnt conform to "${type}"`);
if (modeContent.type !== type) throw new Error(`Loaded Content doesn't conform to "${type}" but "${modeContent.type}".`);
await game.import(type, modeContent.default);
} catch (e) {
console.error(e);