improvement(options): have default options in conf.lua

This commit is contained in:
Kazhnuz 2020-05-10 14:21:45 +02:00
parent 9a0db953ba
commit c946e582bd
5 changed files with 42 additions and 16 deletions

View file

@ -132,7 +132,7 @@ end
-- @param string the logged string
-- @return the debug line
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;
end

View file

@ -38,6 +38,9 @@ local SceneManager = require(cwd .. "scenemanager")
-- Initialize and configure the core object
function CoreSystem:new(debugLevel)
local conf = self:getDefaultConf()
self.gameName = conf.identity
self.modules = birb.modules
self.debug = DebugSystem(self, debugLevel)
@ -54,6 +57,20 @@ function CoreSystem:registerGameSystem(gamesystem)
self.game = gamesystem
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
-- get directly the mouse when needed

View file

@ -31,21 +31,24 @@ local TRANSLATION_PATH = "datas/languages/"
-- INIT FUNCTIONS
-- Initialize and configure the game options
function OptionsManager:new(controller)
self.controller = controller
function OptionsManager:new(core)
self.core = core
-- We begin by creating an empty data table before reading the data.
self.data = {}
self:read()
end
function OptionsManager:reset()
-- load the default set of config
local defaultConf = self.core:getDefaultConf()
-- Reset the option to the game defaults.
self.data.video = {}
self.data.video.crtfilter = false
self.data.video.resolution = 1
self.data.video.border = true
self.data.video.vsync = true
self.data.video.fullscreen = false
self.data.video.resolution = defaultConf.window.resolution
self.data.video.borderless = defaultConf.window.borderless
self.data.video.vsync = defaultConf.window.vsync
self.data.video.fullscreen = defaultConf.window.fullscreen
-- We load the default files
self.data.input = self:getInputDefaultData()
@ -54,8 +57,8 @@ function OptionsManager:reset()
self.data.language = self:getTranslationDefaultData()
self.data.audio = {}
self.data.audio.music = 100
self.data.audio.sfx = 100
self.data.audio.music = defaultConf.volume.music
self.data.audio.sfx = defaultConf.volume.sfx
end
-- INFO FUNCTIONS
@ -129,9 +132,9 @@ function OptionsManager:getTranslationDefaultData()
end
function OptionsManager:setLanguage(lang)
if (self.controller.lang:isLangAvailable(lang)) then
if (self.core.lang:isLangAvailable(lang)) then
self.data.language.current = lang
self.controller.lang:getTranslationData()
self.core.lang:getTranslationData()
end
end
@ -151,11 +154,11 @@ function OptionsManager:read()
filepath = self:getFile(true)
if utils.filesystem.exists("options.data") then
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])
else
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

View file

@ -49,7 +49,7 @@ function ScreenManager:applySettings()
local flags = {}
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.setFullscreen( self.data.fullscreen )

View file

@ -4,11 +4,12 @@ function love.conf(t)
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.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.icon = nil -- Filepath to an image to use as the window's icon (string)
t.window.width = 424 -- The window width (number)
t.window.height = 240 -- The window height (number)
t.window.width = 424 -- The window internal width (number)
t.window.height = 240 -- The window internal height (number)
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.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.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.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.event = true -- Enable the event module (boolean)