Skip to content

Commit 5237143

Browse files
committed
update
1 parent 0006f9d commit 5237143

File tree

2 files changed

+46
-30
lines changed

2 files changed

+46
-30
lines changed

NbsPlayer/NbsPlayer.lls.js

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,25 @@ function convertNbs(name, callback) {
6868
return;
6969
}
7070

71-
let file;
72-
try {
73-
file = new File(nbsCachePath, File.ReadMode);
74-
} catch {
75-
callback(false, '打开文件失败');
76-
return;
77-
}
78-
const ok = file.readAll((ret) => {
79-
let j;
80-
try {
81-
j = JSON.parse(ret);
82-
} catch {
83-
callback(false, '解析转换后Json失败');
84-
return;
85-
}
71+
Promise.resolve()
72+
.then(() => File.readFrom(nbsCachePath))
73+
.then((t) => {
74+
if (!t) {
75+
callback(false, '读取文件失败');
76+
return;
77+
}
8678

87-
file.close();
88-
File.delete(nbsCachePath);
89-
callback(true, j);
90-
});
79+
let j;
80+
try {
81+
j = JSON.parse(t);
82+
} catch {
83+
callback(false, '解析转换后Json失败');
84+
return;
85+
}
9186

92-
if (!ok) callback(false, '读取文件失败');
87+
File.delete(nbsCachePath);
88+
callback(true, j);
89+
});
9390
}
9491
);
9592
}
@@ -188,18 +185,24 @@ function startPlay(player, nbsName) {
188185
time: tickToMs(v.tick, tempo),
189186
note: v,
190187
}));
188+
const totalNotes = noteAndTime.length;
191189
const startTime = Date.now();
192190

193191
const task = () => {
194-
const willPlay = [];
192+
let notesRemain = noteAndTime.length;
195193
const pl = mc.getPlayer(xuid);
194+
if (notesRemain === 0 || !pl) {
195+
stopPlay(xuid);
196+
return;
197+
}
198+
196199
const timeSpent = Date.now() - startTime;
200+
const willPlay = [];
197201

198202
for (;;) {
199-
if (noteAndTime.length === 0 || !pl) {
200-
stopPlay(xuid);
201-
return;
202-
}
203+
notesRemain = noteAndTime.length;
204+
if (notesRemain === 0) break;
205+
203206
const { time, note } = noteAndTime[0];
204207
if (time <= timeSpent) {
205208
willPlay.push(note);
@@ -227,11 +230,14 @@ function startPlay(player, nbsName) {
227230
// log(cmd);
228231
mc.runcmdEx(cmd);
229232
});
233+
234+
const timeSpentStr = formatMsTime(timeSpent);
230235
pl.tell(
231236
`${Green}${LightPurple}NbsPlayer\n` +
232237
`${songDisplayName}\n` +
233-
`${Yellow}${formatMsTime(timeSpent)} ${Gray}| ` +
234-
`${Gold}${totalLengthStr}`,
238+
`${Yellow}${timeSpentStr} ${White}/ ${Gold}${totalLengthStr}` +
239+
`${Gray} | ` +
240+
`${Yellow}${totalNotes - notesRemain} ${White}/ ${Gold}${totalNotes}`,
235241
4
236242
);
237243
};
@@ -398,7 +404,7 @@ function nbsForm(player) {
398404

399405
mc.listen('onLeft', (pl) => stopPlay(pl.xuid));
400406

401-
ll.registerPlugin(pluginName, '在服务器播放NBS音乐!', [0, 1, 0], {
407+
ll.registerPlugin(pluginName, '在服务器播放NBS音乐!', [0, 1, 1], {
402408
Author: 'student_2333',
403409
License: 'Apache-2.0',
404410
});

NbsPlayer/readme.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ BDS 中的 NBS 音乐播放器!
1515
### 特点
1616

1717
- 支持 单音符/轨道/音色 的音高、音量等设置
18+
- 支持超过两个八度限制的音符
1819
- 支持自定义音色
1920
- 请将自定义音色的名称设置为`playsound`命令可以播放的声音 ID,例:`dig.stone`,支持资源包自定义的音色
2021

@@ -33,13 +34,19 @@ BDS 中的 NBS 音乐播放器!
3334
![4](readme/4.png)
3435
![5](readme/5.png)
3536

37+
### 演示
38+
39+
<https://www.bilibili.com/video/bv1gT41177sm>
40+
41+
<iframe src="//player.bilibili.com/player.html?aid=471512773&bvid=BV1gT41177sm&cid=789620051&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
42+
3643
## 安装
3744

3845
请去 [Releases](https://github.com/lgc2333/LLSEPlugins/releases) 下载最新版插件附件,解压到 bds 的插件目录
3946

4047
## 配置
4148

42-
直接将 nbs 文件放置在插件数据目录即可,注意文件名不要有特殊字符、中文等,否则可能会出错
49+
直接将 nbs 文件放置在插件数据目录即可~~,注意文件名不要有特殊字符、中文等,否则可能会出错~~(应该已修复)
4350
例图:
4451
![6](readme/6.png)
4552

@@ -67,4 +74,7 @@ QQ:3076823485
6774

6875
## 更新日志
6976

70-
暂无
77+
- 0.1.1
78+
- 修复 nbs 文件名不能为特殊符号或中文的问题
79+
- 修复无法播放最后一 tick 的音符的 bug
80+
- 加入音符数量显示

0 commit comments

Comments
 (0)