refactor(batchSetting): 重构批量设置脚本

- 将单个配置文件改为模块化设计,便于维护和扩展
- 新增 UpstarConfig.js 文件,作为独立的配置模块
- 重构 batchSetting.js 文件,使其支持多配置文件的批量处理
- 优化代码结构,提高可读性和可维护性
This commit is contained in:
aixianling
2025-01-22 18:03:12 +08:00
parent 2f55a178b5
commit 6ff25a47b9
2 changed files with 35 additions and 20 deletions

View File

@@ -1,10 +1,10 @@
const fs = require('fs')
const key = "UpstarConfig"
const values = [0, 1387, 10, 500, 10000, 5, 0] // 等级,物品ID,属性调整,元宝花费,升级概率
const interval = [1, 0, 15, 50, -450, 10, 1]
const num = 21
const start = () => {
const template = `"S1": {
module.exports = {
key: "UpstarConfig",
desc: "等级,物品ID,属性调整,元宝花费,升级概率",
values: [0, 1387, 10, 500, 10000, 5, 0],
interval: [1, 0, 15, 50, -450, 10, 1],
num: 21,
template: `"S1": {
"consume": [
{
"id": 4,
@@ -51,16 +51,5 @@ const start = () => {
}
],
"rate": S5
}`
const getStr = (index) => {
let str = template
values.forEach((v, i) => {
const reg = new RegExp(`S${i + 1}`, 'g')
str = str.replace(reg, v + index * interval[i])
})
return str
}
const content = Array(num).fill(1).map((e, i) => `${getStr(i)}`).join(',')
fs.writeFileSync(`./dist/${key}.txt`, content)
}
start()
}`,
};

26
tools/batchSetting.js Normal file
View File

@@ -0,0 +1,26 @@
const fs = require("fs");
const path = require("path");
const scope = ["UpstarConfig"].filter(Boolean);
const start = () => {
const configs = scope.map((key) => {
const file = require(`./batchTemples/${key}.js`);
return file;
});
configs.forEach((file) => {
const { key, values, interval, num, template } = file;
const getStr = (index) => {
let str = template;
values.forEach((v, i) => {
const reg = new RegExp(`S${i + 1}`, "g");
str = str.replace(reg, v + index * interval[i]);
});
return str;
};
const content = Array(num)
.fill(1)
.map((e, i) => `${getStr(i)}`)
.join(",");
fs.writeFileSync(`./dist/${key}.txt`, content);
});
};
start();