diff options
author | Aki <nthirtyone@gmail.com> | 2017-07-12 09:31:32 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-07-12 09:31:32 +0200 |
commit | 094f9326d1e3ae6e451b21192b288220a8fab12e (patch) | |
tree | 8f13496fea649801513178b742f3bfc21f6f676b | |
parent | 47d4e1c229adfffb70b3c984d00049bcebcfc183 (diff) | |
download | roflnauts-094f9326d1e3ae6e451b21192b288220a8fab12e.zip roflnauts-094f9326d1e3ae6e451b21192b288220a8fab12e.tar.gz roflnauts-094f9326d1e3ae6e451b21192b288220a8fab12e.tar.bz2 |
Basic SceneManager created and partialy replaced old scene managment system
-rw-r--r-- | main.lua | 20 | ||||
-rw-r--r-- | not/SceneManager.lua | 23 |
2 files changed, 28 insertions, 15 deletions
@@ -11,9 +11,17 @@ function getRealScale () return math.max(1, math.max(love.graphics.getWidth() / 320, love.graphics.getHeight() / 180)) end +-- TODO: They don't look nice like this; move them to some kind of core/game object. +musicPlayer = require "not.MusicPlayer"() +sceneManager = require "not.SceneManager"() + +-- TODO: This is a temporary wrapper! Remove all use cases of `changeScene()`. +function changeScene (scene) + sceneManager:changeScene(scene) +end + -- Require require "iconsList" -require "not.SceneManager" require "not.World" require "not.Camera" require "not.Menu" @@ -34,11 +42,11 @@ function love.load () love.graphics.setFont(Font) Controller.load() Settings.load() - Scene = Menu:new() + sceneManager:changeScene(Menu:new()) end function love.draw () - Scene:draw() + sceneManager:getScene():draw() if debug then local scale = getScale() love.graphics.setFont(Font) @@ -49,7 +57,7 @@ function love.draw () end end -function love.update (dt) Scene:update(dt) end +function love.update (dt) sceneManager:getScene():update(dt) end function love.quit () Settings.save() end -- Pass input to Controller @@ -61,12 +69,12 @@ function love.keyreleased (key) Controller.keyreleased(key) end -- Controller callbacks function Controller.controlpressed (set, action, key) - Scene:controlpressed(set, action, key) + sceneManager:getScene():controlpressed(set, action, key) if key == "f5" then debug = not debug end end function Controller.controlreleased (set, action, key) - Scene:controlreleased(set, action, key) + sceneManager:getScene():controlreleased(set, action, key) end diff --git a/not/SceneManager.lua b/not/SceneManager.lua index 755548a..367a4c0 100644 --- a/not/SceneManager.lua +++ b/not/SceneManager.lua @@ -1,12 +1,17 @@ --- Pretend you didn't see this --- This is work for scene manager --- TODO: Create SceneManager or similar class. -Scene = nil -musicPlayer = require("not.MusicPlayer")() +--- `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 changeScene (scene) - if Scene ~= nil then - Scene:delete() +function SceneManager:changeScene (scene) + if self.scene ~= nil then + self.scene:delete() end - Scene = scene + self.scene = scene end + +function SceneManager:getScene () + return self.scene +end + +return SceneManager |