gamecore: avoid crashes when there is no data for translation or inputs

This commit is contained in:
Kazhnuz 2019-03-16 14:41:31 +01:00
parent 56349c277f
commit f3855c5539
3 changed files with 39 additions and 3 deletions

View file

@ -26,7 +26,7 @@ local InputManager = Object:extend()
function InputManager:new(controller)
self.controller = controller
self.data = self.controller.options.data.input[1]
self.data = self.controller.options:getPlayerInputData(1)
self.keys = self:getKeyList()
self.fakekeys = self:getKeyList()

View file

@ -23,11 +23,22 @@
]]
local LanguageManager = Object:extend()
local langs = require "datas.languages"
function LanguageManager:new(controller)
self.controller = controller
self:setLang(self.controller.options.data.language)
self:getTranslationData()
end
function LanguageManager:getTranslationData()
local _path = "datas/languages/init.lua"
local fileinfo = love.filesystem.getInfo(_path)
if fileinfo ~= nil then
self.datas = require "datas.languages"
else
self.datas = nil
end
end
function LanguageManager:getStringList(library, file)

View file

@ -43,7 +43,7 @@ function OptionsManager:reset()
self.data.video.fullscreen = false
-- We load the default files
self.data.input = require "datas.inputs"
self.data.input = self:getInputDefaultData()
-- TODO: have a way to auto-load a language according to the OS ?
self.data.language = "en"
@ -67,6 +67,31 @@ function OptionsManager:getFile(absolute)
return filepath
end
function OptionsManager:getInputDefaultData()
local _path = "datas/inputs.lua"
local datas = {}
local fileinfo = love.filesystem.getInfo(_path)
if fileinfo ~= nil then
datas = require "datas.inputs"
else
datas = {}
end
return datas
end
function OptionsManager:getPlayerInputData(id)
local _playerInputData = self.data.input[id]
if _playerInputData == nil then
_playerInputData = {}
_playerInputData.keys = {}
end
return _playerInputData
end
function OptionsManager:write()
local data = self:getData()