From 29310cc9a4b29b4f758fb23d6cd963e2caa549b3 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 31 Jul 2017 19:31:17 +0200 Subject: New settings format that allows something else than controller sets --- not/Settings.lua | 29 ++++++++++++++++++++--------- settings.default | 11 +++++++---- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/not/Settings.lua b/not/Settings.lua index e3316f9..ff28e6a 100644 --- a/not/Settings.lua +++ b/not/Settings.lua @@ -4,7 +4,7 @@ Settings = { current = {} } -function Settings.load() +function Settings.load () if Controller then if not love.filesystem.exists("settings") then local def = love.filesystem.newFile("settings.default") @@ -15,9 +15,12 @@ function Settings.load() end local getSettings = love.filesystem.load("settings") Settings.current = getSettings() + if not Settings.current.sets then + Settings.current = Settings.convertToNew() + end Controller.reset() local joysticksList = love.joystick.getJoysticks() -- local list for editing - for _,set in pairs(Settings.current) do + for _,set in pairs(Settings.current.sets) do local isJoystick = set[7] local joystick if isJoystick then @@ -32,12 +35,18 @@ function Settings.load() end end -function Settings.save() +-- Converts from old settings format to the one after `02aba07e03465205b45c41df7aec6894d4e89909`. +function Settings.convertToNew () + local old = Settings.current + return {sets = old, display = "fullscreen"} +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,13 +60,15 @@ function Settings.save() end string = string .. "},\n" end - string = string .. "}" + string = string .. "\t},\n" + string = string .. "\tdisplay = \"fullscreen\",\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 @@ -65,7 +76,7 @@ function Settings.change(n, left, right, up, down, attack, jump, joystick) 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.save() -- Load settings Settings.load() diff --git a/settings.default b/settings.default index 6816116..3a5229b 100644 --- a/settings.default +++ b/settings.default @@ -1,6 +1,9 @@ return { - {"left", "right", "up", "down", "return", "rshift", false}, - {"a", "d", "w", "s", "g", "h", false}, - {"axis:leftx-", "axis:leftx+", "axis:lefty-", "axis:lefty+", "a", "b", true}, - {"axis:leftx-", "axis:leftx+", "axis:lefty-", "axis:lefty+", "a", "b", true}, + display = "fullscreen", + sets = { + {"left", "right", "up", "down", "return", "rshift", false}, + {"a", "d", "w", "s", "g", "h", false}, + {"axis:leftx-", "axis:leftx+", "axis:lefty-", "axis:lefty+", "a", "b", true}, + {"axis:leftx-", "axis:leftx+", "axis:lefty-", "axis:lefty+", "a", "b", true}, + }, } -- cgit v1.1