feat: 添加 gm 目录和相关处理脚本
- 在 .gitignore 中添加 gm 目录,避免版本控制 - 新增 gmItems.js 脚本,用于将 JSON 配置文件转换为 PHP 格式 - 脚本读取 configs 目录中的 JSON 文件,转换后写入 gm 目录
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ config.xml
|
|||||||
/dist.zip
|
/dist.zip
|
||||||
dist/
|
dist/
|
||||||
luaConfigs/
|
luaConfigs/
|
||||||
|
gm/
|
||||||
|
|||||||
27
gmItems.js
Normal file
27
gmItems.js
Normal file
@@ -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 = `<?php\n $items=array(\n${jsonToPhp(json)}\n);`
|
||||||
|
fs.writeFileSync(`./gm/${filename}.php`, luaConfig);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
start()
|
||||||
Reference in New Issue
Block a user