chore: add a wrapper for sfx
This commit is contained in:
parent
e7878c1efa
commit
021a2b08b2
2 changed files with 54 additions and 4 deletions
|
@ -36,6 +36,8 @@ local Tileset = require(cwd .. "tileset")
|
||||||
local Autotile = require(cwd .. "autotile")
|
local Autotile = require(cwd .. "autotile")
|
||||||
local Background = require(cwd .. "background")
|
local Background = require(cwd .. "background")
|
||||||
|
|
||||||
|
local SFX = require(cwd .. "sfx")
|
||||||
|
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initilizing and configuring option
|
-- Initilizing and configuring option
|
||||||
|
|
||||||
|
@ -151,7 +153,7 @@ function Assets:addSFX(name, filepath)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Assets:newSFX(name, filepath)
|
function Assets:newSFX(name, filepath)
|
||||||
self.sfx[name] = love.audio.newSource( filepath, "static" )
|
self.sfx[name] = SFX( filepath )
|
||||||
end
|
end
|
||||||
|
|
||||||
function Assets:clearSFX()
|
function Assets:clearSFX()
|
||||||
|
@ -161,9 +163,7 @@ end
|
||||||
|
|
||||||
function Assets:playSFX(filename)
|
function Assets:playSFX(filename)
|
||||||
if not (self.sfx[filename] == nil) then
|
if not (self.sfx[filename] == nil) then
|
||||||
self.sfx[filename]:stop()
|
self.sfx[filename]:play()
|
||||||
self.sfx[filename]:setVolume(core.options.data.audio.sfx / 100)
|
|
||||||
love.audio.play( self.sfx[filename] )
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
50
sonic-radiance.love/core/modules/assets/sfx.lua
Normal file
50
sonic-radiance.love/core/modules/assets/sfx.lua
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
-- assets/sfx :: the sfx object
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Copyright © 2021 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.source = love.audio.newSource(filepath, "static")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- INFO FUNCTIONS
|
||||||
|
-- get information with these functions
|
||||||
|
|
||||||
|
-- None for the moment
|
||||||
|
|
||||||
|
-- DRAW FUNCTIONS
|
||||||
|
-- Draw texture using these functions
|
||||||
|
|
||||||
|
function SFX:play()
|
||||||
|
self.source:stop()
|
||||||
|
self.source:setVolume(core.options.data.audio.sfx / 100)
|
||||||
|
love.audio.play(self.source)
|
||||||
|
end
|
||||||
|
|
||||||
|
function SFX:stop()
|
||||||
|
self.source:stop()
|
||||||
|
end
|
||||||
|
|
||||||
|
return SFX
|
Loading…
Reference in a new issue