Skip to content

Commit 947704a

Browse files
committed
final!!!!! fix
1 parent 11205f0 commit 947704a

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

NbsPlayer/src/index.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ const builtInInstruments = new Map([
4545
[14, 'note.banjo'],
4646
[15, 'note.pling'],
4747
]);
48-
const playTasks: Map<string, number | boolean> = new Map();
4948
const bossBarId = 627752937; // NbsPlayer九键(xd
5049

50+
const playTasks: Map<string, NodeJS.Timer | boolean> = new Map();
51+
5152
function readNbs(
5253
name: string,
5354
callback: (ok: boolean, resultOrError: string | Song | undefined) => unknown
@@ -59,16 +60,18 @@ function readNbs(
5960
});
6061
}
6162

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);
6465
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);
6770

6871
const pl = mc.getPlayer(xuid);
6972
if (pl) pl.removeBossBar(bossBarId);
7073

71-
return ret;
74+
return true;
7275
}
7376
return false;
7477
}
@@ -108,9 +111,8 @@ function getPlaySoundDataPack(
108111
function startPlay(player: Player, nbsName: string) {
109112
const { xuid } = player;
110113
const playingTask = playTasks.get(xuid);
111-
if (playingTask) stopPlay(xuid);
114+
if (playingTask) stopPlay(xuid, true);
112115

113-
playTasks.set(xuid, true);
114116
player.setBossBar(bossBarId, `${Green}解析nbs文件……`, 100, 4);
115117

116118
readNbs(nbsName, (ok, ret) => {
@@ -125,7 +127,7 @@ function startPlay(player: Player, nbsName: string) {
125127
errors,
126128
meta: { name, author, originalAuthor },
127129
length,
128-
instruments,
130+
instruments: { loaded: loadedIns },
129131
layers,
130132
timePerTick,
131133
} = ret;
@@ -191,7 +193,7 @@ function startPlay(player: Player, nbsName: string) {
191193
key: insKey,
192194
builtIn,
193195
meta: { name: insName },
194-
} = instruments.loaded[instrument];
196+
} = loadedIns[instrument];
195197
const { pos } = pl;
196198

197199
pos.y += 0.37;
@@ -204,7 +206,7 @@ function startPlay(player: Player, nbsName: string) {
204206
bs,
205207
(builtIn ? builtInInstruments.get(instrument) : insName) || '',
206208
pos,
207-
((velocity || 100) / 100) * (volume / 100),
209+
(velocity / 100) * (volume / 100),
208210
2 ** ((finalKey - 45) / 12)
209211
)
210212
);

0 commit comments

Comments
 (0)