From d6c6b647861414a2b04b28958ec37f9444cf330b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 16 Mar 2019 15:15:01 +0100 Subject: [PATCH] gamecore: add scene storage system --- examples/test_scene/init.lua | 1 + examples/test_scene2/init.lua | 2 +- gamecore/scenemanager.lua | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/examples/test_scene/init.lua b/examples/test_scene/init.lua index ddd8008..40dba35 100644 --- a/examples/test_scene/init.lua +++ b/examples/test_scene/init.lua @@ -35,6 +35,7 @@ function TestScene:update(dt) end function TestScene:mousepressed(x, y) + core.scenemanager:storeCurrentScene("pausedScene") examples.Test2() end diff --git a/examples/test_scene2/init.lua b/examples/test_scene2/init.lua index 1efef24..761ef09 100644 --- a/examples/test_scene2/init.lua +++ b/examples/test_scene2/init.lua @@ -35,7 +35,7 @@ function TestScene:update(dt) end function TestScene:mousepressed(x, y) - examples.Test() + core.scenemanager:setStoredScene("pausedScene") end diff --git a/gamecore/scenemanager.lua b/gamecore/scenemanager.lua index d5e3166..008d0a2 100644 --- a/gamecore/scenemanager.lua +++ b/gamecore/scenemanager.lua @@ -28,12 +28,30 @@ local SceneManager = Object:extend() function SceneManager:new(controller) self.controller = controller self.currentScene = nil + + self.storage = {} end function SceneManager:setScene(scene) self.currentScene = scene end +function SceneManager:storeCurrentScene(name) + self.storage[name] = self.currentScene +end + +function SceneManager:setStoredScene(name) + local storedScene = self.storage[name] + if storedScene ~= nil then + self.currentScene = storedScene + self.storage[name] = nil + end +end + +function SceneManager:clearStorage() + self.storage = {} +end + function SceneManager:update(dt) if (self.currentScene ~= nil) then local keys = self.controller.input.keys