Skip to content

Commit f893161

Browse files
committed
fix: audio not registering correctly sometimes
1 parent 11ac3ba commit f893161

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# UnderScript Changelog
22

3+
## Version 0.63.9 (2025-09-10)
4+
1. Fixed in-game audio
5+
36
## Version 0.63.8 (2025-09-03)
47
1. Fix battle log (for realsies)
58

src/base/game/sound.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import eventManager from 'src/utils/eventManager.js';
22
import * as settings from 'src/utils/settings/index.js';
33
import { global, globalSet } from 'src/utils/global.js';
44
import { isApril, AUDIO } from 'src/utils/isApril.js';
5+
import { window } from 'src/utils/1.variables.js';
56
import { isSoftDisabled } from '../vanilla/aprilFools.js';
67

78
const baseVolumeSettings = { type: 'slider', page: 'Audio', max: 0.5, step: 0.01, default: 0.2, reset: true };
@@ -112,7 +113,7 @@ function overrideResult(name) {
112113
if (!resultEnabled.value() || !data.name || event.canceled) return;
113114
pauseMusic();
114115
if (!enable.value()) {
115-
this.super(data.name);
116+
this.super(data.name, resultVolume.value());
116117
return;
117118
}
118119
createAudio(`/${musicPath()}/${data.name}.ogg`, {
@@ -127,7 +128,7 @@ function overrideMusic(name) {
127128
if (!bgmEnabled.value() || !data.name || event.canceled) return;
128129
pauseMusic();
129130
if (!enable.value()) {
130-
this.super(data.name);
131+
this.super(data.name, bgmVolume.value());
131132
return;
132133
}
133134
createAudio(`/${musicPath()}/themes/${data.name}.ogg`, {
@@ -141,7 +142,7 @@ function overrideSound(name) {
141142
const event = eventManager.cancelable.emit('playSound', data);
142143
if (!soundEnabled.value() || !data.name || event.canceled) return;
143144
if (!enable.value()) {
144-
this.super(data.name);
145+
this.super(data.name, soundVolume.value());
145146
return;
146147
}
147148
createAudio(`/sounds/${data.name}.wav`, {
@@ -155,7 +156,7 @@ function overrideJingle(name = '') {
155156
if (!jingleEnabled.value() || !data.name || event.canceled) return;
156157
pauseMusic();
157158
if (!enable.value()) {
158-
this.super(data.name);
159+
this.super(data.name, jingleVolume.value());
159160
return;
160161
}
161162
createAudio(`/${musicPath()}/cards/${data.name.replace(/ /g, '_')}.ogg`, {
@@ -173,21 +174,18 @@ function createAudio(path, {
173174
play = true,
174175
}) {
175176
const audio = new Audio(path);
176-
audio.volume = parseFloat(volume);
177+
audio.volume = volume;
178+
audio.loop = repeat;
177179
if (listener) {
178180
audio.addEventListener('ended', listener, false);
179-
} else if (repeat) {
180-
audio.addEventListener('ended', function ended() {
181-
this.currentTime = 0;
182-
this.play();
183-
}, false);
184181
}
185182
if (set) globalSet(set, audio);
186183
if (play) audio.play();
187184
return audio;
188185
}
189186

190-
eventManager.on('connect', () => {
187+
eventManager.on(':preload', () => {
188+
if (typeof window.playMusic !== 'function') return;
191189
active = true;
192190
// Override sound functions
193191
globalSet('playMusic', overrideResult);

0 commit comments

Comments
 (0)