2020-04-05 18:39:08 +02:00
|
|
|
-- 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")
|
2021-12-04 13:18:54 +01:00
|
|
|
|
2020-04-05 18:39:08 +02:00
|
|
|
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")
|
2020-08-09 14:51:52 +02:00
|
|
|
local MusicManager = require(cwd .. "music")
|
2021-12-04 13:18:54 +01:00
|
|
|
local DataManager = require(cwd .. "datas")
|
2020-04-05 18:39:08 +02:00
|
|
|
|
|
|
|
-- INIT FUNCTIONS
|
|
|
|
-- Initialize and configure the core object
|
|
|
|
|
2021-12-04 13:18:54 +01:00
|
|
|
function CoreSystem:new(args)
|
|
|
|
self.args = args
|
|
|
|
self:setDefaultConf()
|
2020-04-05 18:39:08 +02:00
|
|
|
|
2021-12-04 13:18:54 +01:00
|
|
|
self.debug = DebugSystem(self, self:getArg("DEBUGLEVEL", true))
|
2020-04-05 18:39:08 +02:00
|
|
|
self.options = Options(self)
|
|
|
|
self.input = Input(self)
|
|
|
|
self.screen = Screen(self)
|
|
|
|
self.scenemanager = SceneManager(self)
|
|
|
|
self.lang = Lang(self)
|
2020-08-09 14:51:52 +02:00
|
|
|
self.music = MusicManager(self)
|
2021-12-04 13:18:54 +01:00
|
|
|
self.datas = DataManager(self)
|
|
|
|
end
|
2020-05-10 14:06:20 +02:00
|
|
|
|
2021-12-04 13:18:54 +01:00
|
|
|
function CoreSystem:setDefaultConf()
|
|
|
|
self.conf = {}
|
|
|
|
self.conf.window = {}
|
|
|
|
self.conf.modules = {}
|
|
|
|
love.conf(self.conf)
|
2020-04-05 18:39:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function CoreSystem:registerGameSystem(gamesystem)
|
|
|
|
self.game = gamesystem
|
|
|
|
end
|
|
|
|
|
2020-05-10 14:21:45 +02:00
|
|
|
function CoreSystem:getDefaultConf()
|
2021-12-04 13:18:54 +01:00
|
|
|
return self.conf
|
|
|
|
end
|
2020-05-10 14:21:45 +02:00
|
|
|
|
2021-12-04 13:18:54 +01:00
|
|
|
function CoreSystem:getIdentity(versionned)
|
|
|
|
local identity = self.conf.identity or "birbengine"
|
|
|
|
if (versionned) then
|
|
|
|
local version = self.conf.gameversion or 0
|
|
|
|
identity = identity .. "-" .. version
|
|
|
|
end
|
|
|
|
return identity
|
2020-05-10 14:21:45 +02:00
|
|
|
end
|
|
|
|
|
2021-12-04 13:18:54 +01:00
|
|
|
function CoreSystem:getArg(name, isNumber)
|
|
|
|
for _, arg in ipairs(self.args) do
|
|
|
|
local argData = utils.string.split(arg, "=")
|
|
|
|
if (argData[1] == name) then
|
|
|
|
if (isNumber == true) then
|
|
|
|
return tonumber(argData[2])
|
|
|
|
else
|
|
|
|
return argData[2]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-05-10 14:21:45 +02:00
|
|
|
end
|
|
|
|
|
2020-04-05 18:39:08 +02:00
|
|
|
-- 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)
|
2021-12-04 13:18:54 +01:00
|
|
|
-- If the frameskip is to high, prefer slowdown to frameskip
|
|
|
|
local dt = math.min(dt, 1/15)
|
2020-04-05 18:39:08 +02:00
|
|
|
self.debug:update(dt)
|
|
|
|
self.input:update(dt)
|
|
|
|
|
|
|
|
if (self.game ~= nil) then
|
|
|
|
self.game:update(dt)
|
|
|
|
end
|
|
|
|
|
|
|
|
self.scenemanager:update(dt)
|
2021-12-04 13:18:54 +01:00
|
|
|
self.screen:update(dt)
|
|
|
|
self.music:update(dt)
|
2020-04-05 18:39:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- DRAW FUNCTIONS
|
|
|
|
-- Draw the whole game
|
|
|
|
|
|
|
|
function CoreSystem:draw()
|
2021-12-04 13:18:54 +01:00
|
|
|
self.scenemanager:redraw()
|
2020-04-05 18:39:08 +02:00
|
|
|
self.scenemanager:draw()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- EXIT FUNCTIONS
|
|
|
|
-- Quit the game
|
|
|
|
|
|
|
|
function CoreSystem:exit()
|
|
|
|
self.options:save()
|
|
|
|
love.event.quit()
|
|
|
|
end
|
|
|
|
|
|
|
|
return CoreSystem
|