feat(builder): use a new content processor

This commit is contained in:
Haoyu Xu
2021-08-08 15:01:04 -04:00
parent a59ba1c3a0
commit 04856af894
5 changed files with 151 additions and 29 deletions

View File

@@ -10,6 +10,32 @@ operators:
target_folder: ./operator/{name}/processed/
title: Ch'en the Holungday
use_skel: true
config:
index.html:
operator_logo: logo_rhodes_override
title: Ch'en the Holungday
version: __get_version
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
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
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
workshopid: 2564643862
nian:
common_name: dyn_illust_char_2014_nian
fallback_name: char_2014_nian_2
@@ -21,6 +47,31 @@ operators:
target_folder: ./operator/{name}/processed/
title: Nian
use_skel: true
config:
index.html:
operator_logo: logo_sui
title: Nian
version: __get_version
operator_settings.js:
fallbackImage_height: 2048
fallbackImage_width: 2048
filename: dyn_illust_char_2014_nian
fps: 60
viewport_left: 2
viewport_right: 2
viewport_top: 3
viewport_bottom: 5
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
ui_logo_ratio: 61.8
ui_operator_logo: 'true'
ui_position_padding_left: 02
ui_position_padding_right: 2
ui_position_padding_top: 3
ui_position_padding_bottom: 5
workshopid: 2564642594
skadi:
common_name: dyn_illust_char_1012_skadi2
fallback_name: char_1012_skadi2_2
@@ -32,6 +83,31 @@ operators:
target_folder: ./operator/{name}/processed/
title: Skadi the Corrupting Heart
use_skel: true
config:
index.html:
operator_logo: logo_egir
title: Skadi the Corrupting Heart
version: __get_version
operator_settings.js:
fallbackImage_height: 2048
fallbackImage_width: 2048
filename: dyn_illust_char_1012_skadi2
fps: 60
viewport_left: -5
viewport_right: -10
viewport_top: 0
viewport_bottom: -12
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
ui_logo_ratio: 61.8
ui_operator_logo: 'true'
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/

View File

@@ -4,14 +4,13 @@ from lib.skeleton_binary import SkeletonBinary
from lib.alpha_composite import AlphaComposite
from lib.atlas_reader import AtlasReader
from lib.base64_util import *
from lib.html_processor import HtmlProcessor
from lib.content_processor import ContentProcessor
class Builder:
def __init__(self, config, operator_names=list(), rebuild=False) -> None:
self.operator_names = operator_names
self.config = config
self.html_processor = HtmlProcessor(config)
self.rebuild = rebuild
def start(self):
@@ -191,6 +190,7 @@ class Builder:
release_operator_assets_path = pathlib.Path.cwd().joinpath(operator_release_path, self.config["server"]["operator_folder"])
operator_assets_path = pathlib.Path.cwd().joinpath(self.config["operators"][operator_name]["target_folder"].format(name=operator_name), "..")
template_path = pathlib.Path.cwd().joinpath(self.config["server"]["template_folder"])
content_processor = ContentProcessor(self.config, operator_name)
if operator_release_path.exists() is True:
shutil.rmtree(operator_release_path)
@@ -205,28 +205,15 @@ class Builder:
else:
file_path = pathlib.Path.cwd().joinpath(release_operator_assets_path, filename)
shutil.copyfile(
file,
file_path
)
content_processor.build(file, file_path)
for file in template_path.iterdir():
if file.is_file() is True:
__temp = file.name.split(".")
filename = __temp[0]
fileext = __temp[1]
file_path = pathlib.Path.cwd().joinpath(operator_release_path, file.name)
if filename == "index" and fileext == "html":
self.html_processor.build(operator_name, file, file_path)
else:
shutil.copyfile(
file,
file_path
)
content_processor.build(file, file_path)
elif file.is_dir() is True:
filename = file.name
file_path = pathlib.Path.cwd().joinpath(operator_release_path, filename)
file_path = pathlib.Path.cwd().joinpath(operator_release_path, file.name)
shutil.copytree(
file,

View File

@@ -25,6 +25,7 @@ class Config:
preview=str,
use_skel=bool,
title=str,
config=dict,
)
)
self.__read_config()
@@ -48,8 +49,8 @@ class Config:
for operator_name, operator_content in self.config[key].items():
self.__config_check(operator_name, operator_content, self.valid_keys[key])
with open(self.config_path, 'w') as f:
yaml.safe_dump(self.config, f, allow_unicode=True)
# with open(self.config_path, 'w') as f:
# yaml.safe_dump(self.config, f, allow_unicode=True)
def __config_check(self, block_name: str, contents: dict, required_keys: dict):
checklist = [key for key in required_keys]

58
lib/content_processor.py Normal file
View File

@@ -0,0 +1,58 @@
import pathlib
import shutil
class ContentProcessor:
def __init__(self, config, operator_name):
self.config = config["operators"][operator_name]
self.file_to_process = [key for key, value in self.config["config"].items()]
self.settings = self.config["config"]
self.evalable = [
"__get_version"
]
self.__process_value()
def process(self, file_path):
with open(pathlib.Path.cwd().joinpath(file_path), "r") as f:
content = Formatter(f.read(), "{# ", " #}")
return content.format(**self.settings[file_path.name])
def build(self, source_path, target_path):
if source_path.name in self.file_to_process:
content = self.process(source_path)
with open(pathlib.Path.cwd().joinpath(target_path), "w") as f:
f.write(content)
else:
shutil.copyfile(
source_path,
target_path
)
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))
self.settings[item_key][key] = replace_value
def __get_version(self):
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
self.start = start
self.end = end
def format(self, **kwargs):
for key, value in kwargs.items():
identifier = self.start + key + self.end
self.content = self.content.replace(identifier, str(value))
return self.content

View File

@@ -6,23 +6,23 @@
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="renderer" content="webkit">
<title>{title}</title>
<link rel="stylesheet" href="./assets/style.css?v={version}">
<link rel="stylesheet" href="./assets/spine-player.css?v={version}">
<title>{# title #}</title>
<link rel="stylesheet" href="./assets/style.css?v={# version #}">
<link rel="stylesheet" href="./assets/spine-player.css?v={# version #}">
</head>
<body>
<div id="dev" style="position: fixed;left: 0;top: 0;background-color: white;"></div>
<image src="./operator/{operator_logo}.png" class="logo invert-filter" id="logo" alt="operator logo" />
<image src="./operator/{# operator_logo #}.png" class="logo invert-filter" id="logo" alt="operator logo" />
<div id="widget-wrapper" style="width: 100%; height: 100%;">
<div id="container" style="width: 100%; height: 100%;"></div>
</div>
</body>
<script type="text/javascript" src="./assets/spine-player.js?v={version}"></script>
<script type="text/javascript" src="./operator/operator_assets.js?v={version}"></script>
<script type="text/javascript" src="./operator/operator_settings.js?v={version}"></script>
<script type="text/javascript" src="./assets/settings.js?v={version}"></script>
<script type="text/javascript" src="./assets/runner.js?v={version}"></script>
<script type="text/javascript" src="./assets/spine-player.js?v={# version #}"></script>
<script type="text/javascript" src="./operator/operator_assets.js?v={# version #}"></script>
<script type="text/javascript" src="./operator/operator_settings.js?v={# version #}"></script>
<script type="text/javascript" src="./assets/settings.js?v={# version #}"></script>
<script type="text/javascript" src="./assets/runner.js?v={# version #}"></script>
</html>