From 2f42b9bb1af9aaa9d3a4ea6fd1e2a0464a9d878f Mon Sep 17 00:00:00 2001 From: aixianling Date: Thu, 16 Jan 2025 11:48:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20gm=20=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E5=92=8C=E7=9B=B8=E5=85=B3=E5=A4=84=E7=90=86=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 .gitignore 中添加 gm 目录,避免版本控制 - 新增 gmItems.js 脚本,用于将 JSON 配置文件转换为 PHP 格式 - 脚本读取 configs 目录中的 JSON 文件,转换后写入 gm 目录 --- .gitignore | 1 + gmItems.js | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 gmItems.js diff --git a/.gitignore b/.gitignore index 0655fbe..b533800 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ config.xml /dist.zip dist/ luaConfigs/ +gm/ diff --git a/gmItems.js b/gmItems.js new file mode 100644 index 0000000..da68d09 --- /dev/null +++ b/gmItems.js @@ -0,0 +1,27 @@ +const fs = require('fs') +const path = require('path'); +const folderPath = "./configs" +const props = ["id", "name"] +function jsonToPhp(jsonObj, indent = '', linefeed = '\n') { + return Object.values(jsonObj).map(item => { + return `array(${props.map(e => `'${e}'=>${typeof (v = item[e]) == 'string' ? `'${v}'` : v}`).join(",")})` + }).join(",\n") +} +const start = () => { + const files = fs.readdirSync(folderPath); + + // 过滤出所有的 JSON 文件 + const jsonFiles = files.filter(file => path.extname(file) === '.json').filter(file => ["StdItems"].map(e => `${e}.json`).includes(file)); + fs.access("./gm", fs.constants.F_OK, err => { + if (err) { + fs.mkdirSync("./gm") + } + }) + jsonFiles.forEach(file => { + const json = JSON.parse(fs.readFileSync(path.join(folderPath, file), 'utf8')) + const filename = path.basename(file, path.extname(file)); + const luaConfig = `