miao-plugin/components/cfg-lib/cfg-data.js
Kokomi 5fe63f4896 * 为#喵喵设置增加更多配置项
* 允许禁用面板替换功能
    * 允许禁用非实装角色资料,关闭可禁用非实装角色资料及面板替换
    * 可选择面板服务,可选喵喵Api优先(需具备Token)或Enka优先
* 更新迪希雅、米卡的最新天赋与命座数据
* 全量使用通过属性计算得到的面板数据,移除相关配置项
2023-02-07 02:08:12 +08:00

48 lines
1.3 KiB
JavaScript

import { cfgSchema } from '../../config/system/cfg_system.js'
import lodash from 'lodash'
import { Data } from '../index.js'
import fs from 'node:fs'
let cfgData = {
saveCfg (cfg) {
let ret = []
lodash.forEach(cfgSchema, (cfgGroup) => {
ret.push(`/** ************ 【${cfgGroup.title}】 ************* */`)
lodash.forEach(cfgGroup.cfg, (cfgItem, cfgKey) => {
ret.push(`// ${cfgItem.desc || cfgItem.title}`)
let val = Data.def(cfg[cfgKey], cfgItem.def)
if (cfgItem.input) {
val = cfgItem.input(val)
}
ret.push(`export const ${cfgKey} = ${val.toString()}`, '')
})
})
fs.writeFileSync(`${process.cwd()}/plugins/miao-plugin/config/cfg.js`, ret.join('\n'), 'utf8')
},
async getCfg () {
let ret = lodash.toPlainObject(await Data.importModule('/config/cfg.js'))
lodash.forEach(cfgSchema, (cfgGroup) => {
lodash.forEach(cfgGroup.cfg, (cfgItem, cfgKey) => {
ret[cfgKey] = Data.def(ret[cfgKey], cfgItem.def)
})
})
return ret
},
getCfgSchemaMap () {
let ret = {}
lodash.forEach(cfgSchema, (cfgGroup) => {
lodash.forEach(cfgGroup.cfg, (cfgItem, cfgKey) => {
ret[cfgItem.key] = cfgItem
cfgItem.cfgKey = cfgKey
})
})
return ret
},
getCfgSchema () {
return cfgSchema
}
}
export default cfgData