From af6ceef38d2b8dada3885a96fa56e78473b11827 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 24 Jan 2021 15:44:07 +0100 Subject: [PATCH] improvement: add a way to start a scene after init --- birb/core/scenemanager.lua | 15 ++++----------- birb/modules/scenes.lua | 25 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/birb/core/scenemanager.lua b/birb/core/scenemanager.lua index 5cdc189..fca5991 100644 --- a/birb/core/scenemanager.lua +++ b/birb/core/scenemanager.lua @@ -43,6 +43,7 @@ function SceneManager:setScene(scene) self:startTransition(scene) else self.currentScene = scene + self.currentScene:start() self.currentScene.isActive = true end end @@ -73,12 +74,7 @@ end function SceneManager:update(dt) self.timers:update(dt) if (self.currentScene ~= nil) then - self.currentScene:updateStart(dt) - self.currentScene:setKeys() - self.currentScene.menusystem:update(dt) - self.currentScene:updateWorld(dt) - self.currentScene:update(dt) - self.currentScene:updateEnd(dt) + self.currentScene:updateScene(dt) end end @@ -146,6 +142,7 @@ end function SceneManager:timerResponse(timer) if timer == "fadeOut" then self.currentScene = self.transition.nextScene + self.currentScene:start() self.currentScene:flushKeys(self.transition.duration / 2.5) self.currentScene.isActive = false core.screen:fadeOut(self.transition.duration / 2.5, self.transition.easeOut) @@ -162,11 +159,7 @@ end function SceneManager:draw() self.controller.screen:apply() if (self.currentScene ~= nil) then - self.currentScene:drawStart() - self.currentScene:drawWorld() - self.currentScene:draw() - self.currentScene.menusystem:draw() - self.currentScene:drawEnd() + self.currentScene:drawScene() end self.controller.screen:cease() end diff --git a/birb/modules/scenes.lua b/birb/modules/scenes.lua index 4cd67f5..f78e0aa 100644 --- a/birb/modules/scenes.lua +++ b/birb/modules/scenes.lua @@ -32,7 +32,7 @@ local MenuSystem = require(cwd .. "menusystem") -- INIT FUNCTIONS -- Initialize and configure the scene -function Scene:new() +function Scene:new(args) self.mouse = {} self.mouse.x, self.mouse.y = core.screen:getMousePosition() @@ -45,11 +45,17 @@ function Scene:new() self:flushKeys() self.isActive = false + self.args = args + self:initWorld() self:register() end +function Scene:start() + -- Empty function +end + function Scene:register() core.scenemanager:setScene(self) end @@ -61,6 +67,15 @@ end -- UPDATE FUNCTIONS -- Handle stuff that happens every steps +function Scene:updateScene(dt) + self:updateStart(dt) + self:setKeys() + self.menusystem:update(dt) + self:updateWorld(dt) + self:update(dt) + self:updateEnd(dt) +end + function Scene:updateStart(dt) end @@ -115,6 +130,14 @@ end -- DRAW FUNCTIONS -- Draw the scene and its content +function Scene:drawScene() + self:drawStart() + self:drawWorld() + self:draw() + self.menusystem:draw() + self:drawEnd() +end + function Scene:drawStart() end