From 3b1097c91716806ba116d54a0c4dfb17244f83ea Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 13 Nov 2020 17:43:28 +0100 Subject: [PATCH] chore: make SFX a soundObject too --- birb/modules/assets/init.lua | 8 +++--- birb/modules/assets/sfx.lua | 40 ++++++++++++++++++++++++++++++ birb/modules/menusystem/parent.lua | 4 +-- 3 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 birb/modules/assets/sfx.lua diff --git a/birb/modules/assets/init.lua b/birb/modules/assets/init.lua index 700b139..7336cdd 100644 --- a/birb/modules/assets/init.lua +++ b/birb/modules/assets/init.lua @@ -36,6 +36,8 @@ local Tileset = require(cwd .. "tileset") local Autotile = require(cwd .. "autotile") local Background = require(cwd .. "background") +local SFX = require(cwd .. "sfx") + -- INIT FUNCTIONS -- Initilizing and configuring option @@ -151,7 +153,7 @@ function Assets:addSFX(name, filepath) end function Assets:newSFX(name, filepath) - self.sfx[name] = love.audio.newSource( filepath, "static" ) + self.sfx[name] = SFX(filepath) end function Assets:clearSFX() @@ -161,9 +163,7 @@ end function Assets:playSFX(filename) if not (self.sfx[filename] == nil) then - self.sfx[filename]:stop() - self.sfx[filename]:setVolume(core.options.data.audio.sfx / 100) - love.audio.play( self.sfx[filename] ) + self.sfx[filename]:play() end end diff --git a/birb/modules/assets/sfx.lua b/birb/modules/assets/sfx.lua new file mode 100644 index 0000000..2660f33 --- /dev/null +++ b/birb/modules/assets/sfx.lua @@ -0,0 +1,40 @@ +-- assets/sfx :: the sfx object, essentially used to be able to just have an sfx + +--[[ + Copyright © 2020 Kazhnuz + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +]] + + +local SFX = Object:extend() + +-- INIT FUNCTIONS +-- Initilizing and configuring option + +function SFX:new(filepath) + self.sound = love.audio.newSource(filepath, "static") +end + +function SFX:play() + self.sound:stop() + self.sound:setVolume(core.options.data.audio.sfx / 100) + love.audio.play(self.sound) +end + +return SFX diff --git a/birb/modules/menusystem/parent.lua b/birb/modules/menusystem/parent.lua index 12777e6..bc6b3fd 100644 --- a/birb/modules/menusystem/parent.lua +++ b/birb/modules/menusystem/parent.lua @@ -267,9 +267,7 @@ end function Menu:playNavigationSound() if self.sound.active == true then - love.audio.stop( self.sound.asset ) - self.sound.asset:setVolume(core.options.data.audio.sfx / 100) - love.audio.play( self.sound.asset ) + self.sound.asset:play() end end