diff --git a/Version b/Version index 8f9174b..abae0d9 100644 --- a/Version +++ b/Version @@ -1 +1 @@ -2.1.2 \ No newline at end of file +2.1.3 \ No newline at end of file diff --git a/config.yaml b/config.yaml index 50b17d4..1881446 100644 --- a/config.yaml +++ b/config.yaml @@ -20,22 +20,22 @@ operators: fallback_name: char_1013_chen2_2 id: char_1013_chen2 operator_logo: logo_rhodes_override - title: Ch'en the Holungday - version: __get_version + title: 'Arknights: Ch''en/Chen the Holungday - 明日方舟:假日威龙陈' + version: ${func:get_version()} project.json: description: 'Arknights: Ch''en/Chen the Holungday Live 2D\n明日方舟:假日威龙陈 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/chen\nGithub: https://github.com/Halyul/aklive2d' - title: 'Arknights: Ch''en/Chen the Holungday - 明日方舟:假日威龙陈' - ui_logo_opacity: 100 + title: ${var:index.html->title} + ui_logo_opacity: ${var:_operator_settings.js->opacity} ui_logo_ratio: 61.8 ui_operator_logo: 'true' - ui_position_padding_bottom: 1 - ui_position_padding_left: 0 - ui_position_padding_right: 0 - ui_position_padding_top: 1 + ui_position_padding_bottom: ${var:_operator_settings.js->viewport_bottom} + ui_position_padding_left: ${var:_operator_settings.js->viewport_left} + ui_position_padding_right: ${var:_operator_settings.js->viewport_right} + ui_position_padding_top: ${var:_operator_settings.js->viewport_top} workshopid: 2564643862 nearl: _operator_settings.js: @@ -52,22 +52,22 @@ operators: fallback_name: char_1014_nearl2_2 id: char_1014_nearl2 operator_logo: logo_kazimierz - title: Nearl the Radiant Knight - version: __get_version + title: 'Arknights: Nearl the Radiant Knight - 明日方舟:耀骑士临光' + version: ${func:get_version()} project.json: description: 'Arknights: Nearl the Radiant Knight Live 2D\n明日方舟:耀骑士临光 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/nearl\nGithub: https://github.com/Halyul/aklive2d' - title: 'Arknights: Nearl the Radiant Knight - 明日方舟:耀骑士临光' - ui_logo_opacity: 30 + title: ${var:index.html->title} + ui_logo_opacity: ${var:_operator_settings.js->opacity} ui_logo_ratio: 61.8 ui_operator_logo: 'true' - ui_position_padding_bottom: 0 - ui_position_padding_left: 2 - ui_position_padding_right: 3 - ui_position_padding_top: 10 + ui_position_padding_bottom: ${var:_operator_settings.js->viewport_bottom} + ui_position_padding_left: ${var:_operator_settings.js->viewport_left} + ui_position_padding_right: ${var:_operator_settings.js->viewport_right} + ui_position_padding_top: ${var:_operator_settings.js->viewport_top} workshopid: 2642836787 nian: _operator_settings.js: @@ -75,6 +75,7 @@ operators: fallbackImage_width: 2048 filename: dyn_illust_char_2014_nian fps: 60 + opacity: 30 viewport_bottom: 5 viewport_left: 2 viewport_right: 2 @@ -83,22 +84,22 @@ operators: fallback_name: char_2014_nian_2 id: char_2014_nian operator_logo: logo_sui - title: Nian - version: __get_version + title: 'Arknights: Nian - 明日方舟:年' + version: ${func:get_version()} project.json: description: 'Arknights: Nian Live 2D\n明日方舟:年 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/nian\nGithub: https://github.com/Halyul/aklive2d' - title: 'Arknights: Nian - 明日方舟:年' - ui_logo_opacity: 30 + title: ${var:index.html->title} + ui_logo_opacity: ${var:_operator_settings.js->opacity} ui_logo_ratio: 61.8 ui_operator_logo: 'true' - ui_position_padding_bottom: 5 - ui_position_padding_left: 2 - ui_position_padding_right: 2 - ui_position_padding_top: 3 + ui_position_padding_bottom: ${var:_operator_settings.js->viewport_bottom} + ui_position_padding_left: ${var:_operator_settings.js->viewport_left} + ui_position_padding_right: ${var:_operator_settings.js->viewport_right} + ui_position_padding_top: ${var:_operator_settings.js->viewport_top} workshopid: 2564642594 rosmontis: _operator_settings.js: @@ -115,22 +116,22 @@ operators: fallback_name: char_391_rosmon_2 id: char_391_rosmon operator_logo: logo_rhodes_override - title: Rosmontis - version: __get_version + title: 'Arknights: Rosmontis - 明日方舟:迷迭香' + version: ${func:get_version()} project.json: description: 'Arknights: Rosmontis Live 2D\n明日方舟:迷迭香 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/rosmontis\nGithub: https://github.com/Halyul/aklive2d' - title: 'Arknights: Rosmontis - 明日方舟:迷迭香' - ui_logo_opacity: 100 + title: ${var:index.html->title} + ui_logo_opacity: ${var:_operator_settings.js->opacity} ui_logo_ratio: 61.8 ui_operator_logo: 'true' - ui_position_padding_bottom: -1 - ui_position_padding_left: 0 - ui_position_padding_right: -14 - ui_position_padding_top: -38 + ui_position_padding_bottom: ${var:_operator_settings.js->viewport_bottom} + ui_position_padding_left: ${var:_operator_settings.js->viewport_left} + ui_position_padding_right: ${var:_operator_settings.js->viewport_right} + ui_position_padding_top: ${var:_operator_settings.js->viewport_top} workshopid: 2642834981 skadi: _operator_settings.js: @@ -138,6 +139,7 @@ operators: fallbackImage_width: 2048 filename: dyn_illust_char_1012_skadi2 fps: 60 + opacity: 30 viewport_bottom: -12 viewport_left: -5 viewport_right: -10 @@ -146,22 +148,22 @@ operators: fallback_name: char_1012_skadi2_2 id: char_1012_skadi2 operator_logo: logo_egir - title: Skadi the Corrupting Heart - version: __get_version + title: 'Arknights: Skadi the Corrupting Heart - 明日方舟:浊心斯卡蒂' + version: ${func:get_version()} project.json: description: 'Arknights: Skadi the Corrupting Heart Live 2Di\r\n明日方舟:浊心斯卡蒂 Live 2Di\r\nThe model is extracted from game with Spine support.\r\n模型来自游戏内提取,支持Spine\r\nPlease set your FPS target in Wallpaper Engine > Settings > Performance > FPS\r\n请在 Wallpaper Engine > 设置 > 性能 > FPS 下设置FPS\r\n\r\nLive preview on: https://arknights.halyul.dev/skadi\r\nGithub: https://github.com/Halyul/aklive2d' - title: 'Arknights: Skadi the Corrupting Heart - 明日方舟:浊心斯卡蒂' - ui_logo_opacity: 30 + title: ${var:index.html->title} + ui_logo_opacity: ${var:_operator_settings.js->opacity} ui_logo_ratio: 61.8 ui_operator_logo: 'true' - ui_position_padding_bottom: -12 - ui_position_padding_left: -5 - ui_position_padding_right: -10 - ui_position_padding_top: 0 + ui_position_padding_bottom: ${var:_operator_settings.js->viewport_bottom} + ui_position_padding_left: ${var:_operator_settings.js->viewport_left} + ui_position_padding_right: ${var:_operator_settings.js->viewport_right} + ui_position_padding_top: ${var:_operator_settings.js->viewport_top} workshopid: 2492307783 w: _operator_settings.js: @@ -178,22 +180,22 @@ operators: fallback_name: char_113_cqbw_2 id: char_113_cqbw operator_logo: logo_babel - title: W - version: __get_version + title: 'Arknights: W - 明日方舟:W' + version: ${func:get_version()} project.json: description: 'Arknights: W Live 2D\n明日方舟:W 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/w\nGithub: https://github.com/Halyul/aklive2d' - title: 'Arknights: W - 明日方舟:W' - ui_logo_opacity: 30 + title: ${var:index.html->title} + ui_logo_opacity: ${var:_operator_settings.js->opacity} ui_logo_ratio: 61.8 ui_operator_logo: 'true' - ui_position_padding_bottom: 1 - ui_position_padding_left: 3 - ui_position_padding_right: -3 - ui_position_padding_top: 0 + ui_position_padding_bottom: ${var:_operator_settings.js->viewport_bottom} + ui_position_padding_left: ${var:_operator_settings.js->viewport_left} + ui_position_padding_right: ${var:_operator_settings.js->viewport_right} + ui_position_padding_top: ${var:_operator_settings.js->viewport_top} workshopid: 2642838078 server: operator_folder: ./operator/ diff --git a/lib/config.py b/lib/config.py index d8c0a59..34e511e 100644 --- a/lib/config.py +++ b/lib/config.py @@ -44,17 +44,13 @@ class Config: viewport_right=int, viewport_top=int, viewport_bottom=int, + opacity=int, ), "project.json": dict( description=str, title=str, - ui_logo_opacity=int, ui_logo_ratio=float, ui_operator_logo=str, - ui_position_padding_left=int, - ui_position_padding_right=int, - ui_position_padding_top=int, - ui_position_padding_bottom=int, workshopid=int, ) } diff --git a/lib/content_processor.py b/lib/content_processor.py index 93c84e0..2165f28 100644 --- a/lib/content_processor.py +++ b/lib/content_processor.py @@ -7,9 +7,6 @@ class ContentProcessor: self.config = config["operators"][operator_name] self.file_to_process = [key for key, value in self.config.items() if key.startswith("_") is False] self.settings = self.config - self.evalable = [ - "__get_version" - ] self.__process_value() def process(self, file_path): @@ -17,8 +14,8 @@ class ContentProcessor: with open(file_path, "r") as f: content = f.read() if file_path.name in self.file_to_process: - content = Formatter(content, "{# ", " #}") - return content.format(**self.settings[file_path.name]) + content = Matcher(content, "${format:", "}", self.settings) + return content.format(file_path.name) else: return content @@ -36,32 +33,54 @@ class ContentProcessor: def __process_value(self): for item_key, item_value in self.settings.items(): for key, value in item_value.items(): - replace_value = value - # if value in evalable - if value in self.evalable: - if value == "__get_version": - replace_value = self.__get_version() - else: - raise Exception("Unsupported function name: {}".format(value)) + matcher = Matcher(value, "${", "}", self.settings) + if matcher.match(): + replace_value = matcher.process() + else: + replace_value = value self.settings[item_key][key] = replace_value # copy dict value _operator_settings.js to {id}_settings.js settings_filename = "{}_settings.js".format(self.settings["index.html"]["id"]) self.settings[settings_filename] = self.settings["_operator_settings.js"] self.file_to_process.append(settings_filename) - def __get_version(self): +class Evalable: + def get_version(): with open(pathlib.Path.cwd().joinpath("Version"), "r") as f: version = f.read() return version -class Formatter: - def __init__(self, content, start, end): - self.content = content +class Matcher: + def __init__(self, content, start, end, settings): self.start = start self.end = end + self.content = str(content) + self.settings = settings + + def match(self): + return self.content.startswith(self.start) and self.content.endswith(self.end) - def format(self, **kwargs): - for key, value in kwargs.items(): + def process(self): + type = self.content.replace(self.start, "").replace(self.end, "").split(":")[0] + name = self.content.replace(self.start, "").replace(self.end, "").split(":")[1] + if type == "func": + try: + replace_value = eval("Evalable." + name) + except Exception as e: + raise e + elif type == "var": + replace_value = self.settings + for var in name.split("->"): + try: + replace_value = replace_value[var] + except Exception as e: + raise e + else: + raise Exception("Unsupported type: {}".format(type)) + return replace_value + + def format(self, filename): + for key, value in self.settings[filename].items(): identifier = self.start + key + self.end self.content = self.content.replace(identifier, str(value)) - return self.content \ No newline at end of file + return self.content diff --git a/template/index.html b/template/index.html index 988d96d..0756dc8 100644 --- a/template/index.html +++ b/template/index.html @@ -6,24 +6,24 @@ -