-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathaudio.lua
115 lines (94 loc) · 2.52 KB
/
audio.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
local music_source = nil
music_volume = 1
sfx_volume = 1
current_music = ""
music_fading = false
sounds = {}
local current_volume = 1
local old_volume = 1
local sound_instances = {}
function registerSound(sound, volume)
sounds[sound] = {
data = love.sound.newSoundData(sound_path[sound]),
volume = volume or 1
}
--[[if not (sounds[sound].data) then
sounds[sound].data = love.sound.newSoundData("assets/audio/sfx/" .. sound .. ".xm")
end]]
end
function playSound(sound, volume, pitch)
if doing_past_turns and not do_past_effects then return end
if spookmode or scene == game and hasRule("?","sing","?") then
volume = 0.01
end
if sounds[sound] then
if not sound_instances[sound] then
sound_instances[sound] = 0
end
local source = love.audio.newSource(sounds[sound].data, "static")
local adjusted_volume = 1/(2^sound_instances[sound])
source:setVolume((volume or 1) * adjusted_volume * sounds[sound].volume * sfx_volume)
source:setPitch(pitch or 1)
source:play()
sound_instances[sound] = sound_instances[sound] + 1
tick.delay(function() sound_instances[sound] = sound_instances[sound] - 1 end, sounds[sound].data:getDuration()/4)
end
end
function playMusic(music, volume)
if spookmode then
volume = 0.2
music = "sayonabab"
end
if music_source ~= nil then
music_source:stop()
end
current_volume = volume or 1
old_volume = volume or 1
if music_path[music] then
music_source = love.audio.newSource(music_path[music], "static")
else
music_source = nil
end
if music_source ~= nil then
music_source:setLooping(true)
music_source:setVolume(current_volume * music_volume)
music_source:play()
end
current_music = music
end
function stopMusic()
if music_source ~= nil then
music_source:stop()
current_music = ""
end
end
function resetMusic(name,volume)
if spookmode then
volume = 0.01
end
music_fading = false
if current_volume == 0 or not hasMusic() or current_music ~= name then
playMusic(name,volume)
else
current_volume = volume
old_volume = volume
end
end
function updateMusic()
if not settings["focus_sound"] and not love.window.hasFocus() then
current_volume = 0
end
if music_source ~= nil then
music_source:setVolume(current_volume * music_volume)
end
if music_fading then
if current_volume > 0 then
current_volume = math.max(0, current_volume - 0.01)
end
else
current_volume = old_volume;
end
end
function hasMusic()
return music_source ~= nil
end