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