From 6765ecfc853b6811958746b20b3d8b0051163ad5 Mon Sep 17 00:00:00 2001 From: bietiaop <1527109126@qq.com> Date: Wed, 10 Jul 2024 16:38:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E9=AB=98=E7=89=88=E6=9C=ACnode=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/convert/char.js | 5 ++++- lib/convert/weapon.js | 5 ++++- lib/path.js | 2 ++ utils/file.js | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/convert/char.js b/lib/convert/char.js index 2045f59..1eb38a0 100644 --- a/lib/convert/char.js +++ b/lib/convert/char.js @@ -1,5 +1,8 @@ import settings from '../settings.js'; -import PartnerId2SpriteId from '../../resources/map/PartnerId2Data.json' assert { type: 'json' }; +// import PartnerId2SpriteId from '../../resources/map/PartnerId2Data.json' assert { type: 'json' }; +import { getMapData } from '../../utils/file.js'; + +const PartnerId2SpriteId = getMapData('PartnerId2Data'); /** * diff --git a/lib/convert/weapon.js b/lib/convert/weapon.js index 1fec456..c2daa7f 100644 --- a/lib/convert/weapon.js +++ b/lib/convert/weapon.js @@ -1,4 +1,7 @@ -import WeaponId2Sprite from '../../resources/map/WeaponId2Sprite.json' assert { type: 'json' }; +// import WeaponId2Sprite from '../../resources/map/WeaponId2Sprite.json' assert { type: 'json' }; +import { getMapData } from '../../utils/file.js'; + +const WeaponId2Sprite = getMapData('WeaponId2Sprite'); /** * @param {string} id diff --git a/lib/path.js b/lib/path.js index f776a78..1aee8aa 100644 --- a/lib/path.js +++ b/lib/path.js @@ -21,6 +21,8 @@ export const resourcesPath = path.join(pluginPath, 'resources'); export const imageResourcesPath = path.join(resourcesPath, 'images'); +export const mapResourcesPath = path.join(resourcesPath, 'maps'); + // config 路径 export const configPath = path.join(pluginPath, 'config'); diff --git a/utils/file.js b/utils/file.js index 6ad4a36..dbfd65d 100644 --- a/utils/file.js +++ b/utils/file.js @@ -1,6 +1,22 @@ import fs from 'fs'; +import { mapResourcesPath } from '../lib/path.js'; export function checkFolderExistAndCreate(folderPath) { if (!fs.existsSync(folderPath)) { fs.mkdirSync(folderPath, { recursive: true }); } } + +/** + * + * @param {string} fileName 名称(不包含后缀) + * @returns {object | null} + */ +export function getMapData(fileName) { + const mapDataPath = `${mapResourcesPath}/${fileName}.json`; + try { + const mapData = fs.readFileSync(mapDataPath, 'utf-8'); + return JSON.parse(mapData); + } catch (error) { + return null; + } +}