162 lines
3 KiB
Lua
162 lines
3 KiB
Lua
local Assets = Object:extend()
|
|
|
|
local Sprite = require "core.modules.assets.sprites"
|
|
local Font = require "core.modules.assets.fonts"
|
|
local Tileset = require "core.modules.assets.tileset"
|
|
local Autotile = require "core.modules.assets.autotile"
|
|
local Background = require "core.modules.assets.background"
|
|
|
|
|
|
function Assets:new()
|
|
self.sprites = {}
|
|
self.sfx = {}
|
|
self.fonts = {}
|
|
self.music = nil
|
|
self:clearBackgrounds()
|
|
self:clearFonts()
|
|
self:clearAutotile()
|
|
self:clearTileset()
|
|
|
|
self.images = {}
|
|
end
|
|
|
|
function Assets:init()
|
|
self.sprites = {}
|
|
self.sfx = {}
|
|
self.fonts = {}
|
|
self.music = nil
|
|
self.backgrounds= {}
|
|
self:clearFonts()
|
|
|
|
self.images = {}
|
|
end
|
|
|
|
function Assets:clear()
|
|
self.sprites = {}
|
|
self.sfx = {}
|
|
self.fonts = {}
|
|
self.music = nil
|
|
self.backgrounds= {}
|
|
self:clearFonts()
|
|
|
|
self.images = {}
|
|
end
|
|
|
|
function Assets:update(dt)
|
|
self:animationsUpdate(dt)
|
|
end
|
|
|
|
-- SFX et Musique
|
|
|
|
function Assets:addSFX(name, filepath)
|
|
self:newSFX(name, filepath)
|
|
end
|
|
|
|
function Assets:newSFX(name, filepath)
|
|
self.sfx[name] = love.audio.newSource( filepath, "static" )
|
|
end
|
|
|
|
function Assets:clearSFX()
|
|
love.audio.stop( )
|
|
self.sfx = {}
|
|
end
|
|
|
|
function Assets:setMusic(filename)
|
|
if filename ~= nil then
|
|
love.audio.stop( )
|
|
self.music = love.audio.newSource(filename, "stream" )
|
|
self.music:setVolume(game.options.data.audio.music / 100)
|
|
end
|
|
end
|
|
|
|
function Assets:playSFX(filename)
|
|
if not (self.sfx[filename] == nil) then
|
|
self.sfx[filename]:stop()
|
|
self.sfx[filename]:setVolume(game.options.data.audio.sfx / 100)
|
|
love.audio.play( self.sfx[filename] )
|
|
end
|
|
end
|
|
|
|
function Assets:playMusic()
|
|
if not (self.music == nil) then
|
|
love.audio.play(self.music)
|
|
end
|
|
end
|
|
|
|
function Assets:silence()
|
|
love.audio.stop()
|
|
end
|
|
|
|
-- Background --
|
|
|
|
function Assets:addImage(name, filename)
|
|
self.images[name] = love.graphics.newImage(filename)
|
|
end
|
|
|
|
function Assets:drawImage(name, x, y, r, sx, sy, ox, oy, kx, ky)
|
|
love.graphics.draw(self.images[name], x, y, r, sx, sy, ox, oy, kx, ky)
|
|
end
|
|
|
|
-- Images --
|
|
|
|
function Assets:clearBackgrounds()
|
|
self.backgrounds = {}
|
|
end
|
|
|
|
function Assets:addBackground(name, filepath)
|
|
self.backgrounds[name] = Background(filepath)
|
|
end
|
|
|
|
-- SPRITES --
|
|
|
|
|
|
function Assets:addSprite(name, filepath)
|
|
self.sprites[name] = Sprite(filepath)
|
|
end
|
|
|
|
function Assets:clearSprites()
|
|
self.sprites = {}
|
|
end
|
|
|
|
function Assets:animationsUpdate(dt)
|
|
for i,v in pairs(self.sprites) do
|
|
v:update(dt)
|
|
end
|
|
end
|
|
|
|
-- FONTS --
|
|
|
|
function Assets:clearFonts()
|
|
self.fonts = {}
|
|
end
|
|
|
|
function Assets:addFont(key, filename, size)
|
|
local font = Font(filename, size)
|
|
self.fonts[key] = font
|
|
end
|
|
|
|
function Assets:getFont(filename)
|
|
return self.fonts[filename]
|
|
end
|
|
|
|
-- Tileset
|
|
|
|
function Assets:addTileset(name, filepath)
|
|
self.tileset[name] = Tileset(filepath)
|
|
end
|
|
|
|
function Assets:clearTileset()
|
|
self.tileset = {}
|
|
end
|
|
|
|
-- Autotile
|
|
|
|
function Assets:addAutotile(name, tilesize)
|
|
self.autotile[name] = Autotile(name, tilesize)
|
|
end
|
|
|
|
function Assets:clearAutotile()
|
|
self.autotile = {}
|
|
end
|
|
|
|
return Assets
|