-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialize.lua
More file actions
253 lines (204 loc) · 4.05 KB
/
initialize.lua
File metadata and controls
253 lines (204 loc) · 4.05 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
-- Requirements
SETTINGS = require "settings"
json = require "json"
-- Shuffle a table
local function shuffle(tbl)
for i = #tbl, 2, -1 do
local j = math.random(i)
tbl[i], tbl[j] = tbl[j], tbl[i]
end
end
-- Clone a table
local function deepcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[deepcopy(orig_key)] = deepcopy(orig_value)
end
setmetatable(copy, deepcopy(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end
return copy
end
-- Default table of levels, with properties for whether they are accessible/completed, and the bonus they hold
defaultLevels = {
{ -- Level 1
accessible = false,
bonusID = nil
},
{ -- Level 2
accessible = false,
bonusID = nil
},
{ -- Level 3
accessible = false,
bonusID = nil
},
{ -- Level 4
accessible = false,
bonusID = nil
},
{ -- Level 5
accessible = false,
bonusID = nil
},
{ -- Level 6
accessible = false,
bonusID = 11
},
{ -- Level 7
accessible = false,
bonusID = 21
},
{ -- Level 8
accessible = false,
bonusID = 1
},
{ -- Level 9
accessible = false,
bonusID = 12
},
{ -- Level 10
accessible = false,
bonusID = 22
},
{ -- Level 11
accessible = false,
bonusID = 2
},
{ -- Level 12
accessible = false,
bonusID = 13
},
{ -- Level 13
accessible = false,
bonusID = 23
},
{ -- Level 14
accessible = false,
bonusID = 3
},
{ -- Level 15
accessible = false,
bonusID = 14
},
{ -- Level 16
accessible = false,
bonusID = 24
},
{ -- Level 17
accessible = false,
bonusID = 4
},
{ -- Level 18
accessible = false,
bonusID = 15
},
{ -- Level 19
accessible = false,
bonusID = 25
},
{ -- Level 20
accessible = false,
bonusID = 5
},
{ -- Level 21
accessible = false,
bonusID = 16
},
{ -- Level 22
accessible = false,
bonusID = 26
},
{ -- Level 23
accessible = false,
bonusID = 6
},
{ -- Level 24
accessible = false,
bonusID = 27
},
{ -- Level 25
accessible = false,
bonusID = 28
},
{ -- Level 26
accessible = false,
bonusID = 7
},
{ -- Level 27
accessible = false,
bonusID = 29
},
{ -- Level 28
accessible = false,
bonusID = 30
},
{ -- Level 29
accessible = false,
bonusID = 8
},
{ -- Level 30
accessible = false,
bonusID = 31
},
{ -- Level 31
accessible = false,
bonusID = 32
},
{ -- Level 32
accessible = false,
bonusID = 9
},
{ -- Level 33
accessible = false,
bonusID = 33
},
{ -- Level 34
accessible = false,
bonusID = 34
},
{ -- Level 35
accessible = false,
bonusID = 10
},
{ -- Level 36
accessible = false,
bonusID = nil
},
{ -- Level 37
accessible = false,
bonusID = nil
},
{-- Level 38
accessible = false,
bonusID = nil
}
}
-- Copy of default table, to be modified with above functions and put into a json
randomizedLevels = deepcopy(defaultLevels)
local initialize = {}
-- Shuffle bonuses amongst levels that can hold them
local function shuffleBonuses()
local bonusIDTable = {}
for i = 1, #defaultLevels do
table.insert(bonusIDTable, defaultLevels[i]["bonusID"])
end
shuffle(bonusIDTable)
for i = 1, #defaultLevels do
randomizedLevels[i]["bonusID"] = bonusIDTable[i-5]
end
end
function initialize.init()
-- Deep copy the randomized levels again
randomizedLevels = deepcopy(defaultLevels)
-- Shuffle bonuses if set to do so
if SHUFFLE_BONUSES then shuffleBonuses() end
file = io.open("random.json", "w")
file:write(json.encode(randomizedLevels))
file:close()
end
return initialize