From 84f483f6b47b2c5fa3de79b1716259f358ddee7d Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 5 May 2021 08:53:54 +0200 Subject: [PATCH] chore: separate birbcore in its own subfolder --- .vscode/settings.json | 3 +- sonic-radiance.love/birb/callbacks.lua | 3 + sonic-radiance.love/birb/{ => core}/debug.lua | 3 +- sonic-radiance.love/birb/core/init.lua | 111 ++++++++++++++++++ sonic-radiance.love/birb/{ => core}/input.lua | 0 sonic-radiance.love/birb/{ => core}/lang.lua | 0 .../birb/{ => core}/options.lua | 3 +- .../birb/{ => core}/scenemanager.lua | 0 .../birb/{ => core}/screen.lua | 3 +- sonic-radiance.love/birb/init.lua | 101 +++------------- sonic-radiance.love/main.lua | 15 +-- 11 files changed, 137 insertions(+), 105 deletions(-) rename sonic-radiance.love/birb/{ => core}/debug.lua (95%) create mode 100644 sonic-radiance.love/birb/core/init.lua rename sonic-radiance.love/birb/{ => core}/input.lua (100%) rename sonic-radiance.love/birb/{ => core}/lang.lua (100%) rename sonic-radiance.love/birb/{ => core}/options.lua (98%) rename sonic-radiance.love/birb/{ => core}/scenemanager.lua (100%) rename sonic-radiance.love/birb/{ => core}/screen.lua (97%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 2f0c7a5..93c0adf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,7 @@ "game", "core", "scenes", - "utils" + "utils", + "birb" ] } diff --git a/sonic-radiance.love/birb/callbacks.lua b/sonic-radiance.love/birb/callbacks.lua index 8b3f122..30d4463 100644 --- a/sonic-radiance.love/birb/callbacks.lua +++ b/sonic-radiance.love/birb/callbacks.lua @@ -23,6 +23,9 @@ function love.update(dt) core:update(dt) + if (game ~= nil) then + game:update(dt) + end end function love.draw() diff --git a/sonic-radiance.love/birb/debug.lua b/sonic-radiance.love/birb/core/debug.lua similarity index 95% rename from sonic-radiance.love/birb/debug.lua rename to sonic-radiance.love/birb/core/debug.lua index a1cecb7..26c797d 100644 --- a/sonic-radiance.love/birb/debug.lua +++ b/sonic-radiance.love/birb/core/debug.lua @@ -23,8 +23,7 @@ local DebugSystem = Object:extend() -local cwd = (...):gsub('%.debug$', '') .. "." -local lovebird = require(cwd .. "libs.lovebird") +local lovebird = require "birb.libs.lovebird" function DebugSystem:new(controller, active) self.controller = controller diff --git a/sonic-radiance.love/birb/core/init.lua b/sonic-radiance.love/birb/core/init.lua new file mode 100644 index 0000000..2ecefee --- /dev/null +++ b/sonic-radiance.love/birb/core/init.lua @@ -0,0 +1,111 @@ +-- core/init.lua :: The main file of the core system, an object full of subsystem +-- loaded by the game to handle the main functions (like screen, translation, +-- inputs…) + +--[[ + Copyright © 2019 Kazhnuz + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +]] + +local cwd = (...):gsub('%.init$', '') .. "." + +local CoreSystem = Object:extend() + +local DebugSystem = require(cwd .. "debug") + +local Options = require(cwd .. "options") +local Input = require(cwd .. "input") +local Screen = require(cwd .. "screen") +local Lang = require(cwd .. "lang") +local SceneManager = require(cwd .. "scenemanager") + +-- INIT FUNCTIONS +-- Initialize and configure the core object + +function CoreSystem:new(isDebug) + self.debug = DebugSystem(self, isDebug) + self.options = Options(self) + self.input = Input(self) + self.screen = Screen(self) + self.scenemanager = SceneManager(self) + self.lang = Lang(self) +end + +function CoreSystem:registerGameSystem(gamesystem) + self.game = gamesystem +end + +-- MOUSE FUNCTIONS +-- get directly the mouse when needed + +function CoreSystem:mousemoved(x, y, dx, dy) + local x, y = self.screen:project(x, y) + local dx, dy = self.screen:project(dx, dy) + self.scenemanager:mousemoved(x, y, dx, dy) +end + +function CoreSystem:mousepressed( x, y, button, istouch ) + local x, y = self.screen:project(x, y) + self.scenemanager:mousepressed( x, y, button, istouch ) +end + +-- KEYBOARD FUNCTIONS +-- get directly the keyboard when needed + +function CoreSystem:keypressed( key, scancode, isrepeat ) + self.scenemanager:keypressed( key, scancode, isrepeat ) +end + +function CoreSystem:keyreleased( key ) + self.scenemanager:keyreleased( key ) +end + +-- UPDATE FUNCTIONS +-- Load every sytem every update functions of the scene and objects + +function CoreSystem:update(dt) + -- If the frameskip is to high, prefer slowdown to frameskip + local dt = math.min(dt, 1/15) + self.debug:update(dt) + self.input:update(dt) + + if (self.game ~= nil) then + self.game:update(dt) + end + + self.scenemanager:update(dt) + self.screen:update(dt) +end + +-- DRAW FUNCTIONS +-- Draw the whole game + +function CoreSystem:draw() + self.scenemanager:draw() +end + +-- EXIT FUNCTIONS +-- Quit the game + +function CoreSystem:exit() + self.options:save() + love.event.quit() +end + +return CoreSystem diff --git a/sonic-radiance.love/birb/input.lua b/sonic-radiance.love/birb/core/input.lua similarity index 100% rename from sonic-radiance.love/birb/input.lua rename to sonic-radiance.love/birb/core/input.lua diff --git a/sonic-radiance.love/birb/lang.lua b/sonic-radiance.love/birb/core/lang.lua similarity index 100% rename from sonic-radiance.love/birb/lang.lua rename to sonic-radiance.love/birb/core/lang.lua diff --git a/sonic-radiance.love/birb/options.lua b/sonic-radiance.love/birb/core/options.lua similarity index 98% rename from sonic-radiance.love/birb/options.lua rename to sonic-radiance.love/birb/core/options.lua index c958e1c..8fc2637 100644 --- a/sonic-radiance.love/birb/options.lua +++ b/sonic-radiance.love/birb/core/options.lua @@ -24,8 +24,7 @@ local OptionsManager = Object:extend() -local cwd = (...):gsub('%.options$', '') .. "." -local binser = require(cwd .. "libs.binser") +local binser = require("birb.libs.binser") local TRANSLATION_PATH = "datas/languages/" diff --git a/sonic-radiance.love/birb/scenemanager.lua b/sonic-radiance.love/birb/core/scenemanager.lua similarity index 100% rename from sonic-radiance.love/birb/scenemanager.lua rename to sonic-radiance.love/birb/core/scenemanager.lua diff --git a/sonic-radiance.love/birb/screen.lua b/sonic-radiance.love/birb/core/screen.lua similarity index 97% rename from sonic-radiance.love/birb/screen.lua rename to sonic-radiance.love/birb/core/screen.lua index c943b32..16651b9 100644 --- a/sonic-radiance.love/birb/screen.lua +++ b/sonic-radiance.love/birb/core/screen.lua @@ -24,8 +24,7 @@ local ScreenManager = Object:extend() -local cwd = (...):gsub('%.screen$', '') .. "." -local CScreen = require(cwd .. "libs.cscreen") +local CScreen = require("birb.libs.cscreen") -- INIT FUNCTIONS -- Initialize and configure the screen manager diff --git a/sonic-radiance.love/birb/init.lua b/sonic-radiance.love/birb/init.lua index 5b45336..dd35cec 100644 --- a/sonic-radiance.love/birb/init.lua +++ b/sonic-radiance.love/birb/init.lua @@ -1,9 +1,7 @@ --- core/init.lua :: The main file of the core system, an object full of subsystem --- loaded by the game to handle the main functions (like screen, translation, --- inputs…) +-- birb :: The main birb script, loading the core and main utilities --[[ - Copyright © 2019 Kazhnuz + Copyright © 2021 Kazhnuz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -23,98 +21,31 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] -local cwd = (...):gsub('%.init$', '') .. "." +birb = {} -- GLOBAL UTILS/FUNCTION LOADING -- Load in the global namespace utilities that'll need to be reusable everywhere -- in the game -Object = require(cwd .. "libs.classic") -utils = require(cwd .. "utils") +Object = require("birb.libs.classic") +utils = require("birb.utils") -local CoreSystem = Object:extend() +birb.Core = require("birb.core") -local DebugSystem = require(cwd .. "debug") - -local Options = require(cwd .. "options") -local Input = require(cwd .. "input") -local Screen = require(cwd .. "screen") -local Lang = require(cwd .. "lang") -local SceneManager = require(cwd .. "scenemanager") - -require(cwd .. "callbacks") - --- INIT FUNCTIONS --- Initialize and configure the core object - -function CoreSystem:new(DEBUGMODE) - self.debug = DebugSystem(self, DEBUGMODE) - self.options = Options(self) - self.input = Input(self) - self.screen = Screen(self) - self.scenemanager = SceneManager(self) - self.lang = Lang(self) -end - -function CoreSystem:registerGameSystem(gamesystem) - self.game = gamesystem -end - --- MOUSE FUNCTIONS --- get directly the mouse when needed - -function CoreSystem:mousemoved(x, y, dx, dy) - local x, y = self.screen:project(x, y) - local dx, dy = self.screen:project(dx, dy) - self.scenemanager:mousemoved(x, y, dx, dy) -end - -function CoreSystem:mousepressed( x, y, button, istouch ) - local x, y = self.screen:project(x, y) - self.scenemanager:mousepressed( x, y, button, istouch ) -end - --- KEYBOARD FUNCTIONS --- get directly the keyboard when needed - -function CoreSystem:keypressed( key, scancode, isrepeat ) - self.scenemanager:keypressed( key, scancode, isrepeat ) -end - -function CoreSystem:keyreleased( key ) - self.scenemanager:keyreleased( key ) -end - --- UPDATE FUNCTIONS --- Load every sytem every update functions of the scene and objects - -function CoreSystem:update(dt) - -- If the frameskip is to high, prefer slowdown to frameskip - local dt = math.min(dt, 1/15) - self.debug:update(dt) - self.input:update(dt) - - if (self.game ~= nil) then - self.game:update(dt) +function birb.start(gamemodule, isDebug) + birb.startCore((isDebug == true)) + if (gamemodule ~= nil) then + birb.startGame(gamemodule) end - - self.scenemanager:update(dt) - self.screen:update(dt) end --- DRAW FUNCTIONS --- Draw the whole game - -function CoreSystem:draw() - self.scenemanager:draw() +function birb.startCore(isDebug) + core = birb.Core(isDebug) end --- EXIT FUNCTIONS --- Quit the game - -function CoreSystem:exit() - self.options:save() - love.event.quit() +function birb.startGame(gamemodule) + local GameObject = require(gamemodule) + game = GameObject() end -return CoreSystem +require("birb.callbacks") \ No newline at end of file diff --git a/sonic-radiance.love/main.lua b/sonic-radiance.love/main.lua index f5ac7e1..9d35653 100644 --- a/sonic-radiance.love/main.lua +++ b/sonic-radiance.love/main.lua @@ -21,22 +21,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] -local Core = require "birb" -local Game = require "game" +require "birb" scenes = require "scenes" function love.load() - core = Core(true) - game = Game() + birb.start("game", false) scenes.title() -end - -function love.update(dt) - core:update(dt) - game:update(dt) -end - -function love.draw() - core:draw() end \ No newline at end of file