improvement(options): have default options in conf.lua
This commit is contained in:
parent
9a0db953ba
commit
c946e582bd
5 changed files with 42 additions and 16 deletions
|
@ -132,7 +132,7 @@ end
|
||||||
-- @param string the logged string
|
-- @param string the logged string
|
||||||
-- @return the debug line
|
-- @return the debug line
|
||||||
function DebugSystem:createLogLine(level, context, string)
|
function DebugSystem:createLogLine(level, context, string)
|
||||||
local head = "BIRB" .. "|" .. os.date("%x-%X") .. "|"
|
local head = self.core:getName() .. "|" .. os.date("%x-%X") .. "|"
|
||||||
return head .. level .. "|" .. context .. ": " .. string;
|
return head .. level .. "|" .. context .. ": " .. string;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,9 @@ local SceneManager = require(cwd .. "scenemanager")
|
||||||
-- Initialize and configure the core object
|
-- Initialize and configure the core object
|
||||||
|
|
||||||
function CoreSystem:new(debugLevel)
|
function CoreSystem:new(debugLevel)
|
||||||
|
local conf = self:getDefaultConf()
|
||||||
|
self.gameName = conf.identity
|
||||||
|
|
||||||
self.modules = birb.modules
|
self.modules = birb.modules
|
||||||
|
|
||||||
self.debug = DebugSystem(self, debugLevel)
|
self.debug = DebugSystem(self, debugLevel)
|
||||||
|
@ -54,6 +57,20 @@ function CoreSystem:registerGameSystem(gamesystem)
|
||||||
self.game = gamesystem
|
self.game = gamesystem
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function CoreSystem:getDefaultConf()
|
||||||
|
local defaultConf = {}
|
||||||
|
defaultConf.window = {}
|
||||||
|
defaultConf.modules = {}
|
||||||
|
|
||||||
|
love.conf(defaultConf)
|
||||||
|
|
||||||
|
return defaultConf
|
||||||
|
end
|
||||||
|
|
||||||
|
function CoreSystem:getName()
|
||||||
|
return self.gameName
|
||||||
|
end
|
||||||
|
|
||||||
-- MOUSE FUNCTIONS
|
-- MOUSE FUNCTIONS
|
||||||
-- get directly the mouse when needed
|
-- get directly the mouse when needed
|
||||||
|
|
||||||
|
|
|
@ -31,21 +31,24 @@ local TRANSLATION_PATH = "datas/languages/"
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initialize and configure the game options
|
-- Initialize and configure the game options
|
||||||
|
|
||||||
function OptionsManager:new(controller)
|
function OptionsManager:new(core)
|
||||||
self.controller = controller
|
self.core = core
|
||||||
-- We begin by creating an empty data table before reading the data.
|
-- We begin by creating an empty data table before reading the data.
|
||||||
self.data = {}
|
self.data = {}
|
||||||
self:read()
|
self:read()
|
||||||
end
|
end
|
||||||
|
|
||||||
function OptionsManager:reset()
|
function OptionsManager:reset()
|
||||||
|
-- load the default set of config
|
||||||
|
local defaultConf = self.core:getDefaultConf()
|
||||||
|
|
||||||
-- Reset the option to the game defaults.
|
-- Reset the option to the game defaults.
|
||||||
self.data.video = {}
|
self.data.video = {}
|
||||||
self.data.video.crtfilter = false
|
self.data.video.crtfilter = false
|
||||||
self.data.video.resolution = 1
|
self.data.video.resolution = defaultConf.window.resolution
|
||||||
self.data.video.border = true
|
self.data.video.borderless = defaultConf.window.borderless
|
||||||
self.data.video.vsync = true
|
self.data.video.vsync = defaultConf.window.vsync
|
||||||
self.data.video.fullscreen = false
|
self.data.video.fullscreen = defaultConf.window.fullscreen
|
||||||
|
|
||||||
-- We load the default files
|
-- We load the default files
|
||||||
self.data.input = self:getInputDefaultData()
|
self.data.input = self:getInputDefaultData()
|
||||||
|
@ -54,8 +57,8 @@ function OptionsManager:reset()
|
||||||
self.data.language = self:getTranslationDefaultData()
|
self.data.language = self:getTranslationDefaultData()
|
||||||
|
|
||||||
self.data.audio = {}
|
self.data.audio = {}
|
||||||
self.data.audio.music = 100
|
self.data.audio.music = defaultConf.volume.music
|
||||||
self.data.audio.sfx = 100
|
self.data.audio.sfx = defaultConf.volume.sfx
|
||||||
end
|
end
|
||||||
|
|
||||||
-- INFO FUNCTIONS
|
-- INFO FUNCTIONS
|
||||||
|
@ -129,9 +132,9 @@ function OptionsManager:getTranslationDefaultData()
|
||||||
end
|
end
|
||||||
|
|
||||||
function OptionsManager:setLanguage(lang)
|
function OptionsManager:setLanguage(lang)
|
||||||
if (self.controller.lang:isLangAvailable(lang)) then
|
if (self.core.lang:isLangAvailable(lang)) then
|
||||||
self.data.language.current = lang
|
self.data.language.current = lang
|
||||||
self.controller.lang:getTranslationData()
|
self.core.lang:getTranslationData()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -151,11 +154,11 @@ function OptionsManager:read()
|
||||||
filepath = self:getFile(true)
|
filepath = self:getFile(true)
|
||||||
if utils.filesystem.exists("options.data") then
|
if utils.filesystem.exists("options.data") then
|
||||||
local loadedDatas = binser.readFile(filepath)
|
local loadedDatas = binser.readFile(filepath)
|
||||||
self.controller.debug:logInfo("core/options", "data file found, loading it")
|
self.core.debug:logInfo("core/options", "data file found, loading it")
|
||||||
self:setData(loadedDatas[1])
|
self:setData(loadedDatas[1])
|
||||||
else
|
else
|
||||||
self:reset()
|
self:reset()
|
||||||
self.controller.debug:logInfo("core/options", "no data file found, reseting data")
|
self.core.debug:logInfo("core/options", "no data file found, reseting data")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ function ScreenManager:applySettings()
|
||||||
|
|
||||||
local flags = {}
|
local flags = {}
|
||||||
flags.vsync = self.data.vsync
|
flags.vsync = self.data.vsync
|
||||||
flags.borderless = (self.data.border == false)
|
flags.borderless = (self.data.borderless)
|
||||||
|
|
||||||
love.window.setMode(self.width * self.data.resolution, self.height * self.data.resolution, flags)
|
love.window.setMode(self.width * self.data.resolution, self.height * self.data.resolution, flags)
|
||||||
love.window.setFullscreen( self.data.fullscreen )
|
love.window.setFullscreen( self.data.fullscreen )
|
||||||
|
|
|
@ -4,11 +4,12 @@ function love.conf(t)
|
||||||
t.console = false -- Attach a console (boolean, Windows only)
|
t.console = false -- Attach a console (boolean, Windows only)
|
||||||
t.accelerometerjoystick = false -- Enable the accelerometer on iOS and Android by exposing it as a Joystick (boolean)
|
t.accelerometerjoystick = false -- Enable the accelerometer on iOS and Android by exposing it as a Joystick (boolean)
|
||||||
t.gammacorrect = false -- Enable gamma-correct rendering, when supported by the system (boolean)
|
t.gammacorrect = false -- Enable gamma-correct rendering, when supported by the system (boolean)
|
||||||
|
t.debugLevel = 4 -- Debug level mode : 0=Error only, 3=Everything.
|
||||||
|
|
||||||
t.window.title = "Birb Engine Examples" -- The window title (string)
|
t.window.title = "Birb Engine Examples" -- The window title (string)
|
||||||
t.window.icon = nil -- Filepath to an image to use as the window's icon (string)
|
t.window.icon = nil -- Filepath to an image to use as the window's icon (string)
|
||||||
t.window.width = 424 -- The window width (number)
|
t.window.width = 424 -- The window internal width (number)
|
||||||
t.window.height = 240 -- The window height (number)
|
t.window.height = 240 -- The window internal height (number)
|
||||||
t.window.borderless = false -- Remove all border visuals from the window (boolean)
|
t.window.borderless = false -- Remove all border visuals from the window (boolean)
|
||||||
t.window.resizable = false -- Let the window be user-resizable (boolean)
|
t.window.resizable = false -- Let the window be user-resizable (boolean)
|
||||||
t.window.minwidth = 1 -- Minimum window width if the window is resizable (number)
|
t.window.minwidth = 1 -- Minimum window width if the window is resizable (number)
|
||||||
|
@ -21,6 +22,11 @@ function love.conf(t)
|
||||||
t.window.highdpi = false -- Enable high-dpi mode for the window on a Retina display (boolean)
|
t.window.highdpi = false -- Enable high-dpi mode for the window on a Retina display (boolean)
|
||||||
t.window.x = nil -- The x-coordinate of the window's position in the specified display (number)
|
t.window.x = nil -- The x-coordinate of the window's position in the specified display (number)
|
||||||
t.window.y = nil -- The y-coordinate of the window's position in the specified display (number)
|
t.window.y = nil -- The y-coordinate of the window's position in the specified display (number)
|
||||||
|
t.window.resolution = 2 -- The default resolution
|
||||||
|
|
||||||
|
t.volume = {}
|
||||||
|
t.volume.music = 100 -- music audio volume
|
||||||
|
t.volume.sfx = 100 -- sfx audio volume
|
||||||
|
|
||||||
t.modules.audio = true -- Enable the audio module (boolean)
|
t.modules.audio = true -- Enable the audio module (boolean)
|
||||||
t.modules.event = true -- Enable the event module (boolean)
|
t.modules.event = true -- Enable the event module (boolean)
|
||||||
|
|
Loading…
Reference in a new issue