summaryrefslogtreecommitdiffhomepage
path: root/not/SceneManager.lua
diff options
context:
space:
mode:
Diffstat (limited to 'not/SceneManager.lua')
-rw-r--r--not/SceneManager.lua62
1 files changed, 62 insertions, 0 deletions
diff --git a/not/SceneManager.lua b/not/SceneManager.lua
new file mode 100644
index 0000000..c076448
--- /dev/null
+++ b/not/SceneManager.lua
@@ -0,0 +1,62 @@
+--- `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)
+ table.remove(self.scenes, #self.scenes)
+ return self:addScene(scene)
+end
+
+function SceneManager:addScene (scene)
+ table.insert(self.scenes, scene)
+ return scene
+end
+
+-- Not nice, not nice.
+function SceneManager:removeTopScene ()
+ table.remove(self.scenes, #self.scenes)
+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