File: config.lua

package info (click to toggle)
mrrescue 1.02e-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,228 kB
  • sloc: makefile: 9; sh: 1
file content (115 lines) | stat: -rw-r--r-- 2,727 bytes parent folder | download
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
106
107
108
109
110
111
112
113
114
115
default_config = {
	scale = 3,
	fullscreen = 0,
	vsync = true,
	sfx_volume = 1.0,
	music_volume = 0.5,
	keys = {
			up = "up", down = "down", left = "left", right = "right", jump = "s", shoot = "d", action = "a"
	},
	joykeys = {
		jump = 1, shoot = 3, action = 2, pause = 8
	}
}

keynames = {"up","down","left","right","jump","shoot","action"}
joykeynames = {"jump","shoot","action","pause"}

highscores = { {}, {}, {} }

stats = { 0, 0, 0, 0, 0, 0 }

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.getInfo("settings")~= nil then
		local data = love.filesystem.read("settings")
		local file = TSerial.unpack(data)
		for i,v in pairs(file) do
			config[i] = v
		end
	end
	-- Avoid crash if fullscreen is a boolean from old version
	if type(config.fullscreen) == "boolean" then
		config.fullscreen = 0
	end
end

function loadHighscores()
	if love.filesystem.getInfo("highscores")~= nil 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 loadStats()
	if love.filesystem.getInfo("stats")~= nil then
		local data = love.filesystem.read("stats")
		stats = TSerial.unpack(data)
	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 saveStats()
	local data = TSerial.pack(stats)
	love.filesystem.write("stats", data)
end

function setMode()
	if config.fullscreen == 0 then
		love.window.setMode(WIDTH*config.scale, HEIGHT*config.scale, {fullscreen=false, vsync=config.vsync})
		love.graphics.setScissor()
	elseif config.fullscreen > 0 and config.fullscreen <= 3 then
		love.window.setMode(0,0, {fullscreen=true, vsync=config.vsync})
		love.window.setMode(love.graphics.getWidth(), love.graphics.getHeight(), {fullscreen=true, vsync=config.vsync})
	end
	fs_translatex = (love.graphics.getWidth()-WIDTH*config.scale)/2
	fs_translatey = (love.graphics.getHeight()-HEIGHT*config.scale)/2
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