feat(initializer): add copy-only mode
This commit is contained in:
@@ -41,7 +41,7 @@ optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
-p PORT, --port PORT Development server port (default: 8080)
|
||||
-o OPERATOR_NAME, --operator OPERATOR_NAME
|
||||
<Required> Operatro to develop (default: None)
|
||||
<Required> Operator to develop (default: None)
|
||||
-r, --rebuild Rebuild assets (default: False)
|
||||
```
|
||||
``` bash
|
||||
@@ -56,10 +56,12 @@ optional arguments:
|
||||
```
|
||||
``` bash
|
||||
$ python3 aklive2d.py i -h
|
||||
usage: aklive2d init [-h]
|
||||
usage: aklive2d init [-h] [-c OPERATOR_NAME]
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
-c OPERATOR_NAME, --copy OPERATOR_NAME
|
||||
YAML pre-defined Operator assets to copy (default: None)
|
||||
```
|
||||
### Webpage & JavaScript
|
||||
|
||||
|
||||
11
aklive2d.py
11
aklive2d.py
@@ -48,7 +48,7 @@ class AkLive2D:
|
||||
dest="operator_name",
|
||||
type=str,
|
||||
required=True,
|
||||
help="<Required> Operatro to develop",
|
||||
help="<Required> Operator to develop",
|
||||
)
|
||||
server.add_argument(
|
||||
"-r",
|
||||
@@ -87,6 +87,13 @@ class AkLive2D:
|
||||
aliases=['i'],
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
||||
)
|
||||
initializer.add_argument(
|
||||
"-c",
|
||||
"--copy",
|
||||
dest="operator_name",
|
||||
type=str,
|
||||
help="YAML pre-defined Operator assets to copy",
|
||||
)
|
||||
|
||||
self.args = parser.parse_args()
|
||||
if self.args.command == "server" or self.args.command == "s":
|
||||
@@ -94,7 +101,7 @@ class AkLive2D:
|
||||
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 = Initializer(self.config, self.args.operator_name)
|
||||
|
||||
self.running.start()
|
||||
|
||||
|
||||
@@ -65,8 +65,9 @@ class Config:
|
||||
return self.config
|
||||
|
||||
def save(self, config):
|
||||
yaml.SafeDumper.ignore_aliases = lambda *args : True
|
||||
with open(self.config_path, 'w') as f:
|
||||
yaml.safe_dump(config, f, allow_unicode=True)
|
||||
yaml.safe_dump(config, f, allow_unicode=True, default_flow_style=False)
|
||||
|
||||
def __read_config(self):
|
||||
try:
|
||||
|
||||
@@ -3,51 +3,24 @@ from lib.config import Config
|
||||
|
||||
class Initializer:
|
||||
|
||||
def __init__(self, config) -> None:
|
||||
def __init__(self, config, operator_name=None) -> 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,
|
||||
)
|
||||
}
|
||||
self.operator_name = operator_name
|
||||
self.yaml_template = dict(config["operators"]["skadi"])
|
||||
self.predefined = False
|
||||
if operator_name is not None:
|
||||
self.predefined = True
|
||||
pass
|
||||
|
||||
def start(self):
|
||||
if self.operator_name is None:
|
||||
self.__input()
|
||||
self.__copy_files()
|
||||
Config().save(self.config)
|
||||
return
|
||||
|
||||
def __input(self):
|
||||
print("=== Setting up basic info ===")
|
||||
print("Eg.chen")
|
||||
print("Eg.", "skadi")
|
||||
while(True):
|
||||
self.operator_name = input("Operator Name: ")
|
||||
if self.operator_name != "":
|
||||
@@ -75,13 +48,18 @@ class Initializer:
|
||||
self.yaml_template["project.json"]["description"] = input("Description: ") or self.yaml_template["project.json"]["description"]
|
||||
|
||||
self.config["operators"][self.operator_name] = self.yaml_template
|
||||
Config().save(self.config)
|
||||
return
|
||||
|
||||
def __copy_files(self):
|
||||
# ./operator/<operator_name>
|
||||
operator_assets_path = pathlib.Path.cwd().joinpath(self.config["server"]["operator_folder"], self.operator_name)
|
||||
if operator_assets_path.exists() is True:
|
||||
if self.predefined is False:
|
||||
shutil.rmtree(operator_assets_path)
|
||||
else:
|
||||
print("Operator assets folder already exists.")
|
||||
return
|
||||
operator_assets_path.mkdir()
|
||||
|
||||
dir_map = dict(
|
||||
@@ -99,7 +77,7 @@ class Initializer:
|
||||
copy_map = [
|
||||
dict(
|
||||
source_name="operator_settings.js",
|
||||
target_name="{}_settings.js".format(self.yaml_template["index.html"]["id"]),
|
||||
target_name="{}_settings.js".format(self.config["operators"][self.operator_name]["index.html"]["id"]),
|
||||
source_path=operator_settings_path,
|
||||
target_path=dir_map["config"],
|
||||
),
|
||||
@@ -116,8 +94,8 @@ class Initializer:
|
||||
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_name="{}.png".format(self.config["operators"][self.operator_name]["index.html"]["operator_logo"]),
|
||||
target_name="{}.png".format(self.config["operators"][self.operator_name]["index.html"]["operator_logo"]),
|
||||
source_path=logo_path,
|
||||
target_path=operator_assets_path,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user