summaryrefslogtreecommitdiffhomepage
path: root/not/SceneManager.lua
blob: 4f9edfdca176919fe2fe96bd6a1b2c54eee095ce (plain)
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
--- `SceneManager`
-- Used for changing single active scene.
-- TODO: Extend functionality for more than one active scene (eg. overlay menu).
SceneManager = require "not.Object":extends()

function SceneManager:new ()
	self.scenes = {}
end

-- This function should be removed when multiple scenes will be handled properly by SceneManager and other things.
function SceneManager:changeScene (scene)
	local removed = table.remove(self.scenes, #self.scenes)
	if removed then
		removed:delete()
	end
	return self:addScene(scene)
end

function SceneManager:addScene (scene)
	table.insert(self.scenes, scene)
	return scene
end

-- Not nice, not nice.
function SceneManager:removeTopScene ()
	local scene = table.remove(self.scenes, #self.scenes)
	scene:delete()
end

function SceneManager:getAllScenes ()
	return self.scenes
end

function SceneManager:update (dt)
	for _,scene in pairs(self:getAllScenes()) do
		if not scene:isSleeping() then
			scene:update(dt)
		end
	end
end

function SceneManager:draw ()
	for _,scene in pairs(self:getAllScenes()) do
		if not scene:isHidden() then
			scene:draw()
		end
	end
end

function SceneManager:controlpressed (set, action, key)
	for _,scene in pairs(self:getAllScenes()) do
		if not scene:isInputDisabled() then
			scene:controlpressed(set, action, key)
		end
	end
end

function SceneManager:controlreleased (set, action, key)
	for _,scene in pairs(self:getAllScenes()) do
		if not scene:isInputDisabled() then
			scene:controlreleased(set, action, key)
		end
	end
end

return SceneManager