2019-05-22 22:57:34 -05:00
|
|
|
bgm = {
|
|
|
|
credit_roll = {
|
|
|
|
gm3 = love.audio.newSource("res/bgm/tgm_credit_roll.mp3", "stream"),
|
|
|
|
},
|
|
|
|
pacer_test = love.audio.newSource("res/bgm/pacer_test.mp3", "stream"),
|
2021-10-22 00:08:14 -05:00
|
|
|
test = {
|
|
|
|
intro = love.audio.newSource("res/bgm/h_test_intro.wav", "static"),
|
|
|
|
loop = love.audio.newSource("res/bgm/h_test_loop.wav", "stream"),
|
|
|
|
},
|
2019-05-22 22:57:34 -05:00
|
|
|
}
|
|
|
|
|
2021-10-22 00:08:14 -05:00
|
|
|
|
|
|
|
local frames = 0
|
2019-05-22 22:57:34 -05:00
|
|
|
local current_bgm = nil
|
2020-12-20 14:08:53 -06:00
|
|
|
local bgm_locked = false
|
2021-09-20 22:33:27 -05:00
|
|
|
local unfocused = false
|
2019-05-22 22:57:34 -05:00
|
|
|
|
|
|
|
function switchBGM(sound, subsound)
|
|
|
|
if current_bgm ~= nil then
|
|
|
|
current_bgm:stop()
|
|
|
|
end
|
2021-06-09 19:15:37 -05:00
|
|
|
if bgm_locked or config.bgm_volume <= 0 then
|
|
|
|
current_bgm = nil
|
2019-05-22 22:57:34 -05:00
|
|
|
elseif sound ~= nil then
|
2021-06-09 19:15:37 -05:00
|
|
|
if subsound ~= nil then
|
|
|
|
current_bgm = bgm[sound][subsound]
|
|
|
|
else
|
|
|
|
current_bgm = bgm[sound]
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
else
|
|
|
|
current_bgm = nil
|
|
|
|
end
|
2021-06-09 19:15:37 -05:00
|
|
|
if current_bgm ~= nil then
|
|
|
|
resetBGMFadeout()
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function switchBGMLoop(sound, subsound)
|
|
|
|
switchBGM(sound, subsound)
|
2021-06-09 19:15:37 -05:00
|
|
|
if current_bgm then current_bgm:setLooping(true) end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function lockBGM()
|
|
|
|
bgm_locked = true
|
|
|
|
end
|
|
|
|
|
2021-06-09 19:15:37 -05:00
|
|
|
function unlockBGM()
|
|
|
|
bgm_locked = false
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
local fading_bgm = false
|
|
|
|
local fadeout_time = 0
|
|
|
|
local total_fadeout_time = 0
|
|
|
|
|
|
|
|
function fadeoutBGM(time)
|
|
|
|
if fading_bgm == false then
|
|
|
|
fading_bgm = true
|
|
|
|
fadeout_time = time
|
|
|
|
total_fadeout_time = time
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function resetBGMFadeout(time)
|
2020-12-20 14:26:32 -06:00
|
|
|
current_bgm:setVolume(config.bgm_volume)
|
2019-05-22 22:57:34 -05:00
|
|
|
fading_bgm = false
|
2021-09-20 22:33:27 -05:00
|
|
|
resumeBGM()
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function processBGMFadeout(dt)
|
2021-06-09 19:15:37 -05:00
|
|
|
if current_bgm and fading_bgm then
|
2019-05-22 22:57:34 -05:00
|
|
|
fadeout_time = fadeout_time - dt
|
|
|
|
if fadeout_time < 0 then
|
|
|
|
fadeout_time = 0
|
|
|
|
fading_bgm = false
|
|
|
|
end
|
2020-12-20 14:26:32 -06:00
|
|
|
current_bgm:setVolume(fadeout_time * config.bgm_volume / total_fadeout_time)
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-20 22:33:27 -05:00
|
|
|
function pauseBGM(f)
|
|
|
|
if f then
|
|
|
|
unfocused = true
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
if current_bgm ~= nil then
|
|
|
|
current_bgm:pause()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-20 22:33:27 -05:00
|
|
|
function resumeBGM(f)
|
|
|
|
if f and scene.paused and unfocused then
|
|
|
|
unfocused = false
|
|
|
|
return
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
if current_bgm ~= nil then
|
|
|
|
current_bgm:play()
|
|
|
|
end
|
|
|
|
end
|