summaryrefslogtreecommitdiff
path: root/game/music.lua
blob: b4ed5f191c35aca6b12e8e2891a6e2ca7444c840 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
local M = {}
M.__index = M
M.playing = nil

function M.new(assets)
	local new = setmetatable({}, M)
	new.assets = assets
	return new
end

function M:play(name)
	assert(self.assets.music[name], name.." isn't extant music")
	if M.playing ~= self.assets.music[name] then
        if M.playing then M.playing:stop() end
        self.assets.music[name]:seek(0)
        M.playing = self.assets.music[name]
    end
	self.assets.music[name]:play()
end

return M