@@ -45,9 +45,10 @@ const builtInInstruments = new Map([
45
45
[ 14 , 'note.banjo' ] ,
46
46
[ 15 , 'note.pling' ] ,
47
47
] ) ;
48
- const playTasks : Map < string , number | boolean > = new Map ( ) ;
49
48
const bossBarId = 627752937 ; // NbsPlayer九键(xd
50
49
50
+ const playTasks : Map < string , NodeJS . Timer | boolean > = new Map ( ) ;
51
+
51
52
function readNbs (
52
53
name : string ,
53
54
callback : ( ok : boolean , resultOrError : string | Song | undefined ) => unknown
@@ -59,16 +60,18 @@ function readNbs(
59
60
} ) ;
60
61
}
61
62
62
- function stopPlay ( xuid : string ) : boolean {
63
- const taskId : unknown = playTasks . get ( xuid ) ;
63
+ function stopPlay ( xuid : string , setNew ?: boolean ) : boolean {
64
+ const taskId = playTasks . get ( xuid ) ;
64
65
if ( taskId ) {
65
- const ret = playTasks . delete ( xuid ) ;
66
- if ( taskId instanceof Number ) clearInterval ( taskId ) ;
66
+ if ( typeof taskId === 'object' ) clearInterval ( taskId ) ;
67
+
68
+ if ( setNew ) playTasks . set ( xuid , true ) ;
69
+ else playTasks . delete ( xuid ) ;
67
70
68
71
const pl = mc . getPlayer ( xuid ) ;
69
72
if ( pl ) pl . removeBossBar ( bossBarId ) ;
70
73
71
- return ret ;
74
+ return true ;
72
75
}
73
76
return false ;
74
77
}
@@ -108,9 +111,8 @@ function getPlaySoundDataPack(
108
111
function startPlay ( player : Player , nbsName : string ) {
109
112
const { xuid } = player ;
110
113
const playingTask = playTasks . get ( xuid ) ;
111
- if ( playingTask ) stopPlay ( xuid ) ;
114
+ if ( playingTask ) stopPlay ( xuid , true ) ;
112
115
113
- playTasks . set ( xuid , true ) ;
114
116
player . setBossBar ( bossBarId , `${ Green } 解析nbs文件……` , 100 , 4 ) ;
115
117
116
118
readNbs ( nbsName , ( ok , ret ) => {
@@ -125,7 +127,7 @@ function startPlay(player: Player, nbsName: string) {
125
127
errors,
126
128
meta : { name, author, originalAuthor } ,
127
129
length,
128
- instruments,
130
+ instruments : { loaded : loadedIns } ,
129
131
layers,
130
132
timePerTick,
131
133
} = ret ;
@@ -191,7 +193,7 @@ function startPlay(player: Player, nbsName: string) {
191
193
key : insKey ,
192
194
builtIn,
193
195
meta : { name : insName } ,
194
- } = instruments . loaded [ instrument ] ;
196
+ } = loadedIns [ instrument ] ;
195
197
const { pos } = pl ;
196
198
197
199
pos . y += 0.37 ;
@@ -204,7 +206,7 @@ function startPlay(player: Player, nbsName: string) {
204
206
bs ,
205
207
( builtIn ? builtInInstruments . get ( instrument ) : insName ) || '' ,
206
208
pos ,
207
- ( ( velocity || 100 ) / 100 ) * ( volume / 100 ) ,
209
+ ( velocity / 100 ) * ( volume / 100 ) ,
208
210
2 ** ( ( finalKey - 45 ) / 12 )
209
211
)
210
212
) ;
0 commit comments