feat(content processor): update logic
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
if (matches.length > 1) {
|
||||||
try {
|
try {
|
||||||
replaceValue = replaceValue[item]
|
this.content = this.content.replace(match, result)
|
||||||
} catch (e) {
|
|
||||||
throw new Error(`Cannot find variable ${name}.`)
|
|
||||||
}
|
|
||||||
this.content = this.content.replace(match, replaceValue)
|
|
||||||
})
|
|
||||||
break
|
|
||||||
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) {
|
} catch (e) {
|
||||||
throw new Error(e)
|
throw new Error(e)
|
||||||
}
|
}
|
||||||
break
|
} else if (matches.length === 1) {
|
||||||
case 'directFunc':
|
this.content = result
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user