diff --git a/aklive2d.py b/aklive2d.py index 561344a..d484fab 100755 --- a/aklive2d.py +++ b/aklive2d.py @@ -5,11 +5,12 @@ import sys from lib.config import Config from lib.server import Server from lib.builder import Builder +from lib.initializer import Initializer class AkLive2D: def __init__(self) -> None: - self.config = Config().config + self.config = Config().read() self.args = None self.running = None @@ -80,11 +81,20 @@ class AkLive2D: help="Rebuild assets" ) + initializer = subprasers.add_parser( + "init", + help="Initialize a new operator", + aliases=['i'], + formatter_class=argparse.ArgumentDefaultsHelpFormatter + ) + self.args = parser.parse_args() if self.args.command == "server" or self.args.command == "s": self.running = Server(self.args.port, self.args.operator_name, self.config, self.args.rebuild) elif self.args.command == "build" or self.args.command == "b": self.running = Builder(self.config, self.args.operator_names, self.args.rebuild) + elif self.args.command == "init" or self.args.command == "i": + self.running = Initializer(self.config) self.running.start() diff --git a/config.yaml b/config.yaml index cbbfa70..bac1e0d 100644 --- a/config.yaml +++ b/config.yaml @@ -1,93 +1,105 @@ +operator: + preview: preview.jpg + project_json: project.json + source_folder: ./operator/{name}/extracted/ + target_folder: ./operator/{name}/processed/ + use_skel: true operators: chen: - index.html: - id: char_1013_chen2 - operator_logo: logo_rhodes_override - title: Ch'en the Holungday - version: __get_version - fallback_name: char_1013_chen2_2 _operator_settings.js: fallbackImage_height: 2048 fallbackImage_width: 2048 filename: dyn_illust_char_1013_chen2 fps: 60 opacity: 100 + viewport_bottom: 1 viewport_left: 0 viewport_right: 0 viewport_top: 1 - viewport_bottom: 1 + index.html: + fallback_name: char_1013_chen2_2 + id: char_1013_chen2 + operator_logo: logo_rhodes_override + title: Ch'en the Holungday + version: __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' + 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 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: 1 workshopid: 2564643862 nian: - index.html: - id: char_2014_nian - operator_logo: logo_sui - title: Nian - version: __get_version - fallback_name: char_2014_nian_2 _operator_settings.js: fallbackImage_height: 2048 fallbackImage_width: 2048 filename: dyn_illust_char_2014_nian fps: 60 + viewport_bottom: 5 viewport_left: 2 viewport_right: 2 viewport_top: 3 - viewport_bottom: 5 + index.html: + fallback_name: char_2014_nian_2 + id: char_2014_nian + operator_logo: logo_sui + title: Nian + version: __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' + 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 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: 5 workshopid: 2564642594 skadi: - index.html: - id: char_1012_skadi2 - operator_logo: logo_egir - title: Skadi the Corrupting Heart - version: __get_version - fallback_name: char_1012_skadi2_2 _operator_settings.js: fallbackImage_height: 2048 fallbackImage_width: 2048 filename: dyn_illust_char_1012_skadi2 fps: 60 + viewport_bottom: -12 viewport_left: -5 viewport_right: -10 viewport_top: 0 - viewport_bottom: -12 + index.html: + fallback_name: char_1012_skadi2_2 + id: char_1012_skadi2 + operator_logo: logo_egir + title: Skadi the Corrupting Heart + version: __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' + 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 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: -12 workshopid: 2492307783 server: operator_folder: ./operator/ release_folder: ./release/ template_folder: ./template/ -operator: - use_skel: true - preview: preview.jpg - project_json: project.json - source_folder: ./operator/{name}/extracted/ - target_folder: ./operator/{name}/processed/ diff --git a/lib/config.py b/lib/config.py index a5c4ddb..3bab301 100644 --- a/lib/config.py +++ b/lib/config.py @@ -59,7 +59,14 @@ class Config: ) } ) + + def read(self): self.__read_config() + return self.config + + def save(self, config): + with open(self.config_path, 'w') as f: + yaml.safe_dump(config, f, allow_unicode=True) def __read_config(self): try: @@ -85,8 +92,7 @@ class Config: for filename, filetype in self.config[key][operator_name].items(): self.__config_check(filename, filetype, self.valid_keys["operator_config"][filename]) - # with open(self.config_path, 'w') as f: - # yaml.safe_dump(self.config, f, allow_unicode=True) + self.save(self.config) def __config_check(self, block_name: str, contents: dict, required_keys: dict): checklist = [key for key in required_keys] diff --git a/lib/initializer.py b/lib/initializer.py new file mode 100644 index 0000000..ff5a8f8 --- /dev/null +++ b/lib/initializer.py @@ -0,0 +1,130 @@ +import pathlib, shutil +from lib.config import Config + +class Initializer: + + def __init__(self, config) -> None: + self.config = config + self.operator_name = None + self.yaml_template = { + "_operator_settings.js": dict( + fallbackImage_height=2048, + fallbackImage_width=2048, + filename="dyn_illust_char_2014_nian", + fps=60, + viewport_bottom=0, + viewport_left=0, + viewport_right=0, + viewport_top=0, + ), + "index.html": dict( + fallback_name="char_2014_nian_2", + id="char_2014_nian", + operator_logo="logo_sui", + title="Operator name", + version="__get_version", + ), + "project.json": dict( + title="Arknights: Nian - 明日方舟:年", + 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", + ui_logo_opacity=30, + ui_logo_ratio=61.8, + ui_operator_logo="true", + ui_position_padding_bottom=0, + ui_position_padding_left=0, + ui_position_padding_right=0, + ui_position_padding_top=0, + workshopid=-1, + ) + } + pass + + def start(self): + self.__input() + self.__copy_files() + Config().save(self.config) + return + + def __input(self): + print("=== Setting up basic info ===") + print("Eg.chen") + while(True): + self.operator_name = input("Operator Name: ") + if self.operator_name != "": + break + else: + print("Operator name is empty!") + print("=== Setting up _operator_settings.js ===") + print("Eg.", self.yaml_template["_operator_settings.js"]["filename"]) + self.yaml_template["_operator_settings.js"]["filename"] = input("Filename: ") or self.yaml_template["_operator_settings.js"]["filename"] + + print("=== Setting up index.html ===") + print("Eg.", self.yaml_template["index.html"]["fallback_name"]) + self.yaml_template["index.html"]["fallback_name"] = input("Fallback Name: ") or self.yaml_template["index.html"]["fallback_name"] + print("Eg.", self.yaml_template["index.html"]["id"]) + self.yaml_template["index.html"]["id"] = input("ID Name: ") or self.yaml_template["index.html"]["id"] + print("Eg.", self.yaml_template["index.html"]["operator_logo"]) + self.yaml_template["index.html"]["operator_logo"] = input("Operator Logo Name: ") or self.yaml_template["index.html"]["operator_logo"] + print("Eg.", self.yaml_template["index.html"]["title"]) + self.yaml_template["index.html"]["title"] = input("Title: ") or self.yaml_template["index.html"]["title"] + + print("=== Setting up project.json ===") + print("Eg.", self.yaml_template["project.json"]["title"]) + self.yaml_template["project.json"]["title"] = input("Title: ") or self.yaml_template["project.json"]["title"] + print("Eg.", self.yaml_template["project.json"]["description"]) + self.yaml_template["project.json"]["description"] = input("Description: ") or self.yaml_template["project.json"]["description"] + + self.config["operators"][self.operator_name] = self.yaml_template + return + + def __copy_files(self): + # ./operator/ + operator_assets_path = pathlib.Path.cwd().joinpath(self.config["server"]["operator_folder"], self.operator_name) + if operator_assets_path.exists() is True: + shutil.rmtree(operator_assets_path) + operator_assets_path.mkdir() + + dir_map = dict( + config=pathlib.Path.cwd().joinpath(operator_assets_path, "config"), + extracted=pathlib.Path.cwd().joinpath(operator_assets_path, "extracted"), + processed=pathlib.Path.cwd().joinpath(operator_assets_path, "processed") + ) + + for key, path in dir_map.items(): + path.mkdir() + + # copy file + operator_settings_path = pathlib.Path.cwd().joinpath(self.config["server"]["operator_folder"], "_share") + logo_path = pathlib.Path.cwd().joinpath(operator_settings_path, "logo") + copy_map = [ + dict( + source_name="operator_settings.js", + target_name="{}_settings.js".format(self.yaml_template["index.html"]["id"]), + source_path=operator_settings_path, + target_path=dir_map["config"], + ), + dict( + source_name="project.json", + target_name="project.json", + source_path=operator_settings_path, + target_path=dir_map["config"], + ), + dict( + source_name="operator_bg.png", + target_name="operator_bg.png", + source_path=operator_settings_path, + target_path=operator_assets_path, + ), + dict( + source_name="{}.png".format(self.yaml_template["index.html"]["operator_logo"]), + target_name="{}.png".format(self.yaml_template["index.html"]["operator_logo"]), + source_path=logo_path, + target_path=operator_assets_path, + ), + ] + for item in copy_map: + shutil.copy( + pathlib.Path.cwd().joinpath(item["source_path"], item["source_name"]), + pathlib.Path.cwd().joinpath(item["target_path"], item["target_name"]) + ) + return \ No newline at end of file