fix: 修改文件名大小写
This commit is contained in:
100279
configs/StdItems.json
100279
configs/StdItems.json
File diff suppressed because it is too large
Load Diff
54
json2lua.js
54
json2lua.js
@@ -1,54 +0,0 @@
|
|||||||
const { log } = require('console');
|
|
||||||
const fs = require('fs')
|
|
||||||
const path = require('path');
|
|
||||||
const folderPath = "./configs"
|
|
||||||
const scope = ["StdItems", "ItemMergeConfig", "MergeConfig", "MergeTotal", "RecyclingSettingConfig", "UpstarConfig", "Monster"]
|
|
||||||
function jsonToLua(jsonObj, indent = '', linefeed = '\n') {
|
|
||||||
let luaStr = '';
|
|
||||||
const strKey = key => isNaN(key) ? `${key}` : `[${key}]`;
|
|
||||||
Object.keys(jsonObj).sort().forEach(key => {
|
|
||||||
let value = jsonObj[key];
|
|
||||||
key = strKey(key)
|
|
||||||
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
||||||
// 对象
|
|
||||||
luaStr += `${indent}${key} = {`;
|
|
||||||
luaStr += jsonToLua(value, indent + ' ');
|
|
||||||
luaStr += `${indent}},\n`;
|
|
||||||
} else if (Array.isArray(value)) {
|
|
||||||
// 数组
|
|
||||||
luaStr += `${indent}${key} = {`;
|
|
||||||
value.forEach(item => {
|
|
||||||
|
|
||||||
if (typeof item === 'string') {
|
|
||||||
luaStr += `${indent} '${item}',`;
|
|
||||||
} else if (typeof item == 'object') {
|
|
||||||
luaStr += `{${jsonToLua(item, '', '')}},`;
|
|
||||||
} else {
|
|
||||||
luaStr += `${indent} ${item},`;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
luaStr += `${indent}},\n`;
|
|
||||||
} else {
|
|
||||||
// 基础类型
|
|
||||||
if (typeof value === 'string') {
|
|
||||||
luaStr += `${indent}${key}="${value}",${linefeed}`;
|
|
||||||
} else {
|
|
||||||
luaStr += `${indent}${key} = ${value},${linefeed}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return luaStr;
|
|
||||||
}
|
|
||||||
const start = () => {
|
|
||||||
const files = fs.readdirSync(folderPath);
|
|
||||||
|
|
||||||
// 过滤出所有的 JSON 文件
|
|
||||||
const jsonFiles = files.filter(file => path.extname(file) === '.json').filter(file => scope.map(e => `${e}.json`).includes(file));
|
|
||||||
jsonFiles.forEach(file => {
|
|
||||||
const json = JSON.parse(fs.readFileSync(path.join(folderPath, file), 'utf8'))
|
|
||||||
const filename = path.basename(file, path.extname(file));
|
|
||||||
const luaConfig = `${filename}={\n${jsonToLua(json)}\n}`
|
|
||||||
fs.writeFileSync(`./luaConfigs/${filename}.config`, luaConfig);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
start()
|
|
||||||
57
tools/json2lua.js
Normal file
57
tools/json2lua.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
const { log } = require("console");
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const folderPath = "./configs";
|
||||||
|
const scope = [
|
||||||
|
"StdItems",
|
||||||
|
// "ItemMergeConfig", "MergeConfig", "MergeTotal", "RecyclingSettingConfig", "UpstarConfig", "Monster"
|
||||||
|
];
|
||||||
|
const strKey = (key) => (isNaN(key) ? `${key}` : `[${key}]`);
|
||||||
|
function jsonToLua(jsonObj, indent = "", linefeed = "\n") {
|
||||||
|
let luaStr = "";
|
||||||
|
for (key in jsonObj) {
|
||||||
|
let value = jsonObj[key];
|
||||||
|
key = strKey(key);
|
||||||
|
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
||||||
|
// 对象
|
||||||
|
luaStr += `${indent}${key} = {`;
|
||||||
|
luaStr += jsonToLua(value, indent + " ");
|
||||||
|
luaStr += `${indent}},\n`;
|
||||||
|
} else if (Array.isArray(value)) {
|
||||||
|
// 数组
|
||||||
|
luaStr += `${indent}${key} = {`;
|
||||||
|
value.forEach((item) => {
|
||||||
|
if (typeof item === "string") {
|
||||||
|
luaStr += `${indent} '${item}',`;
|
||||||
|
} else if (typeof item == "object") {
|
||||||
|
luaStr += `{${jsonToLua(item, "", "")}},`;
|
||||||
|
} else {
|
||||||
|
luaStr += `${indent} ${item},`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
luaStr += `${indent}},\n`;
|
||||||
|
} else {
|
||||||
|
// 基础类型
|
||||||
|
if (typeof value === "string") {
|
||||||
|
luaStr += `${indent}${key}="${value}",${linefeed}`;
|
||||||
|
} else {
|
||||||
|
luaStr += `${indent}${key}=${value},${linefeed}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return luaStr;
|
||||||
|
}
|
||||||
|
const start = () => {
|
||||||
|
const files = fs.readdirSync(folderPath);
|
||||||
|
|
||||||
|
// 过滤出所有的 JSON 文件
|
||||||
|
const jsonFiles = files.filter((file) => path.extname(file) === ".json").filter((file) => scope.map((e) => `${e}.json`).includes(file));
|
||||||
|
jsonFiles.forEach((file) => {
|
||||||
|
const json = JSON.parse(fs.readFileSync(path.join(folderPath, file), "utf8"));
|
||||||
|
const filename = path.basename(file, path.extname(file));
|
||||||
|
const luaConfig = `${filename}={\n${jsonToLua(json)}\n}`;
|
||||||
|
|
||||||
|
fs.writeFileSync(`./luaConfigs/${filename}.config`, luaConfig);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
start();
|
||||||
107
tools/lua2json.js
Normal file
107
tools/lua2json.js
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
const { log } = require('console');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const folderPath = "../luaConfigs"
|
||||||
|
|
||||||
|
function parseLuaConfig(luaContent) {
|
||||||
|
const config = {};
|
||||||
|
const lines = luaContent.split('\n');
|
||||||
|
let currentPath = config;
|
||||||
|
|
||||||
|
lines.forEach(line => {
|
||||||
|
line = line.trim();
|
||||||
|
if (line.startsWith('--')) return; // 跳过注释行
|
||||||
|
|
||||||
|
// 匹配键值对
|
||||||
|
const keyMatch = line.match(/^\s*(\w+)\s*=\s*(.+?),?$/);
|
||||||
|
if (keyMatch) {
|
||||||
|
const key = keyMatch[1].trim();
|
||||||
|
const value = keyMatch[2].trim();
|
||||||
|
|
||||||
|
// 尝试解析值
|
||||||
|
let parsedValue;
|
||||||
|
if (value === 'true' || value === 'false') {
|
||||||
|
parsedValue = value === 'true';
|
||||||
|
} else if (!isNaN(parseFloat(value))) {
|
||||||
|
parsedValue = parseFloat(value);
|
||||||
|
} else if (value.startsWith('"') && value.endsWith('"')) {
|
||||||
|
parsedValue = value.slice(1, -1);
|
||||||
|
} else if (value.startsWith('{') && value.endsWith('}')) {
|
||||||
|
parsedValue = parseLuaTable(value);
|
||||||
|
} else {
|
||||||
|
parsedValue = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理嵌套对象
|
||||||
|
const keys = key.split('.');
|
||||||
|
keys.reduce((acc, k, i) => {
|
||||||
|
if (i === keys.length - 1) {
|
||||||
|
acc[k] = parsedValue;
|
||||||
|
} else {
|
||||||
|
acc[k] = acc[k] || {};
|
||||||
|
return acc[k];
|
||||||
|
}
|
||||||
|
}, currentPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 匹配表(数组或对象)
|
||||||
|
const tableMatch = line.match(/^\s*(\w+)\s*=\s*{(.+?)},?$/);
|
||||||
|
if (tableMatch) {
|
||||||
|
const key = tableMatch[1].trim();
|
||||||
|
const tableContent = tableMatch[2].trim();
|
||||||
|
const parsedTable = parseLuaTable(tableContent);
|
||||||
|
|
||||||
|
// 处理嵌套对象
|
||||||
|
const keys = key.split('.');
|
||||||
|
keys.reduce((acc, k, i) => {
|
||||||
|
if (i === keys.length - 1) {
|
||||||
|
acc[k] = parsedTable;
|
||||||
|
} else {
|
||||||
|
acc[k] = acc[k] || {};
|
||||||
|
return acc[k];
|
||||||
|
}
|
||||||
|
}, currentPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析Lua表(数组或对象)
|
||||||
|
function parseLuaTable(tableContent) {
|
||||||
|
const table = [];
|
||||||
|
const lines = tableContent.split(',').map(line => line.trim());
|
||||||
|
|
||||||
|
lines.forEach(line => {
|
||||||
|
if (line.startsWith('{')) {
|
||||||
|
const nestedTableContent = line.slice(1, -1).trim();
|
||||||
|
table.push(parseLuaTable(nestedTableContent));
|
||||||
|
} else if (line.startsWith('"') && line.endsWith('"')) {
|
||||||
|
table.push(line.slice(1, -1));
|
||||||
|
} else if (!isNaN(parseFloat(line))) {
|
||||||
|
table.push(parseFloat(line));
|
||||||
|
} else if (line === 'true' || line === 'false') {
|
||||||
|
table.push(line === 'true');
|
||||||
|
} else {
|
||||||
|
table.push(line);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
const scope = ["Monster"]
|
||||||
|
|
||||||
|
const start = () => {
|
||||||
|
const files = fs.readdirSync(folderPath);
|
||||||
|
|
||||||
|
// 过滤出所有的 JSON 文件
|
||||||
|
const luaFiles = files.filter(file => path.extname(file) === '.config').filter(file => scope.map(e => `${e}.config`).includes(file));
|
||||||
|
luaFiles.forEach(file => {
|
||||||
|
const luaContent = fs.readFileSync(path.join(folderPath, file), 'utf8')
|
||||||
|
const filename = path.basename(file, path.extname(file));
|
||||||
|
const luaConfig = parseLuaConfig(luaContent);
|
||||||
|
log(luaConfig)
|
||||||
|
fs.writeFileSync(`../configs/${filename}.json`, luaConfig);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
start()
|
||||||
60
tools/sortJson.js
Normal file
60
tools/sortJson.js
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
const { log } = require("console");
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const folderPath = "./configs";
|
||||||
|
const scope = [
|
||||||
|
"StdItems",
|
||||||
|
// "ItemMergeConfig", "MergeConfig", "MergeTotal", "RecyclingSettingConfig", "UpstarConfig", "Monster"
|
||||||
|
];
|
||||||
|
|
||||||
|
// 自定义排序函数
|
||||||
|
function customSort(arr) {
|
||||||
|
return arr.sort((a, b) => {
|
||||||
|
const isANumeric = !isNaN(a);
|
||||||
|
const isBNumeric = !isNaN(b);
|
||||||
|
if (isANumeric && isBNumeric) {
|
||||||
|
return parseFloat(a) - parseFloat(b);
|
||||||
|
} else if (isANumeric) {
|
||||||
|
return -1;
|
||||||
|
} else if (typeof a == "object") {
|
||||||
|
return -1;
|
||||||
|
} else if (isBNumeric) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return a.localeCompare(b);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 递归排序函数
|
||||||
|
function sortObject(obj) {
|
||||||
|
if (Array.isArray(obj)) {
|
||||||
|
// 如果是数组,使用自定义排序函数
|
||||||
|
return customSort(obj.map((item) => sortObject(item)));
|
||||||
|
} else if (typeof obj === "object" && obj !== null) {
|
||||||
|
// 如果是对象,递归处理每个属性
|
||||||
|
const sortedObj = {};
|
||||||
|
Object.keys(obj)
|
||||||
|
.sort()
|
||||||
|
.forEach((key) => {
|
||||||
|
sortedObj[key] = sortObject(obj[key]);
|
||||||
|
});
|
||||||
|
return sortedObj;
|
||||||
|
} else {
|
||||||
|
// 如果是基本类型,直接返回
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const start = () => {
|
||||||
|
const files = fs.readdirSync(folderPath);
|
||||||
|
// 过滤出所有的 JSON 文件
|
||||||
|
const jsonFiles = files.filter((file) => path.extname(file) === ".json").filter((file) => scope.map((e) => `${e}.json`).includes(file));
|
||||||
|
jsonFiles.forEach((file) => {
|
||||||
|
const json = JSON.parse(fs.readFileSync(path.join(folderPath, file), "utf8"));
|
||||||
|
const filename = path.basename(file, path.extname(file));
|
||||||
|
const sortedJson = sortObject(json);
|
||||||
|
const jsonstr = JSON.stringify(sortedJson, null, 2);
|
||||||
|
fs.writeFileSync(`${folderPath}/${filename}.json`, jsonstr);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
start();
|
||||||
Reference in New Issue
Block a user