Skip to content

Commit 23aa2c3

Browse files
committed
feat: support april fools music
1 parent d5be895 commit 23aa2c3

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

src/base/game/sound.js

+47-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
import eventManager from '../../utils/eventManager.js';
22
import * as settings from '../../utils/settings/index.js';
33
import { global, globalSet } from '../../utils/global.js';
4+
import { getSeasonMonth } from '../../utils/season.js';
45

56
const baseVolumeSettings = { type: 'slider', page: 'Audio', max: 0.5, step: 0.01, default: 0.2, reset: true };
67
let active = false;
78

9+
const enable = settings.register({
10+
name: 'Enable Audio Override',
11+
key: 'underscript.audio.override',
12+
default: true,
13+
page: 'Audio',
14+
note: 'Disabling this disables all other Audio settings!',
15+
});
16+
17+
const aprilFoolsMusic = settings.register({
18+
name: 'Enable April Fools Music',
19+
key: 'underscript.audio.override.aprilFools',
20+
default: true,
21+
hidden: () => !isApril(),
22+
page: 'Audio',
23+
});
24+
825
const bgmEnabled = settings.register({
926
name: 'Enable BGM',
1027
key: 'underscript.audio.bgm',
@@ -68,12 +85,25 @@ function pauseMusic() {
6885
.forEach((audio) => audio.pause());
6986
}
7087

88+
function isApril() {
89+
return getSeasonMonth() === 4;
90+
}
91+
92+
function enableAprilFools() {
93+
return isApril() && aprilFoolsMusic.value;
94+
}
95+
7196
function overrideResult(name) {
7297
const data = { name, origin: name };
7398
const event = eventManager.cancelable.emit('playMusic', data);
7499
if (!resultEnabled.value() || !data.name || event.canceled) return;
75100
pauseMusic();
76-
createAudio(`/musics/${data.name}.ogg`, {
101+
if (!enable.value) {
102+
this.super(data.name);
103+
return;
104+
}
105+
const path = enableAprilFools() ? 'afm' : 'musics';
106+
createAudio(`/${path}/${data.name}.ogg`, {
77107
volume: resultVolume.value(),
78108
repeat: true,
79109
set: 'music',
@@ -84,7 +114,12 @@ function overrideMusic(name) {
84114
const event = eventManager.cancelable.emit('playBackgroundMusic', data);
85115
if (!bgmEnabled.value() || !data.name || event.canceled) return;
86116
pauseMusic();
87-
createAudio(`/musics/themes/${data.name}.ogg`, {
117+
if (!enable.value) {
118+
this.super(data.name);
119+
return;
120+
}
121+
const path = enableAprilFools() ? 'afm' : 'musics/themes';
122+
createAudio(`/${path}/${data.name}.ogg`, {
88123
volume: bgmVolume.value(),
89124
repeat: true,
90125
set: 'music',
@@ -94,6 +129,10 @@ function overrideSound(name) {
94129
const data = { name, origin: name };
95130
const event = eventManager.cancelable.emit('playSound', data);
96131
if (!soundEnabled.value() || !data.name || event.canceled) return;
132+
if (!enable.value) {
133+
this.super(data.name);
134+
return;
135+
}
97136
createAudio(`/sounds/${data.name}.wav`, {
98137
volume: soundVolume.value(),
99138
set: 'audio',
@@ -104,7 +143,12 @@ function overrideJingle(name = '') {
104143
const event = eventManager.cancelable.emit('playJingle', data);
105144
if (!jingleEnabled.value() || !data.name || event.canceled) return;
106145
pauseMusic();
107-
createAudio(`/musics/cards/${data.name.replace(/ /g, '_')}.ogg`, {
146+
if (!enable.value) {
147+
this.super(data.name);
148+
return;
149+
}
150+
const path = enableAprilFools() ? 'afm' : 'musics';
151+
createAudio(`/${path}/cards/${data.name.replace(/ /g, '_')}.ogg`, {
108152
volume: jingleVolume.value(),
109153
set: 'jingle',
110154
listener: global('jingleEnd'),

src/utils/season.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Stole all this from CMD.
2+
import eventManager from './eventManager.js';
3+
4+
const startsWith = 'quest-s';
5+
6+
let season = -1;
7+
8+
export function getSeason() {
9+
return season;
10+
}
11+
12+
export function getSeasonMonth() {
13+
if (season === -1) throw new Error('Season not loaded');
14+
return ((season - 66) % 12) + 1;
15+
}
16+
17+
eventManager.on('translation:loaded', () => {
18+
const messageKeys = Object.keys($.i18n.messageStore.messages.en);
19+
20+
const seasonKey = messageKeys.reverse().find((key) => key.startsWith(startsWith) && key.endsWith('-start-1'));
21+
if (!seasonKey) return; // Just a fail-safe
22+
23+
season = Number(seasonKey.substring(startsWith.length, seasonKey.indexOf('-', startsWith.length)));
24+
});

0 commit comments

Comments
 (0)