@@ -68,28 +68,25 @@ function convertNbs(name, callback) {
68
68
return ;
69
69
}
70
70
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
+ }
86
78
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
+ }
91
86
92
- if ( ! ok ) callback ( false , '读取文件失败' ) ;
87
+ File . delete ( nbsCachePath ) ;
88
+ callback ( true , j ) ;
89
+ } ) ;
93
90
}
94
91
) ;
95
92
}
@@ -188,18 +185,24 @@ function startPlay(player, nbsName) {
188
185
time : tickToMs ( v . tick , tempo ) ,
189
186
note : v ,
190
187
} ) ) ;
188
+ const totalNotes = noteAndTime . length ;
191
189
const startTime = Date . now ( ) ;
192
190
193
191
const task = ( ) => {
194
- const willPlay = [ ] ;
192
+ let notesRemain = noteAndTime . length ;
195
193
const pl = mc . getPlayer ( xuid ) ;
194
+ if ( notesRemain === 0 || ! pl ) {
195
+ stopPlay ( xuid ) ;
196
+ return ;
197
+ }
198
+
196
199
const timeSpent = Date . now ( ) - startTime ;
200
+ const willPlay = [ ] ;
197
201
198
202
for ( ; ; ) {
199
- if ( noteAndTime . length === 0 || ! pl ) {
200
- stopPlay ( xuid ) ;
201
- return ;
202
- }
203
+ notesRemain = noteAndTime . length ;
204
+ if ( notesRemain === 0 ) break ;
205
+
203
206
const { time, note } = noteAndTime [ 0 ] ;
204
207
if ( time <= timeSpent ) {
205
208
willPlay . push ( note ) ;
@@ -227,11 +230,14 @@ function startPlay(player, nbsName) {
227
230
// log(cmd);
228
231
mc . runcmdEx ( cmd ) ;
229
232
} ) ;
233
+
234
+ const timeSpentStr = formatMsTime ( timeSpent ) ;
230
235
pl . tell (
231
236
`${ Green } ▶ ${ LightPurple } NbsPlayer\n` +
232
237
`${ 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 } ` ,
235
241
4
236
242
) ;
237
243
} ;
@@ -398,7 +404,7 @@ function nbsForm(player) {
398
404
399
405
mc . listen ( 'onLeft' , ( pl ) => stopPlay ( pl . xuid ) ) ;
400
406
401
- ll . registerPlugin ( pluginName , '在服务器播放NBS音乐!' , [ 0 , 1 , 0 ] , {
407
+ ll . registerPlugin ( pluginName , '在服务器播放NBS音乐!' , [ 0 , 1 , 1 ] , {
402
408
Author : 'student_2333' ,
403
409
License : 'Apache-2.0' ,
404
410
} ) ;
0 commit comments