新年第一次更新

This commit is contained in:
bgArray
2022-02-01 00:07:22 +08:00
parent 81272a1166
commit 9f8694ef14
22 changed files with 499 additions and 342 deletions

View File

@ -92,15 +92,6 @@ def funSplit(bigFile, maxCmdLen: int = 10000):
return parts
# 注意播放器应该为个人独立播放器此处bug需要修改
def makeFuncFiles(musicset, path='./'):
"""在指定目录下生成函数文件"""
@ -148,18 +139,48 @@ def makeFuncFiles(musicset, path='./'):
log("完成============================")
def makeFunDir(musicset, path='./'):
"""在指定目录下生成函数包文件夹"""
import os
import uuid
log("=============================生成函数包文件夹")
# note,packname="Ryoun",FileName="Music",EntityName_='music_support',ScoreboardName_='music_support',
# MusicTitle_='Noname',PlayerSelect_='',Repeat_=False,Instrument_='harp'
try:
os.makedirs(path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset'][
'PackName'] + "/functions")
log("已创建目录" + path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset'][
'PackName'] + "/functions")
except FileExistsError:
log("目录已有无需创建")
pass
# 判断文件皆存在
if not (os.path.exists(
path + musicset['mainset']['PackName'] + "Pack/world_behavior_packs.json") and os.path.exists(
path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset'][
'PackName'] + "/manifest.json")):
log("创建manifest.json以及world_behavior_packs.json")
behaviorUuid = uuid.uuid4()
with open(path + musicset['mainset']['PackName'] + "Pack/world_behavior_packs.json", "w") as f:
f.write("[\n {\"pack_id\": \"" + str(behaviorUuid) + "\",\n \"version\": [ 0, 0, 1 ]}\n]")
p = path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset']['PackName'] + \
"/manifest.json"
with open(p, "w") as f:
f.write("{\n \"format_version\": 1,\n \"header\": {\n \"description\": \"" + musicset['mainset'][
'PackName'] + " Pack : behavior pack\",\n \"version\": [ 0, 0, 1 ],\n \"name\": \"" +
musicset['mainset']['PackName'] + "Pack\",\n \"uuid\": \"" + str(
behaviorUuid) + "\"\n },\n \"modules\": [\n {\n \"description\": \"" + musicset['mainset'][
'PackName'] + " Pack : behavior pack\",\n \"type\": \"data\",\n \"version\":"
" [ 0, 0, 1 ],\n \"uuid\": \"" + str(
uuid.uuid4()) + "\"\n }\n ]\n}")
makeFuncFiles(musicset, path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset'][
'PackName'] + "/functions/")
log("完成============================")
def makeNewFuncFiles(musicset, path='./'):
"""在指定目录下生成函数文件"""
from msctspt.transfer import classList_conversion
from msctspt.transfer import newList_conversion_SinglePlayer
commands = []
starts = []
starts.__len__()
@ -175,17 +196,19 @@ def makeNewFuncFiles(musicset, path='./'):
for i in range(len(musicset['musics'])):
log('写入第' + str(i) + '个数据')
# commands.append("execute @e[name=\"" + musicset['musics'][i]['set']['EntityName'] + "\",scores={" +
# musicset['musics'][i]['set']['ScoreboardName'] + "=1..10}] ~~~ title @a" + musicset['mainset'][
# musicset['musics'][i]['set']['ScoreboardName'] + "=1..10}] ~~~ title @a" + musicset['mainset']
# [
# 'PlayerSelect'] + " title " + musicset['mainset']['MusicTitle'] + "\n")
# commands.append("execute @e[name=\"" + musicset['musics'][i]['set']['EntityName'] + "\",scores={" +
# musicset['musics'][i]['set']['ScoreboardName'] + "=1..10}] ~~~ title @a" + musicset['mainset'][
# musicset['musics'][i]['set']['ScoreboardName'] + "=1..10}] ~~~ title @a" + musicset['mainset']
# [
# 'PlayerSelect'] + " subtitle 本函数乐曲由§b§l凌云§r§3函数音乐创建§r生成\n")
if len(musicset['musics'][i]['notes']) > maxlen:
maxlen = len(musicset['musics'][i]['notes'])
with open(path + musicset['mainset']['MusicTitle'] + '_Part' + str(i) + '.mcfunction', 'w',
encoding='UTF-8') as f:
f.writelines(classList_conversion(musicset['musics'][i]['notes'],
musicset['musics'][i]['set']['ScoreboardName']))
f.writelines(newList_conversion_SinglePlayer(musicset['musics'][i]['notes'],
musicset['musics'][i]['set']['ScoreboardName']))
if musicset['mainset']['IsRepeat']:
log("增加重复语句")
for i in range(len(musicset['musics'])):
@ -245,7 +268,61 @@ def makeNewFunDir(musicset, path='./'):
log("完成============================")
def makeFunDir(musicset, path='./'):
def makeClassFuncFiles(musicset, path='./'):
"""在指定目录下生成函数文件"""
from msctspt.transfer import classList_conversion_SinglePlayer
commands = []
starts = []
starts.__len__()
starts.append("scoreboard objectives add " + musicset['musics'][0]['set']['ScoreboardName'] + " dummy\n")
starts.append("summon armor_stand " + musicset['musics'][0]['set']['EntityName'] + '\n')
starts.append("scoreboard objectives setdisplay sidebar " + musicset['musics'][0]['set']['ScoreboardName'] + '\n')
starts.append("scoreboard players set @e[type=armor_stand, name=\"" + musicset['musics'][0]['set']['EntityName'] +
"\"] " + musicset['musics'][0]['set']['ScoreboardName'] + " 0" + '\n')
log("=========================正在在此处生成文件:" + path)
commands.append("scoreboard players add @e[name=\"" + musicset['musics'][0]['set']['EntityName'] + "\"] " +
musicset['musics'][0]['set']['ScoreboardName'] + " 1\n")
maxlen = -1
for i in range(len(musicset['musics'])):
log('写入第' + str(i) + '个数据')
# commands.append("execute @e[name=\"" + musicset['musics'][i]['set']['EntityName'] + "\",scores={" +
# musicset['musics'][i]['set']['ScoreboardName'] + "=1..10}] ~~~ title @a" + musicset['mainset']
# [
# 'PlayerSelect'] + " title " + musicset['mainset']['MusicTitle'] + "\n")
# commands.append("execute @e[name=\"" + musicset['musics'][i]['set']['EntityName'] + "\",scores={" +
# musicset['musics'][i]['set']['ScoreboardName'] + "=1..10}] ~~~ title @a" + musicset['mainset']
# [
# 'PlayerSelect'] + " subtitle 本函数乐曲由§b§l凌云§r§3函数音乐创建§r生成\n")
if len(musicset['musics'][i]['notes']) > maxlen:
maxlen = len(musicset['musics'][i]['notes'])
with open(path + musicset['mainset']['MusicTitle'] + '_Part' + str(i) + '.mcfunction', 'w',
encoding='UTF-8') as f:
f.writelines(classList_conversion_SinglePlayer(musicset['musics'][i]['notes'],
musicset['musics'][i]['set']['ScoreboardName'],
musicset['musics'][i]['set']['Instrument'],
musicset['mainset']['PlayerSelect'],
True))
if musicset['mainset']['IsRepeat']:
log("增加重复语句")
for i in range(len(musicset['musics'])):
commands.append("execute @e[name=\"" + musicset['musics'][i]['set']['EntityName'] + "\",scores={" +
musicset['musics'][i]['set']['ScoreboardName'] + "=" + str(
(maxlen + 2) * 10) + "}] ~~~ scoreboard players set @e[name=\"" + musicset['musics'][i]['set'][
'EntityName'] + "\"] " + musicset['musics'][i]['set']['ScoreboardName'] + " -1\n")
log("增加版权语句")
commands.append("\n\n# 凌云我的世界开发团队 x 凌云软件开发团队 : W-YI金羿bgArray诸葛亮与八卦阵\n")
starts.append("\n\n# 凌云我的世界开发团队 x 凌云软件开发团队 : W-YI金羿bgArray诸葛亮与八卦阵\n")
log("写入支持文件")
with open(path + musicset['mainset']['MusicTitle'] + '_Support.mcfunction', 'w', encoding='UTF-8') as f:
f.writelines(commands)
log("写入开始文件")
with open(path + 'Start_' + musicset['mainset']['MusicTitle'] + '.mcfunction', 'w', encoding='UTF-8') as f:
f.writelines(starts)
del commands, starts, maxlen
log("完成============================")
def makeClassFunDir(musicset, path='./'):
"""在指定目录下生成函数包文件夹"""
import os
import uuid
@ -265,7 +342,6 @@ def makeFunDir(musicset, path='./'):
path + musicset['mainset']['PackName'] + "Pack/world_behavior_packs.json") and os.path.exists(
path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset'][
'PackName'] + "/manifest.json")):
log("创建manifest.json以及world_behavior_packs.json")
behaviorUuid = uuid.uuid4()
with open(path + musicset['mainset']['PackName'] + "Pack/world_behavior_packs.json", "w") as f:
@ -280,7 +356,7 @@ def makeFunDir(musicset, path='./'):
'PackName'] + " Pack : behavior pack\",\n \"type\": \"data\",\n \"version\":"
" [ 0, 0, 1 ],\n \"uuid\": \"" + str(
uuid.uuid4()) + "\"\n }\n ]\n}")
makeFuncFiles(musicset, path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset'][
makeClassFuncFiles(musicset, path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset'][
'PackName'] + "/functions/")
log("完成============================")

View File

@ -1,6 +1,5 @@
"""音·创 的转换工具库"""
# 诸葛亮与八卦阵帮忙修改语法 日期:---2022年1月19日
# 统计致命三级错误0个警告二级错误4个--未解决1个语法一级错误302个
@ -26,15 +25,8 @@ def hans2pinyin(hans, style=3):
return final
def classList_conversion_SinglePlayer(List: list, ScoreboardName: str, playerSelection: str = '',
isProsess: bool = False) -> list:
def classList_conversion_SinglePlayer(List: list, ScoreboardName: str, Instrument: str, playerSelection: str = '',
isProsess: bool = False) -> list:
from bgArrayLib.compute import round_up
commands = []
length = len(List)
@ -48,11 +40,17 @@ def classList_conversion_SinglePlayer(List: list, ScoreboardName: str, playerSel
if i.instrument > 119:
pass
else:
commands.append(f"execute @a{playerSelection} ~ ~ ~ execute @s[scores={{{ScoreboardName}={str(round_up(i.time_position)).replace('.0', '')}}}] ~ ~{127 - i.velocity} ~ playsound {i.instrument}{i.CD}.{i.pitch} @s ~ ~ ~ 1000 1.0 1000\n")
commands.append(
f"execute @a{playerSelection} ~ ~ ~ execute @s[scores={{{ScoreboardName}="
f"{str(round_up(i.time_position)).replace('.0', '')}}}] ~ ~{127 - i.velocity} "
f"~ playsound {Instrument} @s ~ ~ ~ 1000 {i.pitch} 1000\n")
if isProsess:
commands.append(f"execute @a{playerSelection} ~ ~ ~ execute @s[scores={{{ScoreboardName}={str(round_up(i.time_position)).replace('.0', '')}}}] ~ ~ ~ title @s actionbar §e▶ 播放中: §a{j}/{length} || {int(j / length * 1000) / 10}\n")
commands.append(
f"execute @a{playerSelection} ~ ~ ~ execute @s[scores={{{ScoreboardName}="
f"{str(round_up(i.time_position)).replace('.0', '')}}}] ~ ~ ~ "
f"title @s actionbar §e▶ 播放中: §a{j}/{length} || {int(j / length * 1000) / 10}\n")
j += 1
except :
except:
pass
# a += List[i][1]
# commands.append("\n\n# 凌云我的世界开发团队 x 凌云软件开发团队 : W-YI金羿\n")
@ -60,13 +58,37 @@ def classList_conversion_SinglePlayer(List: list, ScoreboardName: str, playerSel
return commands
def newList_conversion_SinglePlayer(List: list, ScoreboardName: str, playerSelection: str = '',
isProsess: bool = False) -> list:
from bgArrayLib.compute import round_up
commands = []
length = len(List)
j = 1
print(List)
for k in range(len(List)):
i = List[k][0]
print(i)
print(type(i))
try:
if i.instrument > 119:
pass
else:
commands.append(
f"execute @a{playerSelection} ~ ~ ~ execute @s[scores={{{ScoreboardName}="
f"{str(round_up(i.time_position)).replace('.0', '')}}}] ~ ~{127 - i.velocity} "
f"~ playsound {i.instrument}{i.CD}.{i.pitch} @s ~ ~ ~ 1000 1.0 1000\n")
if isProsess:
commands.append(
f"execute @a{playerSelection} ~ ~ ~ execute @s[scores={{{ScoreboardName}="
f"{str(round_up(i.time_position)).replace('.0', '')}}}] ~ ~ ~ "
f"title @s actionbar §e▶ 播放中: §a{j}/{length} || {int(j / length * 1000) / 10}\n")
j += 1
except:
pass
# a += List[i][1]
# commands.append("\n\n# 凌云我的世界开发团队 x 凌云软件开发团队 : W-YI金羿\n")
print(commands)
return commands
def classList_conversion(List: list, ScoreboardName: str, isProsess: bool = False) -> list:
@ -104,25 +126,6 @@ def classList_conversion(List: list, ScoreboardName: str, isProsess: bool = Fals
print(commands)
return commands
def formCmdBlock(direction: Iterable, command: str, particularValue: int, impluse: int = 0, condition: bool = False,
needRedstone: bool = True, tickDelay: int = 0, customName: str = '', lastOutput: str = '',
@ -172,7 +175,7 @@ def formCmdBlock(direction: Iterable, command: str, particularValue: int, implus
是否输出
:return: 指令方块字典结构,如下
'''
"""
'''
:param block: {
"direction": [x: int, y: int, z: int] #方块位置
@ -188,7 +191,7 @@ def formCmdBlock(direction: Iterable, command: str, particularValue: int, implus
"conditional": int, #是否有条件 1 bytes
"needRedstone": int #是否需要红石 1 bytes
}
"""
'''
return {"direction": direction,
"block_name": "command_block",
"particular_value": particularValue,
@ -205,7 +208,7 @@ def formCmdBlock(direction: Iterable, command: str, particularValue: int, implus
def note2bdx(filePath: str, dire: list, Notes: list, ScoreboardName: str, Instrument: str,
PlayerSelect: str = '', isProsess: bool = False, height: int = 200):
PlayerSelect: str = '', isProsess: bool = False, height: int = 200):
"""使用方法同Note2Cmd
:param 参数说明:
filePath: 生成.bdx文件的位置
@ -257,24 +260,8 @@ def note2bdx(filePath: str, dire: list, Notes: list, ScoreboardName: str, Instru
return BdxConverter(filePath, 'Build by RyounMusicreater', blocks)
def music2BDX(filePath: str, direction: Iterable, music: dict, isProsess: bool = False, height: int = 200, isSquare: bool = False):
def music2BDX(filePath: str, direction: Iterable, music: dict, isProsess: bool = False, height: int = 200,
isSquare: bool = False):
"""使用方法同Note2Cmd
:param 参数说明:
filePath: 生成.bdx文件的位置
@ -293,14 +280,18 @@ def music2BDX(filePath: str, direction: Iterable, music: dict, isProsess: bool =
direction = list(direction)
for track in music['musics']:
cmdList = classList_conversion_SinglePlayer(track['notes'],track['set']['ScoreboardName'],music['mainset']['PlayerSelect'],isProsess)
cmdList = classList_conversion_SinglePlayer(track['notes'], track['set']['ScoreboardName'],
music['mainset']['PlayerSelect'], isProsess)
dire = direction
down = False
'''当前是否为向下的阶段?'''
#开头的指令方块
blocks.append(formCmdBlock(dire, f"scoreboard players add @a{music['mainset']['PlayerSelect']} {track['set']['ScoreboardName']} 1", 1, 1))
# 开头的指令方块
blocks.append(formCmdBlock(dire,
f"scoreboard players add @a{music['mainset']['PlayerSelect']} "
f"{track['set']['ScoreboardName']} 1",
1, 1))
dire[1] += 1
blocks.append(formCmdBlock(dire, cmdList.pop(0), 2,needRedstone=False))
blocks.append(formCmdBlock(dire, cmdList.pop(0), 2, needRedstone=False))
dire[1] += 1
# :0 下 无条件
# :1 上 无条件
@ -309,36 +300,24 @@ def music2BDX(filePath: str, direction: Iterable, music: dict, isProsess: bool =
# :4 x轴负方向 无条件
# :5 x轴正方向 无条件
for cmd in cmdList:
blocks.append(formCmdBlock(dire,cmd,5 if (down == False and dire[1] == height+direction[1]) or (down and dire[1] == direction+1) else 0 if down else 1,2,needRedstone=False))
blocks.append(formCmdBlock(dire, cmd, 5 if (down is False and dire[1] == height + direction[1]) or (
down and dire[1] == direction + 1) else 0 if down else 1, 2, needRedstone=False))
if down:
if dire[1] > direction[1]+1:
dire[1]-=1
if dire[1] > direction[1] + 1:
dire[1] -= 1
else:
if dire[1] < height+direction[1]:
dire[1]+=1
if (down == False and dire[1] == height+direction[1]) or (down and dire[1] == direction+1):
if dire[1] < height + direction[1]:
dire[1] += 1
if (down is False and dire[1] == height + direction[1]) or (down and dire[1] == direction + 1):
down = not down
dire[0] += 1
direction[2] += 2
return BdxConverter(filePath, 'Build by Ryoun Musicreater', blocks)
def note2webs(Notes: list, Instrument: str, speed: float = 5.0, PlayerSelect: str = '', isProsess: bool = False):
"""传入音符在oaclhost:8080上建立websocket服务器以供我的世界connect/wssever指令连接
:param 参数说明:
@ -369,17 +348,13 @@ def note2webs(Notes: list, Instrument: str, speed: float = 5.0, PlayerSelect: st
await fcwslib.send_command(websocket,
'execute @a' + PlayerSelect + ' ~ ~ ~ title @s actionbar §e▶ 播放中: §a' +
str(
j) + '/' + str(length) + ' || ' + str(int(j / length * 1000) / 10))
j) + '/' + str(length) + ' || ' + str(int(j / length * 1000) / 10))
j += 1
time.sleep(Notes[i][1] / speed)
fcwslib.run_server(run_server)
def note2RSworld(world: str, startpos: list, notes: list, instrument: str, speed: float = 2.5,
posadder: Iterable = (1, 0, 0), baseblock: str = 'stone'): # -> bool
"""传入音符,生成以音符盒存储的红石音乐
@ -407,7 +382,7 @@ def note2RSworld(world: str, startpos: list, notes: list, instrument: str, speed
powered = 'true'
else:
powered = 'false'
return Block('universal_minecraft', 'noteblock',
return Block('universal_minecraft', 'notebooks',
{"instrument": ts(instrument1.replace("note.", '')), 'note': ts(str(note)),
'powered': ts(powered)})
@ -487,11 +462,6 @@ def note2RSworld(world: str, startpos: list, notes: list, instrument: str, speed
level.close()
class ryStruct:
def __init__(self, world: str) -> None:
@ -556,9 +526,6 @@ class ryStruct:
return self.RyStruct
"""
RyStruct = {
(0,0,0) = {