From 9f4c057a277bea42828efbe3fea14032b6002226 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 5 Apr 2020 18:39:08 +0200 Subject: [PATCH] chore: place the birb core in a separate folder --- birb/{ => core}/debug.lua | 3 +- birb/core/init.lua | 111 ++++++++++++++++++ birb/{ => core}/input.lua | 0 birb/{ => core}/lang.lua | 0 birb/{ => core}/options.lua | 3 +- birb/{ => core}/scenemanager.lua | 0 birb/{ => core}/screen.lua | 3 +- birb/init.lua | 101 ++-------------- birb/{modules/gamesystem => }/libs/binser.lua | 0 birb/modules/gamesystem/init.lua | 3 +- examples/main.lua | 4 +- 11 files changed, 127 insertions(+), 101 deletions(-) rename birb/{ => core}/debug.lua (95%) create mode 100644 birb/core/init.lua rename birb/{ => core}/input.lua (100%) rename birb/{ => core}/lang.lua (100%) rename birb/{ => core}/options.lua (97%) rename birb/{ => core}/scenemanager.lua (100%) rename birb/{ => core}/screen.lua (97%) rename birb/{modules/gamesystem => }/libs/binser.lua (100%) diff --git a/birb/debug.lua b/birb/core/debug.lua similarity index 95% rename from birb/debug.lua rename to birb/core/debug.lua index 0c1097a..53d62f2 100644 --- a/birb/debug.lua +++ b/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/birb/core/init.lua b/birb/core/init.lua new file mode 100644 index 0000000..21dd59e --- /dev/null +++ b/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(DEBUGMODE) + self.modules = birb.modules + + 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) + self.debug:update(dt) + self.input:update(dt) + self.screen:update(dt) + + if (self.game ~= nil) then + self.game:update(dt) + end + + self.scenemanager:update(dt) +end + +-- DRAW FUNCTIONS +-- Draw the whole game + +function CoreSystem:draw() + self.scenemanager:draw() + self.screen:drawFade() +end + +-- EXIT FUNCTIONS +-- Quit the game + +function CoreSystem:exit() + self.options:save() + love.event.quit() +end + +return CoreSystem diff --git a/birb/input.lua b/birb/core/input.lua similarity index 100% rename from birb/input.lua rename to birb/core/input.lua diff --git a/birb/lang.lua b/birb/core/lang.lua similarity index 100% rename from birb/lang.lua rename to birb/core/lang.lua diff --git a/birb/options.lua b/birb/core/options.lua similarity index 97% rename from birb/options.lua rename to birb/core/options.lua index 28b8efb..0067e62 100644 --- a/birb/options.lua +++ b/birb/core/options.lua @@ -24,8 +24,7 @@ local OptionsManager = Object:extend() -local cwd = (...):gsub('%.options$', '') .. "." -local binser = require(cwd .. "modules.gamesystem.libs.binser") +local binser = require("birb.libs.binser") local TRANSLATION_PATH = "datas/languages/" diff --git a/birb/scenemanager.lua b/birb/core/scenemanager.lua similarity index 100% rename from birb/scenemanager.lua rename to birb/core/scenemanager.lua diff --git a/birb/screen.lua b/birb/core/screen.lua similarity index 97% rename from birb/screen.lua rename to birb/core/screen.lua index 7a39c22..82b601e 100644 --- a/birb/screen.lua +++ b/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/birb/init.lua b/birb/init.lua index b172785..a43f79f 100644 --- a/birb/init.lua +++ b/birb/init.lua @@ -1,6 +1,5 @@ --- 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/init.lua :: The main file of birb, that initilize the whole birb engine +-- It basically works by loading everything needed for a full birb experience. --[[ Copyright © 2019 Kazhnuz @@ -23,100 +22,20 @@ 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.modules = require("birb.modules") +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") - -local modules = require(cwd .. "modules") - -require(cwd .. "callbacks") - --- INIT FUNCTIONS --- Initialize and configure the core object - -function CoreSystem:new(DEBUGMODE) - self.modules = modules - - 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) +function birb.startCore() + core = birb.Core(true) 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) - self.debug:update(dt) - self.input:update(dt) - self.screen:update(dt) - - if (self.game ~= nil) then - self.game:update(dt) - end - - self.scenemanager:update(dt) -end - --- DRAW FUNCTIONS --- Draw the whole game - -function CoreSystem:draw() - self.scenemanager:draw() - self.screen:drawFade() -end - --- EXIT FUNCTIONS --- Quit the game - -function CoreSystem:exit() - self.options:save() - love.event.quit() -end - -return CoreSystem +require("birb.callbacks") diff --git a/birb/modules/gamesystem/libs/binser.lua b/birb/libs/binser.lua similarity index 100% rename from birb/modules/gamesystem/libs/binser.lua rename to birb/libs/binser.lua diff --git a/birb/modules/gamesystem/init.lua b/birb/modules/gamesystem/init.lua index c3c7fe8..82b0649 100644 --- a/birb/modules/gamesystem/init.lua +++ b/birb/modules/gamesystem/init.lua @@ -26,10 +26,9 @@ ]] local cwd = (...):gsub('%.init$', '') .. "." -local cwd2 = (...):gsub('%.gamesystem.init$', '') .. "." local GameSystem = Object:extend() -local binser = require(cwd2 .. "libs.binser") +local binser = require("birb.libs.binser") local DEFAULT_SAVENUMBER = 3 diff --git a/examples/main.lua b/examples/main.lua index 47d0c30..b0f6ba0 100644 --- a/examples/main.lua +++ b/examples/main.lua @@ -21,12 +21,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] -Core = require "birb" +require "birb" Game = require "game" scenes = require "scenes" function love.load() - core = Core(true) + birb.startCore() game = Game() game:read(1)