summaryrefslogtreecommitdiffhomepage
path: root/settings.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-12-20 06:02:05 +0100
committerAki <nthirtyone@gmail.com>2016-12-20 06:02:05 +0100
commit73bcd524906c51d43b22b3ea68c64b38f130bea6 (patch)
tree998fe4fd04f901e411e366f4acdf142afe302a88 /settings.lua
parent941d0214a4a1b499190f4f3c6133b5e512d897fe (diff)
downloadroflnauts-73bcd524906c51d43b22b3ea68c64b38f130bea6.zip
roflnauts-73bcd524906c51d43b22b3ea68c64b38f130bea6.tar.gz
roflnauts-73bcd524906c51d43b22b3ea68c64b38f130bea6.tar.bz2
I have no idea why I have put everything in one commit
Diffstat (limited to 'settings.lua')
-rw-r--r--settings.lua46
1 files changed, 42 insertions, 4 deletions
diff --git a/settings.lua b/settings.lua
index 93432a0..ad8b8e5 100644
--- a/settings.lua
+++ b/settings.lua
@@ -1,5 +1,5 @@
Settings = {}
-
+Settings.current = {}
function Settings.load()
if Controller then
if not love.filesystem.exists("settings") then
@@ -10,12 +10,15 @@ function Settings.load()
new:close() def:close()
end
local getSettings = love.filesystem.load("settings")
- for _,set in pairs(getSettings()) do
+ Settings.current = getSettings()
+ local joysticksList = love.joystick.getJoysticks() -- local list for editing
+ for _,set in pairs(Settings.current) do
local isJoystick = set[7]
local joystick
if isJoystick then
- joystick = love.joystick.getJoysticks()[1]
- -- Add first free joystick from joysticks list
+ -- take and remove first joystick from list
+ joystick = joysticksList[1]
+ 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)
@@ -23,3 +26,38 @@ function Settings.load()
end
end
end
+function Settings.save()
+ local new = love.filesystem.newFile("settings")
+ local sets = Settings.current
+ local string = "return {\n"
+ for i,set in pairs(sets) do
+ string = string .. "\t{"
+ for j,word in pairs(set) do
+ if j ~= 7 then
+ string = string .. "\"" .. word .. "\", "
+ else
+ if word then
+ string = string .. "true"
+ else
+ string = string .. "false"
+ end
+ end
+ end
+ string = string .. "},\n"
+ end
+ string = string .. "}"
+ new:open("w")
+ new:write(string)
+ new:close()
+end
+function Settings.change(n, left, right, up, down, attack, jump, joystick)
+ local bool
+ if joystick then
+ bool = true
+ else
+ bool = false
+ end
+ Settings.current[n] = {left, right, up, down, attack, jump, bool}
+ table.remove(Controller.sets, n)
+ Controller.registerSet(left, right, up, down, attack, jump, joystick)
+end \ No newline at end of file