diff --git a/config/_project_json.yaml b/config/_project_json.yaml index bccabef..11199ad 100644 --- a/config/_project_json.yaml +++ b/config/_project_json.yaml @@ -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: en-us: ui_custom_background: Custom Background @@ -67,11 +67,11 @@ properties: value: text: ui_default_background type: combo - value: !match ${directFunc:getVar('assets', "backgrounds")[0]} + value: !match ~{var('assets', "backgrounds")[0]} fraction: false max: 100 min: 0 - options: !match ${directFunc:getVar('assets', "backgroundOptions")} + options: !match ~{var('assets', "backgroundOptions")} - key: background value: text: ui_custom_background @@ -86,7 +86,7 @@ properties: value: text: ui_position_padding_left type: slider - value: !match ${directFunc:getVar('config', "viewport_left")} + value: !match ~{var('config', "viewport_left")} condition: position.value == true fraction: false max: 100 @@ -95,7 +95,7 @@ properties: value: text: ui_position_padding_right type: slider - value: !match ${directFunc:getVar('config', "viewport_right")} + value: !match ~{var('config', "viewport_right")} condition: position.value == true fraction: false max: 100 @@ -104,7 +104,7 @@ properties: value: text: ui_position_padding_top type: slider - value: !match ${directFunc:getVar('config', "viewport_top")} + value: !match ~{var('config', "viewport_top")} condition: position.value == true fraction: false max: 100 @@ -113,7 +113,7 @@ properties: value: text: ui_position_padding_bottom type: slider - value: !match ${directFunc:getVar('config', "viewport_bottom")} + value: !match ~{var('config', "viewport_bottom")} condition: position.value == true fraction: false max: 100 diff --git a/libs/content_processor.js b/libs/content_processor.js index 170b737..7807467 100644 --- a/libs/content_processor.js +++ b/libs/content_processor.js @@ -8,7 +8,7 @@ export default class Matcher { constructor(start, end, config, assets) { this.#start = start this.#end = end - this.#reExp = new RegExp(`\\${start}.+?${end}`, 'g') + this.#reExp = new RegExp(`${start}.+?${end}`, 'g') this.#config = config this.#assets = assets } @@ -17,33 +17,21 @@ export default class Matcher { const matches = this.content.match(this.#reExp) if (matches !== null) { matches.forEach((match) => { - const matchTypeName = match.replace(this.#start, '').replace(this.#end, '') - const type = matchTypeName.split(':')[0] - const name = matchTypeName.split(':')[1] - switch (type) { - case 'var': - let replaceValue = this.#config - name.split('->').forEach((item) => { - try { - replaceValue = replaceValue[item] - } 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) { - 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}.`) + const name = match.replace(this.#start, '').replace(this.#end, '') + const result = (new Function( + 'Evalable', + 'config', + 'assets', + `return new Evalable(config, assets).${name}`) + )(Evalable, this.#config, this.#assets) + if (matches.length > 1) { + try { + this.content = this.content.replace(match, result) + } catch (e) { + throw new Error(e) + } + } else if (matches.length === 1) { + this.content = result } }) } @@ -64,7 +52,7 @@ class Evalable { return this.#step(location, varName).split(separator) } - getVar(location, varName) { + var(location, varName) { return this.#step(location, varName) } diff --git a/libs/project_json.js b/libs/project_json.js index 4f83206..2234e82 100644 --- a/libs/project_json.js +++ b/libs/project_json.js @@ -21,7 +21,7 @@ export default class ProjectJson { async load() { // load json from file 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, backgroundOptions: this.#assets.backgrounds.map((b) => { return {