2023-10-24 19:34:36 +00:00
|
|
|
import fs from 'node:fs'
|
2022-07-30 20:20:10 +00:00
|
|
|
import lodash from 'lodash'
|
2023-02-13 20:43:14 +00:00
|
|
|
import cfgData from './cfg/CfgData.js'
|
2023-03-31 20:03:05 +00:00
|
|
|
import { Version } from '#miao'
|
2024-05-21 18:05:37 +00:00
|
|
|
import { miaoPath } from '#miao.path'
|
2022-04-09 21:33:21 +00:00
|
|
|
|
2024-05-21 18:05:37 +00:00
|
|
|
const _cfgPath = `${miaoPath}/components/`
|
2022-07-30 20:20:10 +00:00
|
|
|
let cfg = {}
|
2023-03-31 20:03:05 +00:00
|
|
|
let miaoCfg = {}
|
|
|
|
|
2022-04-09 21:33:21 +00:00
|
|
|
|
|
|
|
try {
|
2022-11-12 21:35:46 +00:00
|
|
|
cfg = await cfgData.getCfg()
|
2023-02-06 18:08:12 +00:00
|
|
|
cfgData.saveCfg(cfg)
|
2023-03-31 20:03:05 +00:00
|
|
|
lodash.forEach(cfgData.getCfgSchemaMap(), (cm) => {
|
|
|
|
if (cm.miao) {
|
|
|
|
miaoCfg[cm.cfgKey] = true
|
|
|
|
}
|
|
|
|
})
|
2022-04-09 21:33:21 +00:00
|
|
|
} catch (e) {
|
|
|
|
// do nth
|
|
|
|
}
|
|
|
|
|
|
|
|
let Cfg = {
|
2023-10-31 20:07:47 +00:00
|
|
|
get (rote, def = '') {
|
2023-03-31 20:03:05 +00:00
|
|
|
if (Version.isMiao && miaoCfg[rote]) {
|
|
|
|
return true
|
|
|
|
}
|
2023-10-31 20:07:47 +00:00
|
|
|
let ret = lodash.get(cfg, rote)
|
|
|
|
return lodash.isUndefined(cfg) ? def : ret
|
2022-04-09 21:33:21 +00:00
|
|
|
},
|
2022-07-30 20:20:10 +00:00
|
|
|
set (rote, val) {
|
2022-11-12 21:35:46 +00:00
|
|
|
cfg[rote] = val
|
|
|
|
cfgData.saveCfg(cfg)
|
2022-04-09 21:33:21 +00:00
|
|
|
},
|
2022-07-30 20:20:10 +00:00
|
|
|
del (rote) {
|
|
|
|
lodash.set(cfg, rote, undefined)
|
|
|
|
fs.writeFileSync(_cfgPath + 'cfg.json', JSON.stringify(cfg, null, '\t'))
|
2022-05-28 21:18:13 +00:00
|
|
|
},
|
2022-11-12 21:35:46 +00:00
|
|
|
getCfg () {
|
|
|
|
return cfg
|
|
|
|
},
|
|
|
|
getCfgSchema () {
|
|
|
|
return cfgData.getCfgSchema()
|
|
|
|
},
|
|
|
|
getCfgSchemaMap () {
|
|
|
|
return cfgData.getCfgSchemaMap()
|
|
|
|
},
|
2022-07-30 20:20:10 +00:00
|
|
|
scale (pct = 1) {
|
2022-11-12 21:35:46 +00:00
|
|
|
let scale = Cfg.get('renderScale', 100)
|
2022-07-30 20:20:10 +00:00
|
|
|
scale = Math.min(2, Math.max(0.5, scale / 100))
|
|
|
|
pct = pct * scale
|
|
|
|
return `style=transform:scale(${pct})`
|
2022-04-09 21:33:21 +00:00
|
|
|
}
|
2022-07-30 20:20:10 +00:00
|
|
|
}
|
2022-04-09 21:33:21 +00:00
|
|
|
|
2022-07-30 20:20:10 +00:00
|
|
|
export default Cfg
|