feat(content processor): update logic

This commit is contained in:
Haoyu Xu
2023-01-21 17:44:53 -05:00
parent f363c0b908
commit 3efd3cb11a
3 changed files with 25 additions and 37 deletions

View File

@@ -1,4 +1,4 @@
description: !match "${replaceFunc:split('config', 'title' ,' - ')[0]} Live 2D\n${replaceFunc:split('config', 'title' ,' - ')[1]} Live 2D\nThe model is extracted from game with Spine support.\n模型来自游戏内提取支持Spine\nPlease set your FPS target in Wallpaper Engine > Settings > Performance > FPS\n请在 Wallpaper Engine > 设置 > 性能 > FPS 下设置FPS\n\nLive preview on: https://arknights.halyul.dev/${var:link}\nGithub: https://github.com/Halyul/aklive2d" description: !match "~{split('config', 'title' ,' - ')[0]} Live 2D\n~{split('config', 'title' ,' - ')[1]} Live 2D\nThe model is extracted from game with Spine support.\n模型来自游戏内提取支持Spine\nPlease set your FPS target in Wallpaper Engine > Settings > Performance > FPS\n请在 Wallpaper Engine > 设置 > 性能 > FPS 下设置FPS\n\nLive preview on: https://arknights.halyul.dev/~{var('config', 'link')}\nGithub: https://github.com/Halyul/aklive2d"
localization: localization:
en-us: en-us:
ui_custom_background: Custom Background ui_custom_background: Custom Background
@@ -67,11 +67,11 @@ properties:
value: value:
text: ui_default_background text: ui_default_background
type: combo type: combo
value: !match ${directFunc:getVar('assets', "backgrounds")[0]} value: !match ~{var('assets', "backgrounds")[0]}
fraction: false fraction: false
max: 100 max: 100
min: 0 min: 0
options: !match ${directFunc:getVar('assets', "backgroundOptions")} options: !match ~{var('assets', "backgroundOptions")}
- key: background - key: background
value: value:
text: ui_custom_background text: ui_custom_background
@@ -86,7 +86,7 @@ properties:
value: value:
text: ui_position_padding_left text: ui_position_padding_left
type: slider type: slider
value: !match ${directFunc:getVar('config', "viewport_left")} value: !match ~{var('config', "viewport_left")}
condition: position.value == true condition: position.value == true
fraction: false fraction: false
max: 100 max: 100
@@ -95,7 +95,7 @@ properties:
value: value:
text: ui_position_padding_right text: ui_position_padding_right
type: slider type: slider
value: !match ${directFunc:getVar('config', "viewport_right")} value: !match ~{var('config', "viewport_right")}
condition: position.value == true condition: position.value == true
fraction: false fraction: false
max: 100 max: 100
@@ -104,7 +104,7 @@ properties:
value: value:
text: ui_position_padding_top text: ui_position_padding_top
type: slider type: slider
value: !match ${directFunc:getVar('config', "viewport_top")} value: !match ~{var('config', "viewport_top")}
condition: position.value == true condition: position.value == true
fraction: false fraction: false
max: 100 max: 100
@@ -113,7 +113,7 @@ properties:
value: value:
text: ui_position_padding_bottom text: ui_position_padding_bottom
type: slider type: slider
value: !match ${directFunc:getVar('config', "viewport_bottom")} value: !match ~{var('config', "viewport_bottom")}
condition: position.value == true condition: position.value == true
fraction: false fraction: false
max: 100 max: 100

View File

@@ -8,7 +8,7 @@ export default class Matcher {
constructor(start, end, config, assets) { constructor(start, end, config, assets) {
this.#start = start this.#start = start
this.#end = end this.#end = end
this.#reExp = new RegExp(`\\${start}.+?${end}`, 'g') this.#reExp = new RegExp(`${start}.+?${end}`, 'g')
this.#config = config this.#config = config
this.#assets = assets this.#assets = assets
} }
@@ -17,33 +17,21 @@ export default class Matcher {
const matches = this.content.match(this.#reExp) const matches = this.content.match(this.#reExp)
if (matches !== null) { if (matches !== null) {
matches.forEach((match) => { matches.forEach((match) => {
const matchTypeName = match.replace(this.#start, '').replace(this.#end, '') const name = match.replace(this.#start, '').replace(this.#end, '')
const type = matchTypeName.split(':')[0] const result = (new Function(
const name = matchTypeName.split(':')[1] 'Evalable',
switch (type) { 'config',
case 'var': 'assets',
let replaceValue = this.#config `return new Evalable(config, assets).${name}`)
name.split('->').forEach((item) => { )(Evalable, this.#config, this.#assets)
try { if (matches.length > 1) {
replaceValue = replaceValue[item] try {
} catch (e) { this.content = this.content.replace(match, result)
throw new Error(`Cannot find variable ${name}.`) } catch (e) {
} throw new Error(e)
this.content = this.content.replace(match, replaceValue) }
}) } else if (matches.length === 1) {
break this.content = result
case 'replaceFunc':
try {
this.content = this.content.replace(match, (new Function('Evalable', 'config', 'assets', `return new Evalable(config, assets).${name}`))(Evalable, this.#config, this.#assets))
} catch (e) {
throw new Error(e)
}
break
case 'directFunc':
this.content = (new Function('Evalable', 'config', 'assets', `return new Evalable(config, assets).${name}`))(Evalable, this.#config, this.#assets)
break
default:
throw new Error(`Cannot find type ${type}.`)
} }
}) })
} }
@@ -64,7 +52,7 @@ class Evalable {
return this.#step(location, varName).split(separator) return this.#step(location, varName).split(separator)
} }
getVar(location, varName) { var(location, varName) {
return this.#step(location, varName) return this.#step(location, varName)
} }

View File

@@ -21,7 +21,7 @@ export default class ProjectJson {
async load() { async load() {
// load json from file // load json from file
this.#json = JSON.parse(await readFile(this.#getPath())) this.#json = JSON.parse(await readFile(this.#getPath()))
const matcher = new Matcher('${', '}', __config.operators[this.#operatorName], { const matcher = new Matcher('~{', '}', __config.operators[this.#operatorName], {
...this.#assets, ...this.#assets,
backgroundOptions: this.#assets.backgrounds.map((b) => { backgroundOptions: this.#assets.backgrounds.map((b) => {
return { return {