修改部分说明文件,提供了命令行操作的支持

This commit is contained in:
EillesWan 2021-12-12 17:50:41 +08:00
parent 737ec6a1be
commit 71d445d255
6 changed files with 400 additions and 7 deletions

383
Cmd_Msct.py Normal file
View File

@ -0,0 +1,383 @@
# -*- coding: utf-8 -*-
# W-YI 金羿
# QQ 2647547478
# 音·创 开发交流群 861684859
# Email EillesWan2006@163.com W-YI_DoctorYI@outlook.com
# 版权所有 Team-Ryoun 金羿
# 若需转载或借鉴 请附作者
# 代码写的并非十分的漂亮还请大佬多多包涵本软件源代码依照Apache软件协议公开
import json
import os
import shutil
import threading
import sys
from msctspt.threadOpera import NewThread
from msctspt.bugReporter import version
from nmcsup.log import log
__version__ = version.version[1]+version.version[0]
__author__ = 'W-YI (金羿)'
log("系统工作————————加载变量及函数")
print("更新执行位置...")
if sys.platform == 'win32':
os.chdir(__file__[:len(__file__)-__file__[len(__file__)::-1].index('\\')])
log("更新执行位置,当前文件位置"+__file__)
else:
try:
os.chdir(__file__[:len(__file__)-__file__[len(__file__)::-1].index('/')])
except:
pass
log("其他平台:"+sys.platform+"更新执行位置,当前文件位置"+__file__)
print('完成!')
def __main__():
print('建立变量,存入内存,载入字典常量函数')
# 主体部分
# 支持多文件同时操作
# dataset[{ 'mainset':{ 'x':'y' }, 'musics': [ { 'set' :{ 'A':'B' } , 'note' : [ [ 'a' , b ], ] }, ] }, ]
# 编辑:
# 修改主设置: dataset[第几个项目]['mainset']['什么设置'] = '设置啥'
# 修改音乐: dataset[第几个项目]['musics'][第几个音轨]['notes'][第几个音符][音符还是时间01] = 改成啥
# 修改音轨设置: dataset[第几个项目]['musics'][第几个音轨]['set']['什么设置'] = '设置啥'
#
# 新增音轨: dataset[第几个项目]['musics'].append(datasetmodelpart)
#
'''
dataset=[
{
'mainset':{
'PackName':"Ryoun",
'MusicTitle':'Noname',
'IsRepeat':False,
'PlayerSelect':''
},
'musics':[
{
'set':{
'EntityName':'music_support',
'ScoreboardName':'music_support',
'Instrument':'harp',
'FileName':"Music"
},
'notes':[
[0.0,1.0],
]
},
],
},
]
'''
global dataset
dataset = [
{
'mainset': {
'PackName': "Ryoun",
'MusicTitle': 'Noname',
'IsRepeat': False,
'PlayerSelect': ''
},
'musics': [
{
'set': {
'EntityName': 'MusicSupport',
'ScoreboardName': 'MusicSupport',
'Instrument': 'note.harp',
'FileName': "Music"
},
'notes': [
[0.0, 1.0],
]
},
],
},
]
global is_new_file
global is_save
global ProjectName
global NowMusic
is_new_file = True
is_save = True
ProjectName = ''
NowMusic = 0
def DMM(): # 反回字典用于编辑
datasetmodelpart = {
'set': {
'EntityName': 'MusicSupport',
'ScoreboardName': 'MusicSupport',
'Instrument': 'note.harp',
'FileName': "Music"
},
'notes': []
}
return datasetmodelpart
print("完成")
# 菜单命令
print('加载菜单命令...');
def exitapp(cmd):
log("程序正常退出",False)
global is_save
if is_save == False:
if '/s' in cmd:
saveProject()
else:
print("您尚未保存,请使用 /s 开关保存并退出")
return
try:
global dataset
del dataset
except:
pass;
if '/c' in cmd :
print("清除log此句不载入日志")
try:
if os.path.exists("./log/"):
shutil.rmtree("./log/")
if os.path.exists("./logs/"):
shutil.rmtree("./logs/")
if os.path.exists("./cache/"):
shutil.rmtree("./cache/")
except:
print("无法清除日志及临时文件")
exit()
print('退出函数加载完成!')
print("载入文件读取函数")
def ReadFile(fn:str) -> list:
from nmcsup.nmcreader import ReadFile as fileRead
k = fileRead(fn)
if k == False :
log("找不到"+fn)
return
else:
return k
def ReadMidi(midfile:str) -> str:
from nmcsup.nmcreader import ReadMidi as midiRead
k = midiRead(midfile)
if k == False :
log("找不到"+midfile)
return
else:
return k
print('完成!')
print("载入命令函数")
def saveProject(cmd:list):
global is_new_file
if '/a' in cmd:
log("另存项目")
ProjectName = cmd[cmd.index('/a')+1]
else:
if is_new_file:
print("初次存储请使用 /a 开关规定存储文件名")
log("文件为未保存")
return
log("存储文件:"+ProjectName)
with open(ProjectName, 'w', encoding='utf-8') as f:
json.dump(dataset[0], f)
global is_save
is_save = True
print('保存项目函数加载完成!')
def loadMusic(cmd:list):
if '/mid' in cmd:
th = NewThread(ReadMidi, (cmd[cmd.index('/mid')+1],))
th.start()
def midiSPT(th):
for i in th.getResult():
datas = DMM()
datas['notes'] = i
dataset[0]['musics'].append(datas)
del th
global is_save
is_save = False
threading.Thread(target=midiSPT, args=(th,)).start()
del th
elif '/txt' in cmd:
th = NewThread(ReadFile, (cmd[cmd.index('/txt')+1],))
th.start()
def midiSPT(th):
for i in th.getResult():
datas = DMM()
datas['notes'] = i
dataset[0]['musics'].append(datas)
del th
global is_save
is_save = False
threading.Thread(target=midiSPT, args=(th,)).start()
elif '/input' in cmd:
datas = []
for i in cmd[cmd.index('/input')+1:]:
datas.append([str(i), 1.0])
from nmcsup.trans import note2list
datat = DMM()
datat['notes'] = note2list(datas)
dataset[0]['musics'].append(datat)
del datas, datat
global is_save
is_save = False
print('音轨载入函数加载完成!')
def funBuild(cmd:list):
if '/file' in cmd:
from msctspt.funcOpera import makeFuncFiles
makepath = cmd[cmd.index('/file')+1]
if makepath[-1] != '/':
makepath += '/'
makeFuncFiles(dataset[0], makepath)
elif '/directory' in cmd:
from msctspt.funcOpera import makeFunDir
makepath = cmd[cmd.index('/directory')+1]
if makepath[-1] != '/':
makepath += '/'
makeFunDir(dataset[0], makepath)
elif '/mcpack' in cmd:
import zipfile
from msctspt.funcOpera import makeFunDir
makepath = cmd[cmd.index('/mcpack')+1]
if makepath[-1] != '/':
makepath += '/'
if not os.path.exists('./temp/'):
os.makedirs('./temp/')
makeFunDir(dataset[0], './temp/')
shutil.move('./temp/'+dataset[0]['mainset']['PackName'] +"Pack/behavior_packs/"+dataset[0]['mainset']['PackName']+"/functions",'./')
shutil.move('./temp/'+dataset[0]['mainset']['PackName'] +"Pack/behavior_packs/"+dataset[0]['mainset']['PackName']+"/manifest.json",'./')
with zipfile.ZipFile(makepath+dataset[0]['mainset']['PackName']+'.mcpack', "w") as zipobj:
for i in os.listdir('./functions/'):
zipobj.write('./functions/'+i)
zipobj.write('./manifest.json')
shutil.move('./functions','./temp/')
shutil.move('./manifest.json','./temp/')
shutil.rmtree("./temp/")
print("函数建立函数加载完成")
if sys.platform == 'win32':
os.system("cls")
else:
os.system("clear")
if sys.platform in ('win32','linux'):
print("您当前的运行环境为标准桌面,您可以打开 Musicreater.py 运行窗口模式的 音·创")
print("您也可以输入 win 指令在不退出命令行模式的同时打开窗口模式\n")
print(__author__+" 音·创<命令行模式> 当前核心版本 "+__version__+'\n')
nowWorkPath = os.path.split(os.path.realpath(__file__))[0]
while True:
strcmd = input("MSCT "+nowWorkPath+">")
cmd = strcmd.lower().split(' ')
if cmd[0] == 'exit':
exitapp(cmd[1:])
elif cmd[0] == 'save':
saveProject(cmd[1:])
elif cmd[0] == 'load':
loadMusic(cmd[1:])
elif cmd[0] == 'win':
def run(cmd):
os.system(cmd)
if sys.platform == 'win32':
NewThread(run,("python "+os.path.split(os.path.realpath(__file__))[0]+"/Musicreater.py",)).start()
else:
NewThread(run,("python3 "+os.path.split(os.path.realpath(__file__))[0]+"/Musicreater.py",)).start()
elif cmd[0] == 'chdir':
nowWorkPath = os.path.realpath(cmd[1])
os.chdir(nowWorkPath)
elif cmd[0] == 'build':
funBuild(cmd[1:])
else:
os.system(strcmd)
if __name__ == '__main__':
__main__()

View File

@ -175,8 +175,11 @@ def __main__():
print("更新执行位置...")
if sys.platform == 'win32':
os.chdir(__file__[:len(__file__)-__file__[len(__file__)::-1].index('\\')])
log("更新执行位置,当前文件位置"+__file__)
try:
os.chdir(__file__[:len(__file__)-__file__[len(__file__)::-1].index('\\')])
log("更新执行位置,当前文件位置"+__file__)
except:
pass
else:
try:
os.chdir(__file__[:len(__file__)-__file__[len(__file__)::-1].index('/')])

View File

@ -16,7 +16,8 @@
#### Windows7+
0. [下载](https://gitee.com/EillesWan/Musicreater/repository/archive/master.zip)本程序
0. [Gitee下载需要登陆](https://gitee.com/EillesWan/Musicreater/repository/archive/master.zip)
[Github下载](https://github.com/EillesWan/Musicreater/archive/refs/heads/master.zip)本程序
1. 安装Python 3.8.10
[下载64位安装包](https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.exe)
[下载32位安装包](https://www.python.org/ftp/python/3.8.10/python-3.8.10.exe)
@ -54,10 +55,15 @@ python3 Musicreater.py
### 致谢
1. 感谢由 [Fuckcraft](https://gitee.com/fuckcraft) “鸣凤鸽子”等 带来的我的世界websocket服务器功能
1. 感谢由 [Fuckcraft](https://github.com/fuckcraft) “鸣凤鸽子”等 带来的我的世界websocket服务器功能
2. 感谢 昀梦QQ1515399885 找出指令生成错误bug并指正
3. 感谢由 Charlie_Ping “查理平” 带来的bdx转换功能
4. 感谢广大群友为此程序提供的测试等支持
5. 若您为我找出了错误但您的名字没有显示在此列表中,请联系我!
### 作者<金羿>联系方式
1. QQ 2647547478
2. 电邮 EillesWan2006@163.com W-YI_DoctorYI@outlook.com
3. 微信 WYI_DoctorYI

View File

@ -1,5 +1,5 @@
音·创(Musicreater)是由金羿(W-YI)开发的一款《我的世界》基岩版音乐生成辅助软件
本软件源代码依照Apache软件协议公开,如使用未经授权的音乐经过此软件生成的任何物件侵犯了他人权利与本软件及其作者无关
本软件源代码依照Apache软件协议公开
Copyright © W-YI 2021

View File

@ -7,10 +7,11 @@ StrStartTime = str(datetime.datetime.now()).replace(':', '_')[:-7]
'''字符串型的程序开始时间'''
def log(info:str = ''):
def log(info:str = '',isPrinted:bool = True):
'''将信息连同当前时间载入日志'''
if not os.path.exists('./log/'):
os.makedirs('./log/')
with open('./log/'+StrStartTime+'.msct.log', 'a',encoding='UTF-8') as f:
f.write(str(datetime.datetime.now())[11:19]+' '+info+'\n')
print(str(datetime.datetime.now())[11:19]+' '+info)
if isPrinted:
print(str(datetime.datetime.now())[11:19]+' '+info)