-
Notifications
You must be signed in to change notification settings - Fork 15
/
resmgr.lua
74 lines (59 loc) · 1.76 KB
/
resmgr.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
local ResMgr = {}
ResMgr.__index = ResMgr
local images = {}
local fonts = {}
local sounds = {}
local fontString = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.,:+-?!()|x%"
local currentSongSource = nil
function ResMgr.getImage(name)
local path = "res/images/" .. name
if images[path] == nil then
images[path] = love.graphics.newImage(path)
images[path]:setWrap("repeat", "repeat")
print("Loaded image: " .. name)
end
return images[path]
end
function ResMgr.loadFonts()
fonts["bold"] = love.graphics.newImageFont(ResMgr.getImage("fonts/bold.png"), fontString, 2)
fonts["menu"] = love.graphics.newImageFont(ResMgr.getImage("fonts/menu.png"), fontString)
fonts["joystix30"] = love.graphics.newFont("res/images/fonts/joystix.ttf", 30)
fonts["joystix40"] = love.graphics.newFont("res/images/fonts/joystix.ttf", 40)
end
function ResMgr.getFont(name)
return fonts[name]
end
function ResMgr.getSound(name)
local path = "res/sounds/" .. name .. ".wav"
if sounds[path] == nil then
sounds[path] = love.audio.newSource(path, "static")
sounds[path]:addTags("sfx")
print("Loaded sound: " .. name)
end
return sounds[path]
end
function playSound(name)
local sound = ResMgr.getSound(name)
love.audio.play(sound)
end
function playMusic(name)
stopMusic()
local path = "res/music/" .. name
if love.filesystem.exists(path) == false then return end
local source = love.audio.newSource("res/music/" .. name, "stream")
source:setLooping(true)
source:setVolume(config.music_volume/5)
source:play()
currentSongSource = source
end
function stopMusic()
if currentSongSource then
currentSongSource:stop()
currentSongSource = nil
end
end
function updateVolume()
currentSongSource:setVolume(config.music_volume/5)
love.audio.tags.sfx.setVolume(config.sound_volume/5)
end
return ResMgr