修复类型定义的重复问题-2

This commit is contained in:
EillesWan 2024-01-23 18:14:41 +08:00
parent d7e3c62deb
commit d3b637a0c8
5 changed files with 104 additions and 68 deletions

View File

@ -16,7 +16,7 @@ Terms & Conditions: License.md in the root directory
# Email TriM-Organization@hotmail.com # Email TriM-Organization@hotmail.com
# 若需转载或借鉴 许可声明请查看仓库目录下的 License.md # 若需转载或借鉴 许可声明请查看仓库目录下的 License.md
from typing import Dict, List, Tuple from .types import Dict, List, Tuple, MidiInstrumentTableType, MidiNoteNameTableType
x = "x" x = "x"
""" """
@ -33,13 +33,6 @@ z = "z"
z z
""" """
DEFAULT_PROGRESSBAR_STYLE = (
r"%%N [ %%s/%^s %%% __________ %%t|%^t ]",
("§e=§r", "§7=§r"),
)
"""
默认的进度条样式组
"""
# Midi用对照表 # Midi用对照表

View File

@ -28,6 +28,8 @@ Terms & Conditions: License.md in the root directory
import math import math
import os import os
import mido
from .constants import * from .constants import *
from .exceptions import * from .exceptions import *
from .subclass import * from .subclass import *
@ -68,6 +70,12 @@ tick * tempo / 1000000.0 / ticks_per_beat * 一秒多少游戏刻
""" """
VoidMido = Union[mido.MidiFile, None] # void mido
"""
空Midi类类型
"""
@dataclass(init=False) @dataclass(init=False)
class MidiConvert: class MidiConvert:
""" """
@ -203,7 +211,7 @@ class MidiConvert:
self, self,
max_score: int, max_score: int,
scoreboard_name: str, scoreboard_name: str,
progressbar_style: ProgressBarStyleType = DEFAULT_PROGRESSBAR_STYLE, progressbar_style: ProgressBarStyle = DEFAULT_PROGRESSBAR_STYLE,
) -> List[SingleCommand]: ) -> List[SingleCommand]:
""" """
生成进度条 生成进度条
@ -223,7 +231,7 @@ class MidiConvert:
------- -------
list[SingleCommand,] list[SingleCommand,]
""" """
pgs_style = progressbar_style[0] pgs_style = progressbar_style.base_style
"""用于被替换的进度条原始样式""" """用于被替换的进度条原始样式"""
""" """
@ -253,7 +261,7 @@ class MidiConvert:
result.append( result.append(
SingleCommand( SingleCommand(
'scoreboard objectives add {}PercT dummy "百分比计算"'.format(sbn_pc), 'scoreboard objectives add {}PercT dummy "百分比计算"'.format(sbn_pc),
annotation="新增临时计算用计分板(百分比)", annotation="新增临时百分比变量",
) )
) )
result.append( result.append(
@ -264,7 +272,7 @@ class MidiConvert:
+ "scoreboard players set MaxScore {} {}".format( + "scoreboard players set MaxScore {} {}".format(
scoreboard_name, max_score scoreboard_name, max_score
), ),
annotation="设定此音乐最大计分", annotation="设定音乐最大延迟分数",
) )
) )
result.append( result.append(
@ -284,7 +292,7 @@ class MidiConvert:
+ "scoreboard players operation @s {} = @s {}".format( + "scoreboard players operation @s {} = @s {}".format(
sbn_pc + "PercT", scoreboard_name sbn_pc + "PercT", scoreboard_name
), ),
annotation="为临时变量赋值", annotation="赋值临时百分比",
) )
) )
result.append( result.append(
@ -295,7 +303,7 @@ class MidiConvert:
+ "scoreboard players operation @s {} *= n100 {}".format( + "scoreboard players operation @s {} *= n100 {}".format(
sbn_pc + "PercT", scoreboard_name sbn_pc + "PercT", scoreboard_name
), ),
annotation="改变临时变量的单位为百分比(扩大精度)", annotation="转换临时百分比之单位至%(扩大精度)",
) )
) )
result.append( result.append(
@ -306,7 +314,7 @@ class MidiConvert:
+ "scoreboard players operation @s {} /= MaxScore {}".format( + "scoreboard players operation @s {} /= MaxScore {}".format(
sbn_pc + "PercT", scoreboard_name sbn_pc + "PercT", scoreboard_name
), ),
annotation="使用临时变量计算百分比", annotation="计算百分比",
) )
) )
@ -318,13 +326,13 @@ class MidiConvert:
result.append( result.append(
SingleCommand( SingleCommand(
'scoreboard objectives add {}TMinT dummy "时间计算:分"'.format(sbn_pc), 'scoreboard objectives add {}TMinT dummy "时间计算:分"'.format(sbn_pc),
annotation="新增临时计算计分板(分)", annotation="新增临时分变量",
) )
) )
result.append( result.append(
SingleCommand( SingleCommand(
'scoreboard objectives add {}TSecT dummy "时间计算:秒"'.format(sbn_pc), 'scoreboard objectives add {}TSecT dummy "时间计算:秒"'.format(sbn_pc),
annotation="新增临时计算计分板(秒)", annotation="新增临时秒变量",
) )
) )
result.append( result.append(
@ -354,7 +362,7 @@ class MidiConvert:
+ "scoreboard players operation @s {} = @s {}".format( + "scoreboard players operation @s {} = @s {}".format(
sbn_pc + "TMinT", scoreboard_name sbn_pc + "TMinT", scoreboard_name
), ),
annotation="为临时变量(分)赋值", annotation="赋值临时分",
) )
) )
result.append( result.append(
@ -365,7 +373,7 @@ class MidiConvert:
+ "scoreboard players operation @s {} /= n20 {}".format( + "scoreboard players operation @s {} /= n20 {}".format(
sbn_pc + "TMinT", scoreboard_name sbn_pc + "TMinT", scoreboard_name
), ),
annotation="将临时变量转换单位为秒(缩减精度)", annotation="转换临时分之单位为秒(缩减精度)",
) )
) )
result.append( result.append(
@ -376,7 +384,7 @@ class MidiConvert:
+ "scoreboard players operation @s {} = @s {}".format( + "scoreboard players operation @s {} = @s {}".format(
sbn_pc + "TSecT", sbn_pc + "TMinT" sbn_pc + "TSecT", sbn_pc + "TMinT"
), ),
annotation="为临时变量(秒)赋值", annotation="赋值临时秒",
) )
) )
@ -388,7 +396,7 @@ class MidiConvert:
+ "scoreboard players operation @s {} /= n60 {}".format( + "scoreboard players operation @s {} /= n60 {}".format(
sbn_pc + "TMinT", scoreboard_name sbn_pc + "TMinT", scoreboard_name
), ),
annotation="将临时变量(分)转换单位为分(缩减精度)", annotation="转换临时分之单位为分(缩减精度)",
) )
) )
@ -400,42 +408,35 @@ class MidiConvert:
+ "scoreboard players operation @s {} %= n60 {}".format( + "scoreboard players operation @s {} %= n60 {}".format(
sbn_pc + "TSecT", scoreboard_name sbn_pc + "TSecT", scoreboard_name
), ),
annotation="将临时变量(秒)确定下来(框定精度区间)", annotation="确定临时秒(框定精度区间)",
) )
) )
for i in range(pgs_style.count("_")): for i in range(pgs_style.count("_")):
npg_stl = ( npg_stl = (
pgs_style.replace("_", progressbar_style[1][0], i + 1) pgs_style.replace("_", progressbar_style.played_style, i + 1)
.replace("_", progressbar_style[1][1]) .replace("_", progressbar_style.to_play_style)
.replace(r"%%N", self.midi_music_name) .replace(r"%%N", self.midi_music_name)
if r"%%N" in pgs_style .replace(
else pgs_style.replace("_", progressbar_style[1][0], i + 1).replace(
"_", progressbar_style[1][1]
)
)
if r"%%s" in npg_stl:
npg_stl = npg_stl.replace(
r"%%s", r"%%s",
'"},{"score":{"name":"*","objective":"' '"},{"score":{"name":"*","objective":"'
+ scoreboard_name + scoreboard_name
+ '"}},{"text":"', + '"}},{"text":"',
) )
if r"%%%" in npg_stl: .replace(
npg_stl = npg_stl.replace(
r"%%%", r"%%%",
r'"},{"score":{"name":"*","objective":"' r'"},{"score":{"name":"*","objective":"'
+ sbn_pc + sbn_pc
+ r'PercT"}},{"text":"%', + r'PercT"}},{"text":"%',
) )
if r"%%t" in npg_stl: .replace(
npg_stl = npg_stl.replace(
r"%%t", r"%%t",
r'"},{"score":{"name":"*","objective":"{-}TMinT"}},{"text":":"},' r'"},{"score":{"name":"*","objective":"{-}TMinT"}},{"text":":"},'
r'{"score":{"name":"*","objective":"{-}TSecT"}},{"text":"'.replace( r'{"score":{"name":"*","objective":"{-}TSecT"}},{"text":"'.replace(
r"{-}", sbn_pc r"{-}", sbn_pc
), ),
) )
)
result.append( result.append(
SingleCommand( SingleCommand(
self.execute_cmd_head.format( self.execute_cmd_head.format(
@ -455,20 +456,20 @@ class MidiConvert:
result.append( result.append(
SingleCommand( SingleCommand(
"scoreboard objectives remove {}PercT".format(sbn_pc), "scoreboard objectives remove {}PercT".format(sbn_pc),
annotation="移除临时计算计分板(百分比)", annotation="移除临时百分比变量",
) )
) )
if r"%%t" in pgs_style: if r"%%t" in pgs_style:
result.append( result.append(
SingleCommand( SingleCommand(
"scoreboard objectives remove {}TMinT".format(sbn_pc), "scoreboard objectives remove {}TMinT".format(sbn_pc),
annotation="移除临时计算计分板(分)", annotation="移除临时分变量",
) )
) )
result.append( result.append(
SingleCommand( SingleCommand(
"scoreboard objectives remove {}TSecT".format(sbn_pc), "scoreboard objectives remove {}TSecT".format(sbn_pc),
annotation="移除临时计算计分板(秒)", annotation="移除临时秒变量",
) )
) )

View File

@ -18,7 +18,8 @@ Terms & Conditions: License.md in the root directory
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional, Any from typing import Any
from .types import Optional, Any, List, Mapping
from .constants import MC_PERCUSSION_INSTRUMENT_LIST from .constants import MC_PERCUSSION_INSTRUMENT_LIST
@ -339,3 +340,58 @@ class SingleNoteBox:
if not isinstance(other, self.__class__): if not isinstance(other, self.__class__):
return False return False
return self.__str__() == other.__str__() return self.__str__() == other.__str__()
@dataclass(init=False)
class ProgressBarStyle:
"""进度条样式类"""
base_style: str
"""基础样式"""
to_play_style: str
"""未播放之样式"""
played_style: str
"""已播放之样式"""
def __init__(self, base_s: str, to_play_s: str, played_s: str):
"""用于存储进度条样式的类
:param base_s 基础样式用以定义进度条整体
:param to_play_s 进度条样式尚未播放的样子
:param played_s 已经播放的样子"""
self.base_style = base_s
self.to_play_style = to_play_s
self.played_style = played_s
def set_base_style(self, value: str):
"""设置基础样式"""
self.base_style = value
def set_to_play_style(self, value: str):
"""设置未播放之样式"""
self.to_play_style = value
def set_played_style(self, value: str):
"""设置已播放之样式"""
self.played_style = value
DEFAULT_PROGRESSBAR_STYLE = ProgressBarStyle(
r"%%N [ %%s/%^s %%% __________ %%t|%^t ]",
r"§e=§r",
r"§7=§r",
)
"""
默认的进度条样式
"""
NoteChannelType = Mapping[
int,
List[SingleNote,],
]
"""
频道信息类型
Dict[int,Dict[int,List[SingleNote,],],]
"""

View File

@ -18,9 +18,6 @@ Terms & Conditions: License.md in the root directory
from typing import Any, Dict, List, Literal, Optional, Tuple, Union, Iterable, Sequence, Mapping, Callable from typing import Any, Dict, List, Literal, Optional, Tuple, Union, Iterable, Sequence, Mapping, Callable
import mido
from .subclass import SingleNote
MidiNoteNameTableType = Mapping[int, Tuple[str, ...]] MidiNoteNameTableType = Mapping[int, Tuple[str, ...]]
""" """
@ -34,26 +31,7 @@ Midi乐器对照表类型
FittingFunctionType = Callable[[float], float] FittingFunctionType = Callable[[float], float]
ProgressBarStyleType = Tuple[str, Tuple[str, str]]
"""
进度条样式类型
"""
VoidMido = Union[mido.MidiFile, None] # void mido
"""
空Midi类类型
"""
NoteChannelType = Dict[
int,
List[SingleNote,],
]
"""
频道信息类型
Dict[int,Dict[int,List[SingleNote,],],]
"""
ChannelType = Dict[ ChannelType = Dict[

View File

@ -173,7 +173,7 @@
|`InstID`|声音效果ID|不同的声音ID可以对应不同的乐器详见转换[乐器对照表](./%E8%BD%AC%E6%8D%A2%E4%B9%90%E5%99%A8%E5%AF%B9%E7%85%A7%E8%A1%A8.md)| |`InstID`|声音效果ID|不同的声音ID可以对应不同的乐器详见转换[乐器对照表](./%E8%BD%AC%E6%8D%A2%E4%B9%90%E5%99%A8%E5%AF%B9%E7%85%A7%E8%A1%A8.md)|
|`Ht`|播放点对玩家的距离|通过距离来表达声音的响度 $S$ 表示此参数`Ht`以Vol表示音量百分比则计算公式为 $S = \frac{1}{Vol}-1$ | |`Ht`|播放点对玩家的距离|通过距离来表达声音的响度 $S$ 表示此参数`Ht`以Vol表示音量百分比则计算公式为 $S = \frac{1}{Vol}-1$ |
|`Vlct`|原生我的世界中规定的播放力度|这个参数是一个谜一样的存在似乎它的值毫不重要因为无论这个值是多少我们听起来都差不多当此音符所在MIDI通道为第一通道则这个值为 $0.7$ 倍MIDI指定力度其他则为 $0.9$ | |`Vlct`|原生我的世界中规定的播放力度|这个参数是一个谜一样的存在似乎它的值毫不重要因为无论这个值是多少我们听起来都差不多当此音符所在MIDI通道为第一通道则这个值为 $0.7$ 倍MIDI指定力度其他则为 $0.9$ |
|`Ptc`|音符的音高|这是决定音调的参数 $P$ 表示此参数 $n$ 表示其在MIDI中的编号 $x$ 表示一定的音调偏移则计算公式为 $P = 2^\frac{n-60-x}{12}$之所以存在音调偏移是因为在我的世界不同的[乐器存在不同的音域](https://minecraft.fandom.com/zh/wiki/%E9%9F%B3%E7%AC%A6%E7%9B%92#%E4%B9%90%E5%99%A8),我们通过音调偏移来进行调整。| |`Ptc`|音符的音高|这是决定音调的参数 $P$ 表示此参数 $n$ 表示其在MIDI中的编号 $x$ 表示一定的音调偏移则计算公式为 $P = 2^\frac{n-60-x}{12}$之所以存在音调偏移是因为在我的世界不同的[乐器存在不同的音域](https://zh.minecraft.wiki/wiki/%E9%9F%B3%E7%AC%A6%E7%9B%92#%E4%B9%90%E5%99%A8),我们通过音调偏移来进行调整。|
### 播放器内容 ### 播放器内容
@ -285,23 +285,31 @@
表示进度条占位的 `_` 是用来标识你的进度条的也就是可变部分的唯一的图形部分 表示进度条占位的 `_` 是用来标识你的进度条的也就是可变部分的唯一的图形部分
**样式定义字符串**的样例如下这也是默认进度条的样式 **样式定义字符串基础样式**的样例如下这也是默认进度条的基础样式
` %%N [ %%s/%^s %%% __________ %%t|%^t]` ``` %%N [ %%s/%^s %%% __________ %%t|%^t]```
这是单独一行的进度条当然你也可以制作多行的如果是一行的输出时所使用的指令便是 `title`而如果是多行的话输出就会用 `titleraw` 作为进度条字幕 这是单独一行的进度条当然你也可以制作多行的如果是一行的输出时所使用的指令便是 `title`而如果是多行的话输出就会用 `titleraw` 作为进度条字幕
哦对了上面的只不过是样式定义同时还需要定义的是可变图形的部分也就是进度条上那个真正的 哦对了上面的只不过是样式定义同时还需要定义的是可变图形的部分也就是进度条上那个真正的
对于这个我们就采用了固定参数的方法对于一个进度条无非就是已经播放过的没播放过的两种形态所以使用一个元组来传入这两个参数就是最简单的了元组的格式也很简单`(str: 播放过的部分长啥样, str: 没播放过的部分长啥样)` 例如我们默认的进度的定义是这样的 对于这个我们就采用了固定参数的方法对于一个进度条无非就是已经播放过的没播放过的两种形态例如我们默认的进度**可变样式**的定义是这样的
`('§e=§r', '§7=§r')` **可变样式甲已播放样式**`'§e=§r'`
综合起来把这些参数传给函数需要一个参数整合你猜用的啥啊对对对我用的还是元组 **可变样式乙未播放样式**`'§7=§r'`
综合起来把这些参数传给函数需要一个参数整合使用位于 `Musicreater/subclass.py` 下的 `ProgressBarStyle` 类进行定义
我们的默认定义参数如下 我们的默认定义参数如下
`(r'%%N [ %%s/%^s %%% __________ %%t|%^t]',('§e=§r', '§7=§r'))` ```python
DEFAULT_PROGRESSBAR_STYLE = ProgressBarStyle(
r"%%N [ %%s/%^s %%% __________ %%t|%^t ]",
r"§e=§r",
r"§7=§r",
)
```
*为了避免生成错误请尽量避免使用标识符作为定义样式字符串的其他部分* *为了避免生成错误请尽量避免使用标识符作为定义样式字符串的其他部分*