Skip to content

Commit

Permalink
Fix overlapping music on re-injection
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelius7309 committed Dec 28, 2024
1 parent c55ccd8 commit a6e80f8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 26 deletions.
26 changes: 1 addition & 25 deletions lovely/keybind.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pattern = "function Controller:key_release_update(key, dt)"
position = "after"
payload = '''
for _, keybind in pairs(SMODS.Keybinds) do
if keybind.action and keybind.key_pressed == key then
if keybind.action and keybind.key_pressed == key and keybind.event == 'released' then
local execute = true
for _, other_key in pairs(keybind.held_keys) do
if not self.held_keys[other_key] then
Expand Down Expand Up @@ -80,27 +80,3 @@ for _, keybind in pairs(SMODS.Keybinds) do
end
end
'''

# Controller:key_release_update
[[patches]]
[patches.pattern]
target = 'engine/controller.lua'
pattern = "function Controller:key_release_update(key, dt)"
position = "after"
payload = '''
for _, keybind in pairs(SMODS.Keybinds) do
if keybind.action and keybind.key_pressed == key and keybind.event == 'released' then
local execute = true
for _, other_key in pairs(keybind.held_keys) do
if not self.held_keys[other_key] then
execute = false
break
end
end
if execute then
keybind:action()
end
end
end
'''
match_indent = true
3 changes: 3 additions & 0 deletions src/game_object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,15 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
local file_path = type(self.path) == 'table' and
((G.SETTINGS.real_language and self.path[G.SETTINGS.real_language]) or self.path[G.SETTINGS.language] or self.path['default'] or self.path['en-us']) or self.path
if file_path == 'DEFAULT' then return end
local prev_path = self.full_path
self.full_path = (self.mod and self.mod.path or SMODS.path) ..
'assets/sounds/' .. file_path
if prev_path == self.full_path then return end
self.data = NFS.read('data', self.full_path)
self.decoder = love.sound.newDecoder(self.data)
self.should_stream = string.find(self.key, 'music') or string.find(self.key, 'stream') or string.find(self.key, 'ambient')
self.sound = love.audio.newSource(self.decoder, self.should_stream and 'stream' or 'static')
if prev_path then G.SOUND_MANAGER.channel:push({ type = 'stop' }) end
G.SOUND_MANAGER.channel:push({ type = 'sound_source', sound_code = self.sound_code, data = self.data, should_stream = self.should_stream, per = self.pitch, vol = self.volume })
end,
register_global = function(self)
Expand Down
2 changes: 1 addition & 1 deletion version.lua
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return "1.0.0~ALPHA-1227b-STEAMODDED"
return "1.0.0~ALPHA-1228a-STEAMODDED"

0 comments on commit a6e80f8

Please sign in to comment.