更新协议,完成可用性升级,更换协议

This commit is contained in:
2024-08-08 18:47:14 +08:00
parent 4791dcd63d
commit 319be8bbc0
11 changed files with 284 additions and 138 deletions

View File

@ -7,24 +7,28 @@
伶伦转换器 命令行
Linglun Converter CLI
版权所有 © 2024 金羿 & 睿乐开发组
Copyright © 2024 EillesWan & TriM Org.
版权所有 © 2024 金羿
Copyright © 2024 EillesWan
开源相关声明请见 ./License.md
Terms & Conditions: ./Lisense.md
伶伦转换器命令行版本(“本项目”)的协议颁发者为 金羿
The Licensor of _Linglun Converter CLI_("this project") is Eilles Wan.
本项目根据 第一版 汉钰律许可协议(“本协议”)授权。
任何人皆可从以下地址获得本协议副本https://gitee.com/EillesWan/YulvLicenses。
若非因法律要求或经过了特殊准许,此作品在根据本协议“原样”提供的基础上,不予提供任何形式的担保、任何明示、任何暗示或类似承诺。也就是说,用户将自行承担因此作品的质量或性能问题而产生的全部风险。
详细的准许和限制条款请见原协议文本。
"""
__version__ = "0.0.7"
__version__ = "0.0.8"
import datetime
import os
import random
# import sys
import Musicreater
from Musicreater.constants import DEFAULT_PROGRESSBAR_STYLE
from Musicreater.plugin import ConvertConfig
from Musicreater import DEFAULT_PROGRESSBAR_STYLE
from Musicreater.plugin.addonpack import (
to_addon_pack_in_delay,
to_addon_pack_in_repeater,
@ -34,10 +38,11 @@ from Musicreater.plugin.addonpack import (
from Musicreater.plugin.mcstructfile import (
to_mcstructure_file_in_delay,
to_mcstructure_file_in_repeater,
# to_mcstructure_file_in_score,
to_mcstructure_file_in_score,
)
from Musicreater.plugin.bdxfile import to_BDX_file_in_delay, to_BDX_file_in_score
from utils.io import logger, int_str, prt, ipt, myWords, isin, bool_str, float_str
from utils.io import logger, int_str, prt, ipt, isin, bool_str, float_str
from utils.yanlun import yanlun_texts, solar_date
# from Musicreater.plugin.mcstructure import commands_to_structure, commands_to_redstone_delay_structure
@ -76,33 +81,25 @@ logger.console.rule(
style="#26E2FF",
)
nowYang = datetime.datetime.now()
if nowYang.month == 8 and nowYang.day == 6:
if solar_date == (4, 3):
# 诸葛八卦生日
logger.console.print(
"[#7DB5F0 on #121110]今天可不是催更的日子!\n诸葛亮与八卦阵{}岁生日快乐!".format(
nowYang.year - 2008
),
style="#7DB5F0 on #121110",
justify="center",
)
elif nowYang.month == 4 and nowYang.day == 3:
style_ = "#7DB5F0 on #121110"
elif solar_date == (8, 6):
# 金羿生日快乐
logger.console.print(
"[#0089F2 on #F0F2F4]今天就不要催更啦!\n金羿{}岁生日快乐!".format(
nowYang.year - 2006
),
style="#0089F2 on #F0F2F4",
justify="center",
)
style_ = "#0089F2 on #F0F2F4"
elif solar_date == (8, 16):
# 旧梦生日快乐
style_ = "#F0F2F4 on #0089F2" # TODO
else:
# 显示箴言部分
logger.console.print(
"[#121110 on #F0F2F4]{}".format(random.choice(myWords)),
style="#121110 on #F0F2F4",
justify="center",
)
style_ = "#121110 on #F0F2F4"
# 显示箴言部分
logger.console.print(
"[{}]{}".format(style_, random.choice(yanlun_texts)),
style=style_,
justify="center",
)
del style_
# prt(f"{_('LangChd')}{_(':')}{_(currentLang)}")
@ -171,7 +168,7 @@ while True:
def is_in_bdx_mcpack(sth: str):
return isin(
sth,
sth.lower(),
{
1: ("bdx", "1", "币帝查", "币帝·艾克斯", "", ""),
0: ("mcpack", "0", "唉姆西·派克", "", ""),
@ -180,19 +177,25 @@ def is_in_bdx_mcpack(sth: str):
)
def is_in_player(sth: str, in_ok: tuple = (0,1,2)):
def is_in_player(sth: str, in_ok: tuple = (0, 1, 2)):
return isin(
sth,
sth.lower(),
dict(
[
(i, v)
for i, v in [
(0,
("delay", "0", "延迟", "帝蕾"),),
(1,
("score", "1", "计分板", "积分", "积分板", "计分", "斯阔尔"),),
(2,
("repeater", "2", "中继器", "瑞皮特"),),
(
0,
("delay", "0", "延迟", "帝蕾"),
),
(
1,
("score", "1", "计分板", "积分", "积分板", "计分", "斯阔尔"),
),
(
2,
("repeater", "2", "中继器", "瑞皮特"),
),
]
if i in in_ok
]
@ -201,32 +204,26 @@ def is_in_player(sth: str, in_ok: tuple = (0,1,2)):
output_file_format = format_ipt(
"输出文件类型 (mcpack/0|bdx/1)",
"输出文件类型 (mcpack/0|bdx/1|mcstructure/2)",
is_in_bdx_mcpack,
"输入内容有误,请重新输入。",
)[1]
if output_file_format == 0:
if output_file_format == 1:
player_format = format_ipt(
"播放器类型 (延迟/0|计分板/1|中继器/2)",
is_in_player,
"输入内容有误,请重新输入。",
)[1]
elif output_file_format == 1:
player_format = format_ipt(
"播放器类型 (延迟/0|计分板/1)",
"播放器类型 (延迟/0|计分板/1)",
lambda a: is_in_player(a, (0, 1)),
"输入内容有误,请重新输入。",
)[1]
else:
player_format = format_ipt(
"播放器类型 (延迟/0|中继器/2)",
lambda a: is_in_player(a, (0, 2)),
"播放器类型 (延迟/0|计分板/1|中继器/2)",
is_in_player,
"输入内容有误,请重新输入。",
)[1]
old_exe_enabled = not format_ipt(
"启用版代行指令 (否/0|是/1)",
old_exe_enabled = format_ipt(
"启用版代行指令 (否/0|是/1)",
bool_str,
"输入内容格式错误,应为 是/1/真/t/y 或 否/0/假/f/n",
)[1]
@ -242,17 +239,21 @@ else:
prompts = []
# 提示语 检测函数 错误提示语
for args in [
(
"音量大小 (0,1]",
float_str,
),
(
"速度倍率 (0,+∞)",
float_str,
),
(
"自动生成进度条 (否/0|是/1)",
bool_str,
"最小音量 (0,1]",
float_str,
),
(
(
"自动生成进度条 (否/0|是/1)",
bool_str,
)
if output_file_format != 2
else ()
),
(
(
@ -281,7 +282,7 @@ else:
if output_file_format == 1
else (
(
"结构延展方向x+|z+|x-|z-",
"结构延展方向 (x+|z+|x-|z-)",
lambda a: isin(
a,
{
@ -298,16 +299,16 @@ else:
),
(
(
"结构生成最大高度 (0,+∞)",
int_str,
"基础底部方块 (例concrete)",
str,
)
if player_format == 0
if (player_format == 2 and output_file_format == 2)
else (
(
"基础空白方块concrete",
str,
"结构生成最大高度 (0,+∞)",
int_str,
)
if (player_format == 2 and output_file_format == 2)
if player_format == 0 or output_file_format != 0
else ()
)
),
@ -319,22 +320,26 @@ else:
)[1]
)
if prompts[2]:
if output_file_format != 2 and prompts[2]:
style = DEFAULT_PROGRESSBAR_STYLE
costom_pgb_enabled = format_ipt(
"自定义进度条样式 (否/0|是/1)",
bool_str,
"输入内容格式错误,应为 是/1/真/t/y 或 否/0/假/f/n",
)[1]
if costom_pgb_enabled:
style = ipt("基本样式组 (回车默认)")
if not style:
style = DEFAULT_PROGRESSBAR_STYLE[0]
yet_part = ipt("未播放样式 (回车默认)")
if not yet_part:
yet_part = DEFAULT_PROGRESSBAR_STYLE[1][1]
done_part = ipt("已播放样式 (回车默认)")
if not done_part:
done_part = DEFAULT_PROGRESSBAR_STYLE[1][0]
base_style = ipt("基本样式组 (留空默认)")
if base_style:
style.set_base_style(base_style)
yet_part = ipt("未播放样式 (留空默认)")
if yet_part:
style.set_to_play_style(yet_part)
done_part = ipt("已播放样式 (留空默认)")
if done_part:
style.set_played_style(done_part)
else:
style = None
if output_file_format == 0:
if player_format == 1:
@ -344,8 +349,8 @@ if output_file_format == 0:
elif player_format == 2:
cvt_method = to_addon_pack_in_repeater
elif output_file_format == 2:
# if player_format == 1:
# cvt_method = to_mcstructure_file_in_score
if player_format == 1:
cvt_method = to_mcstructure_file_in_score
if player_format == 0:
cvt_method = to_mcstructure_file_in_delay
elif player_format == 2:
@ -355,36 +360,37 @@ elif output_file_format == 2:
for singleMidi in midis:
prt("\n" f"正在处理 {singleMidi}")
cvt_mid = Musicreater.MidiConvert.from_midi_file(
singleMidi, old_exe_format=old_exe_enabled
)
cvt_cfg = ConvertConfig(
out_path,
*prompts[:2],
progressbar=(
((style, (done_part, yet_part)) if costom_pgb_enabled else True) # type: ignore
if prompts[2]
else False
),
midi_file_path=singleMidi,
play_speed=prompts[0],
old_exe_format=old_exe_enabled,
min_volume=prompts[1],
)
conversion_result = (
(cvt_method(cvt_mid, cvt_cfg, *prompts[3:])) # type: ignore
(cvt_method(cvt_mid, out_path, style, *prompts[3:])) # type: ignore
if output_file_format == 0
else (
(
to_BDX_file_in_score(cvt_mid, cvt_cfg, *prompts[3:])
to_BDX_file_in_score(cvt_mid, out_path, style, *prompts[3:])
if player_format == 1
else to_BDX_file_in_delay(cvt_mid, cvt_cfg, *prompts[3:])
else to_BDX_file_in_delay(cvt_mid, out_path, style, *prompts[3:])
)
if output_file_format == 1
else (cvt_method(cvt_mid, cvt_cfg, *prompts[3:])) # type: ignore
else (cvt_method(cvt_mid, out_path, *prompts[2:]))
)
)
prt(
f" 结构大小:{conversion_result[0]},播放刻数:{conversion_result[1]}"
if output_file_format == 2
else f" 指令总长:{conversion_result[0]},播放刻数:{conversion_result[1]}{f''',结构大小:{conversion_result[2]},末点坐标:{conversion_result[3]}''' if output_file_format == 1 else ''}" # type: ignore
"\t{}{},播放刻数:{}{}".format(
"结构大小" if output_file_format == 2 else "指令总长",
conversion_result[0],
conversion_result[1],
(
",结构大小:{},末点坐标:{}".format(*conversion_result[2:])
if output_file_format == 1
else ""
),
)
)
exitSth = ipt("结束。换行以退出程序。")