-
Notifications
You must be signed in to change notification settings - Fork 0
/
options-classes.lua
144 lines (120 loc) · 2.6 KB
/
options-classes.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
--[[
This software is released under the MIT License. See LICENSE.txt for details.
Also, on a non-legal note: I do not recommend reading my code, especially not for educative
purposes. It was written over like three years, and I often forgot how I implemented several
things over time. Also, I was mostly drunk and listening to the Katamari Damacy soundtrack.
So yeah.
]]
allOptions = {}
allOptionNames = {}
optionClass = newClass()
function newOption(name,func)
local o = optionClass:newInstance()
o.name = name
o.func = func
return o
end
function optionClass:exec()
self.func()
end
questionClass = newClass()
function newQuestion(name,answers)
local o = questionClass:newInstance()
o.name = name
o.ans = answers
allOptions[name] = o
table.insert(allOptionNames,name)
end
function questionClass:getStandardOption()
return self.ans[1]
end
function getStandardOptions()
local o = {}
for i,v in pairs(allOptions) do
o[i] = v:getStandardOption().name
end
return o
end
function optionsToString()
local s = "options = {}\n"
for i,v in pairs(options) do
s = s.."options['"..i.."'] = '"..v.."'\n"
end
return s
end
function writeOptions()
love.filesystem.write("options.lua",optionsToString())
end
function loadOptions()
local ok,lol = pcall(love.filesystem.load,"options.lua")
if ok then
lol()
else
options = getStandardOptions()
print("I AM ERROR: Failed to load settings properly")
end
if options["controls"] == nil then
options.controls = "fast"
end
if options["sound effects"] == nil then
options["sound effects"] = "on"
end
for i,v in pairs(options) do
local option = allOptions[i]
for j = 1,#option.ans do
if option.ans[j].name == v then
option.ans[j]:exec()
end
end
end
end
newQuestion("show fps",{
newOption("yes",function()
showFPS = true
end),
newOption("no",function()
showFPS = false
end)
})
newQuestion("draw mode",{
newOption("sb",function()
drawMode = 1
end),
newOption("fb",function()
drawMode = 2
end)
})
newQuestion("sound",{
newOption("on",function()
lolSound = true
print(audio.theNameOfTheCurrentlyPlayingMusic)
audio:playMusic(audio.theNameOfTheCurrentlyPlayingMusic)
end),
newOption("off",function()
lolSound = false
if audio then
audio:shutup()
end
end)
})
newQuestion("sound effects", {
newOption("on", function()
lolSfx = true
end),
newOption("off", function()
lolSfx = false
if audio then
audio:sfxShutup()
end
end)
})
newQuestion("controls",{
newOption("fast", function()
preciseControls = false
end),
newOption("precise", function()
preciseControls = true
end)
})
loadOptions()
--writeOptions()