优化example结构,支持mcstructure的计分板播放

This commit is contained in:
2024-02-03 16:54:43 +08:00
parent b0bdb7b445
commit 041c64ff65
37 changed files with 380 additions and 152 deletions

View File

@ -5,8 +5,8 @@
Musicreater(音·创)
A free open source library used for convert midi file into formats that is suitable for **Minecraft**.
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory
@ -17,8 +17,8 @@ Terms & Conditions: License.md in the root directory
# 若需转载或借鉴 许可声明请查看仓库目录下的 License.md
__version__ = "1.7.2.1"
__vername__ = "修复指令错误问题"
__version__ = "1.7.3"
__vername__ = "功能结构化"
__author__ = (
("金羿", "Eilles Wan"),
("诸葛亮与八卦阵", "bgArray"),

View File

@ -5,8 +5,8 @@
"""
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -5,8 +5,8 @@
"""
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -5,8 +5,8 @@
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -22,8 +22,8 @@
Musicreater (音·创)
A free open source library used for convert midi file into formats that is suitable for **Minecraft**.
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 ../License.md
Terms & Conditions: ../License.md

View File

@ -7,8 +7,8 @@
Musicreater (音·创)
A free open source library used for convert midi file into formats that is suitable for **Minecraft**.
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory
@ -724,7 +724,7 @@ class MidiConvert:
command_channels.append(this_channel)
self.music_tick_num = max_score
return (command_channels, command_amount, max_score)
return command_channels, command_amount, max_score
def to_command_list_in_delay(
self,

View File

@ -2,8 +2,8 @@
"""
存放非音·创本体的附加内容(插件?)
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory
@ -15,8 +15,57 @@ Terms & Conditions: License.md in the root directory
__all__ = [
# 通用
"ConvertConfig",
"bottem_side_length_of_smallest_square_bottom_box",
# 打包
"compress_zipfile",
"behavior_mcpack_manifest",
# MCSTRUCTURE 函数
"antiaxis",
"forward_IER",
"command_statevalue",
"form_note_block_in_NBT_struct",
"form_repeater_in_NBT_struct",
"form_command_block_in_NBT_struct",
"commands_to_structure",
"commands_to_redstone_delay_structure",
# MCSTRUCTURE 常量
"AXIS_PARTICULAR_VALUE",
"COMPABILITY_VERSION_117",
"COMPABILITY_VERSION_119",
# BDX 函数
"bdx_move",
"form_command_block_in_BDX_bytes",
"commands_to_BDX_bytes",
# BDX 常量
"BDX_MOVE_KEY",
]
__author__ = (("金羿", "Eilles Wan"), ("诸葛亮与八卦阵", "bgArray"))
from .main import *
from .main import ConvertConfig
from .archive import compress_zipfile, behavior_mcpack_manifest
from .bdx import (
BDX_MOVE_KEY,
bdx_move,
form_command_block_in_BDX_bytes,
commands_to_BDX_bytes,
)
from .common import bottem_side_length_of_smallest_square_bottom_box
from .mcstructure import (
antiaxis,
forward_IER,
AXIS_PARTICULAR_VALUE,
COMPABILITY_VERSION_119,
COMPABILITY_VERSION_117,
command_statevalue,
form_note_block_in_NBT_struct,
form_repeater_in_NBT_struct,
form_command_block_in_NBT_struct,
commands_to_structure,
commands_to_redstone_delay_structure,
)

View File

@ -2,8 +2,8 @@
"""
用以生成附加包的附加功能
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -5,8 +5,8 @@
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -4,8 +4,8 @@
"""
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory
@ -21,7 +21,7 @@ from ..constants import x, y, z
from ..subclass import SingleCommand
from .common import bottem_side_length_of_smallest_square_bottom_box
bdx_key = {
BDX_MOVE_KEY = {
"x": [b"\x0f", b"\x0e", b"\x1c", b"\x14", b"\x15"],
"y": [b"\x11", b"\x10", b"\x1d", b"\x16", b"\x17"],
"z": [b"\x13", b"\x12", b"\x1e", b"\x18", b"\x19"],
@ -34,21 +34,18 @@ def bdx_move(axis: str, value: int):
if value == 0:
return b""
if abs(value) == 1:
return bdx_key[axis][0 if value == -1 else 1]
return BDX_MOVE_KEY[axis][0 if value == -1 else 1]
pointer = sum(
[
1 if i else 0
for i in (
value != -1,
value < -1 or value > 1,
value < -128 or value > 127,
value < -32768 or value > 32767,
)
value != -1,
value < -1 or value > 1,
value < -128 or value > 127,
value < -32768 or value > 32767,
]
)
return bdx_key[axis][pointer] + value.to_bytes(
return BDX_MOVE_KEY[axis][pointer] + value.to_bytes(
2 ** (pointer - 2), "big", signed=True
)
@ -198,13 +195,13 @@ def commands_to_BDX_bytes(
):
now_z -= 1 if z_forward else -1
z_forward = not z_forward
_bytes += bdx_key[x][1]
_bytes += BDX_MOVE_KEY[x][1]
now_x += 1
else:
_bytes += bdx_key[z][int(z_forward)]
_bytes += BDX_MOVE_KEY[z][int(z_forward)]
else:
_bytes += bdx_key[y][int(y_forward)]
_bytes += BDX_MOVE_KEY[y][int(y_forward)]
return (
_bytes,

View File

@ -2,8 +2,8 @@
"""
用以生成BDX结构文件的附加功能
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -4,8 +4,8 @@
"""
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -4,8 +4,8 @@
"""
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -2,8 +2,8 @@
"""
用以生成单个mcstructure文件的附加功能
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory
@ -17,7 +17,8 @@ Terms & Conditions: License.md in the root directory
__all__ = [
"to_mcstructure_file_in_delay",
"to_mcstructure_file_in_repeater",
"to_mcstructure_file_in_score",
]
__author__ = (("金羿", "Eilles Wan"),)
from .main import to_mcstructure_file_in_delay, to_mcstructure_file_in_repeater
from .main import to_mcstructure_file_in_delay, to_mcstructure_file_in_repeater, to_mcstructure_file_in_score

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory
@ -14,9 +14,10 @@ Terms & Conditions: License.md in the root directory
import os
from typing import Literal
from ...exceptions import CommandFormatError
# from ...exceptions import CommandFormatError
from ...main import MidiConvert
from ..main import ConvertConfig
from ...subclass import SingleCommand
from ..mcstructure import (
COMPABILITY_VERSION_117,
COMPABILITY_VERSION_119,
@ -47,7 +48,7 @@ def to_mcstructure_file_in_delay(
Returns
-------
tuple[tuple[int,]结构大小, int音乐总延迟]
tuple[tuple[int,int,int]结构大小, int音乐总延迟]
"""
compability_ver = (
@ -80,6 +81,78 @@ def to_mcstructure_file_in_delay(
return size, max_delay
def to_mcstructure_file_in_score(
midi_cvt: MidiConvert,
data_cfg: ConvertConfig,
scoreboard_name: str = "mscplay",
auto_reset: bool = False,
max_height: int = 64,
):
"""
将midi以延迟播放器形式转换为mcstructure结构文件
Parameters
----------
midi_cvt: MidiConvert 对象
用于转换的MidiConvert对象
data_cfg: ConvertConfig 对象
部分转换通用参数
scoreboard_name: str
我的世界的计分板名称
auto_reset: bool
是否自动重置计分板
max_height: int
生成结构最大高度
Returns
-------
tuple[tuple[int,int,int]结构大小, int音乐总延迟, int指令数量
"""
compability_ver = (
COMPABILITY_VERSION_117
if midi_cvt.enable_old_exe_format
else COMPABILITY_VERSION_119
)
cmd_list, cmd_count, max_delay = midi_cvt.to_command_list_in_score(
scoreboard_name,
data_cfg.volume_ratio,
data_cfg.speed_multiplier,
)
if not os.path.exists(data_cfg.dist_path):
os.makedirs(data_cfg.dist_path)
struct, size, end_pos = commands_to_structure(
midi_cvt.music_command_list+(
[
SingleCommand(
command="scoreboard players reset @a[scores={"
+ scoreboard_name
+ "="
+ str(max_delay + 20)
+ "}] "
+ scoreboard_name,
annotation="自动重置计分板",
)
]
if auto_reset
else []
), max_height - 1, compability_version_=compability_ver
)
with open(
os.path.abspath(
os.path.join(data_cfg.dist_path, f"{midi_cvt.midi_music_name}.mcstructure")
),
"wb+",
) as f:
struct.dump(f)
return size, max_delay, cmd_count
def to_mcstructure_file_in_repeater(
midi_cvt: MidiConvert,
data_cfg: ConvertConfig,
@ -105,7 +178,7 @@ def to_mcstructure_file_in_repeater(
Returns
-------
tuple[tuple[int,]结构大小, int音乐总延迟]
tuple[tuple[int,int,int]结构大小, int音乐总延迟]
"""
compability_ver = (

View File

@ -4,8 +4,8 @@
"""
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -4,8 +4,8 @@
"""
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -4,8 +4,8 @@
"""
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -2,8 +2,8 @@
"""
用以生成Schematic结构的附加功能
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -4,8 +4,8 @@
"""
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -2,8 +2,8 @@
"""
用以启动WebSocket服务器播放的附加功能
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -4,8 +4,8 @@
"""
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -5,8 +5,8 @@
"""
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -5,8 +5,8 @@
"""
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory

View File

@ -4,8 +4,8 @@
"""
"""
版权所有 © 2023 音·创 开发者
Copyright © 2023 all the developers of Musicreater
版权所有 © 2024 音·创 开发者
Copyright © 2024 all the developers of Musicreater
开源相关声明请见 仓库根目录下的 License.md
Terms & Conditions: License.md in the root directory