-
Notifications
You must be signed in to change notification settings - Fork 68
/
config.lua
105 lines (92 loc) · 2.08 KB
/
config.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
default_config = {
scale = 3,
vsync = true,
sfx_volume = 1.0,
music_volume = 0.5,
joystick = 1,
keys = {
up = "up", down = "down", left = "left", right = "right", jump = "s", shoot = "d", action = "a"
},
joykeys = {
jump = 3, shoot = 4, action = 2
}
}
keynames = {"up","down","left","right","jump","shoot","action"}
joykeynames = {"jump","shoot","action"}
highscores = { {}, {}, {} }
keystate = {
up = false, down = false, left = false, right = false,
jump = false, shoot = false, action = false,
oldaxis1 = 0, oldaxis2 = 0
}
function loadConfig()
-- Read default settings first
config = {}
for i,v in pairs(default_config) do
if type(v) == "table" then
config[i] = {}
for j,w in pairs(v) do
config[i][j] = w
end
else
config[i] = v
end
end
if love.filesystem.exists("settings") then
local data = love.filesystem.read("settings")
local file = TSerial.unpack(data)
for i,v in pairs(file) do
config[i] = v
end
end
-- Select first open joystick if current is not open
if love.joystick.isOpen(config.joystick) == false then
config.joystick = 1
nextJoystick()
end
end
function loadHighscores()
if love.filesystem.exists("highscores") then
local data = love.filesystem.read("highscores")
local file = TSerial.unpack(data)
for i=1,3 do
if file[i] then
highscores[i] = file[i]
end
end
end
end
function saveConfig()
local data = TSerial.pack(config)
love.filesystem.write("settings", data)
end
function saveHighscores()
local data = TSerial.pack(highscores)
love.filesystem.write("highscores", data)
end
function setMode()
love.graphics.setMode(WIDTH*config.scale, HEIGHT*config.scale, false, config.vsync)
end
function toggleVSync()
config.vsync = not config.vsync
setMode()
end
function defaultKeys()
for i,v in pairs(default_config.keys) do
config.keys[i] = v
end
end
function defaultJoyKeys()
for i,v in pairs(default_config.joykeys) do
config.joykeys[i] = v
end
end
function nextJoystick()
for i=0,14 do
local pos = (config.joystick+i)%16+1
if love.joystick.isOpen(pos) then
config.joystick = pos
break
end
end
end