summaryrefslogtreecommitdiffhomepage
path: root/not/Settings.lua
diff options
context:
space:
mode:
Diffstat (limited to 'not/Settings.lua')
-rw-r--r--not/Settings.lua90
1 files changed, 66 insertions, 24 deletions
diff --git a/not/Settings.lua b/not/Settings.lua
index e3316f9..ca429eb 100644
--- a/not/Settings.lua
+++ b/not/Settings.lua
@@ -4,26 +4,39 @@ Settings = {
current = {}
}
-function Settings.load()
+-- Converts from old settings format to the one after `02aba07e03465205b45c41df7aec6894d4e89909`.
+local function convertToNew (old)
+ return {sets = old, display = "fullscreen"}
+end
+
+local function filePrepare ()
+ if not love.filesystem.exists("settings") then
+ local def = love.filesystem.newFile("settings.default")
+ local new = love.filesystem.newFile("settings")
+ new:open("w") def:open("r")
+ new:write(def:read())
+ new:close() def:close()
+ end
+end
+
+local function fileLoad ()
+ local getSettings = love.filesystem.load("settings")
+ local settings = getSettings()
+ if not settings.sets then
+ settings = convertToNew(settings)
+ end
+ Settings.current = settings
+end
+
+local function controllerLoad ()
if Controller then
- if not love.filesystem.exists("settings") then
- local def = love.filesystem.newFile("settings.default")
- local new = love.filesystem.newFile("settings")
- new:open("w") def:open("r")
- new:write(def:read())
- new:close() def:close()
- end
- local getSettings = love.filesystem.load("settings")
- Settings.current = getSettings()
Controller.reset()
- local joysticksList = love.joystick.getJoysticks() -- local list for editing
- for _,set in pairs(Settings.current) do
+ local joysticksList = love.joystick.getJoysticks()
+ for _,set in pairs(Settings.current.sets) do
local isJoystick = set[7]
local joystick
if isJoystick then
- -- take and remove first joystick from list
- joystick = joysticksList[1]
- table.remove(joysticksList, 1)
+ joystick = table.remove(joysticksList, 1)
end
if not isJoystick or joystick then
Controller.registerSet(set[1], set[2], set[3], set[4], set[5], set[6], joystick)
@@ -32,12 +45,37 @@ function Settings.load()
end
end
-function Settings.save()
+local function displayLoad ()
+ local width, height, flags = love.window.getMode()
+ if Settings.current.display == "fullscreen" then
+ if not flags.fullscreen then
+ love.window.setFullscreen(true, "desktop")
+ end
+ else
+ local scale = tonumber(Settings.current.display) or 1
+ local expectedWidth, expectedHeight = 320 * scale, 180 * scale
+ if flags.fullscreen then
+ love.window.setFullscreen(false)
+ end
+ if width ~= expectedWidth or height ~= expectedHeight then
+ love.window.setMode(expectedWidth, expectedHeight)
+ end
+ end
+end
+
+function Settings.load ()
+ filePrepare()
+ fileLoad()
+ controllerLoad()
+ displayLoad()
+end
+
+function Settings.save ()
local new = love.filesystem.newFile("settings")
- local sets = Settings.current
- local string = "return {\n"
+ local sets = Settings.current.sets
+ local string = "return {\n\tsets = {\n"
for i,set in pairs(sets) do
- string = string .. "\t{"
+ string = string .. "\t\t{"
for j,word in pairs(set) do
if j ~= 7 then
string = string .. "\"" .. word .. "\", "
@@ -51,22 +89,26 @@ function Settings.save()
end
string = string .. "},\n"
end
- string = string .. "}"
+ string = string .. "\t},\n"
+ string = string .. "\tdisplay = \"" .. Settings.current.display .. "\",\n"
+ string = string .. "}\n"
new:open("w")
new:write(string)
new:close()
end
-function Settings.change(n, left, right, up, down, attack, jump, joystick)
+function Settings.change (n, left, right, up, down, attack, jump, joystick)
local bool
if joystick then
bool = true
else
bool = false
end
- -- Save current settings
- Settings.current[n] = {left, right, up, down, attack, jump, bool}
+ Settings.current.sets[n] = {left, right, up, down, attack, jump, bool}
+ Settings.reload()
+end
+
+function Settings.reload ()
Settings.save()
- -- Load settings
Settings.load()
end