-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaves.lua
More file actions
486 lines (421 loc) · 9.63 KB
/
saves.lua
File metadata and controls
486 lines (421 loc) · 9.63 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
-- This software is released under the MIT License. See LICENSE.txt for details.
local alphabet = "abcdefghijklmnopqrstuvwxyz"
--[[
kod:
1-9: antalet banor i rad som är klarade med minloops
0: fler än 9 banor i rad
a-y: antalet loopar banan är klarad i
z: fler än 25 loopar
-: 99 loopar
]]
local function lolchecksum(s)
local sum = 0
for i = 1, #s do
sum = sum + string.byte(s:sub(i,i)) + 1
end
return "" .. (sum % 9)
end
function importsave(strin)
local shopped = tonumber(strin:sub(-2,-2))
if shopped == nil then
print("not a number")
return false
end
local sausage = {false, false, false}
if shopped==1 then
sausage[1] = true
elseif shopped==2 then
sausage[2] = true
elseif shopped==3 then
sausage[3] = true
elseif shopped==4 then
sausage[1] = true
sausage[2] = true
elseif shopped==5 then
sausage[2] = true
sausage[3] = true
elseif shopped==6 then
sausage[1] = true
sausage[3] = true
elseif shopped==7 then
sausage[1] = true
sausage[2] = true
sausage[3] = true
elseif shopped==8 then
print("an 8")
return false
elseif shopped==9 then
print("a 9")
return false
end
local lhs = {}
for i = 1,9 do
lhs[worlds[i]] = {}
for j = 1,7 do
lhs[worlds[i]][j] = 99
end
end
local function seths(w,l,a)
print("writing " .. worlds[w] .. ":" .. l .. " as " .. a)
lhs[worlds[w]][l] = a
end
local pos = 1
local str = strin:sub(1,-3)
local len = #str
local w = 1
local l = 1
local astr = "a"
while pos <= len do
local char = str:sub(pos, pos)
local num = tonumber(char)
if num ~= nil then
local val = num
while num == 0 do
val = val + 9
pos = pos + 1
if pos > len then
print("wrong 0")
return false
end
num = tonumber(str:sub(pos,pos))
if num == nil then
print("wrong 0, case 2")
return false
end
val = val + num
end
for i = 1, val do
if w > 8 then
print "tldr"
return false
end
seths(w,l,minLoops[worlds[w]][l])
l = l + 1
if l > 7 then
l = 1
w = w + 1
end
end
pos = pos + 1
elseif char=="-" then
pos = pos + 1
l = l + 1
if l > 7 then
w = w + 1
l = 1
end
else
num = 0
while char=="z" do
num = num + char:byte() - astr:byte() + 1
pos = pos + 1
if pos > len then
print("wrong z")
return false
end
char = str:sub(pos,pos)
end
num = num + char:byte() - astr:byte() + 1
if num==minLoops[worlds[w]][l] then
print("minloop")
return false
end
seths(w,l,num)
pos = pos + 1
l = l + 1
if l > 7 then
w = w + 1
l = 1
end
end
end
if w > 8 then
print "tldr"
return false
end
hs = lhs
shopstate:write(sausage)
love.filesystem.write("mappos.lua", "return {1,1}")
if loadmap then
globalpack = w
globalnumber = l
saveHS(hs)
loadmap()
else
globalpack = w
globalnumber = l
end
return true
end
function exportsaves()
local s = ""
local ml_inarow = 0
local nr_inarow = 0
local done = false
for i = 1, #worlds do
local world = hs[worlds[i]]
for j = 1, #world do
local level = world[j]
if level < 99 and nr_inarow > 0 then
for k = 1, nr_inarow do
s = s .. "-"
end
nr_inarow = 0
end
if level == minLoops[worlds[i]][j] and level ~= 99 then
ml_inarow = ml_inarow + 1
else
if ml_inarow > 0 and nr_inarow == 0 then
while ml_inarow > 9 do
s = s .. "0"
ml_inarow = ml_inarow - 9
end
s = s .. ml_inarow
end
ml_inarow = 0
if level == 99 then
nr_inarow = nr_inarow + 1
else
while level > #alphabet - 1 do
s = s .. "z"
level = level - (#alphabet - 1)
end
s = s .. alphabet:sub(level,level)
end
end
end
end
local sg = shopstate:getSausage()
local num = 0
if sg[1] then
num = num + 1
if sg[2] or sg[3] then
num = num + 1
if not sg[2] then
num = num + 1
end
end
end
if sg[2] then
num = num + 2
end
if sg[3] then
num = num + 3
end
s = s .. num
-- checksum
local cs = lolchecksum(s)
s = s .. cs
return s
end
savessstate = stateClass:newSubClass()
function savessstate.deldata()
exit_prompt = newpopup("are you sure?", {{"yes",savessstate.deldata2},{"no",function()
exit_prompt = nil
end}})
end
function savessstate.deldata2()
local files = {"iwanttopoophere", "ibuysausage", "mappos.lua", "hs.lua", "options.lua"}
local hugesuccess = true
for i,v in ipairs(files) do
if love.filesystem.exists(v) then
local res = love.filesystem.remove(v)
if v ~= "mappos.lua" and v~= "hs.lua" and v~= "options.lua" and not res then
exit_prompt = newpopup("deleting didn't work!", {{"ok", function() exit_prompt = nil end}})
hugesuccess = false
break
end
end
end
hs = require "bhs"
calc_beatenlevels()
globalpack = 1
globalnumber = 1
if hugesuccess then
exit_prompt = nil
end
end
function savessstate:load()
self.gfx = love.graphics.newImage("res/introfg.png")
self.lolpass = "your password is:"
self.butts = newButtList()
self.butts:add(newButt("back", 50 + width*0.1, 40 + height*0.1,
function()
changeState(optionsState)
end))
self.butts:add(newButt("delete all data", centerx, centery + 150, self.deldata))
self.butts:add(newButt("export save data", centerx, centery, function()
local lines = 1
local newpass = exportsaves()
local origpass = newpass
while font:getWidth(newpass)/lines > width*0.9 do
lines = lines + 1
local half = #origpass / lines
newpass = ""
for i = 1, lines do
newpass = newpass .. origpass:sub((i-1)*half + 1, i*half) .. " "
end
end
state.pass = newpass
state.butts.list[3].tween.clicktime = 0
end))
self.butts:add(newButt("import save data", centerx, centery - 150, function()
state.import = ""
state.butts.list[4].tween.clicktime = 0
end))
self.keyboard = newButtList()
self.keyboard:add(newButt("back",50, 40, function()
state.import = nil
state.keyboard.list[1].tween.clicktime = 0
state.keyboard.list[1].tween.fact = 1
end))
self.byletter = {}
local dx = width*0.8 / 10
local dy = height/9
local function a(let, y, x)
self.keyboard:add(newButt(let, width * 0.05 + dx*x, 180 + dy*y, function()
if let == "<-" then
state.import = state.import:sub(1,-2)
else
state.import = state.import .. let
end
end))
self.byletter[let] = self.keyboard.list[#self.keyboard.list]
end
a("1",0,1)
a("2",0,2)
a("3",0,3)
a("4",0,4)
a("5",0,5)
a("6",0,6)
a("7",0,7)
a("8",0,8)
a("9",0,9)
a("0",0,10)
a("q",1,1)
a("w",1,2)
a("e",1,3)
a("r",1,4)
a("t",1,5)
a("y",1,6)
a("u",1,7)
a("i",1,8)
a("o",1,9)
a("p",1,10)
a("a",2,1)
a("s",2,2)
a("d",2,3)
a("f",2,4)
a("g",2,5)
a("h",2,6)
a("j",2,7)
a("k",2,8)
a("l",2,9)
a("z",3,1)
a("x",3,2)
a("c",3,3)
a("v",3,4)
a("b",3,5)
a("n",3,6)
a("m",3,7)
a("-",3,8)
a("<-",3,10)
self.keyboard:add(newButt("ok", centerx ,180 + 4.5*dy, function()
if state.import == "ouiimlikesamsonitsthesourceofmystrength" then
funkMode = true
changeState(titleScreen)
elseif state.import == "awesomesauce" then
lolmusiceasteregg = true
audio:shutup()
audio = newAudioList2()
audio:fillCompletely()
changeState(titleScreen)
elseif lolchecksum(state.import:sub(1,-2))==state.import:sub(-1) then
print "correct checksum, loading save data"
local res = importsave(state.import)
if res then
changeState(titleScreen)
else
exit_prompt = newpopup("incorrect password! :<",{{"ok", function()
exit_prompt = nil
end}})
end
else
exit_prompt = newpopup("incorrect password!",{{"ok", function()
exit_prompt = nil
end}})
end
end))
end
function savessstate:draw()
love.graphics.setColor(0,40,0)
love.graphics.rectangle("fill",0,0,width,height)
love.graphics.setColor(255,255,255,40)
love.graphics.draw(self.gfx, width - 400*2, height - 512*2 + 50,0,2,2)
love.graphics.setColor(255,255,255)
if self.pass then
love.graphics.print(self.lolpass, centerx - font:getWidth(self.lolpass)*0.5, centery - 100)
love.graphics.printf(self.pass, 0, centery - 60, width - 30, "center")
elseif state.import then
self.keyboard:draw()
love.graphics.print("password:",width*0.15,20)
local str = self.import
if font:getWidth(str) > width*0.85 then
local len = math.ceil(#str / 2)
str = str:sub(1,len) .. " " .. str:sub(len+1)
end
love.graphics.printf(str, width*0.15, 50, width*0.85, "left")
else
self.butts:draw()
end
end
function savessstate:mousepressed()
if self.pass then
self.pass = nil
elseif state.import then
self.keyboard:click()
else
self.butts:click()
end
end
function savessstate.is_ok(k)
local a = "a"
local z = "z"
local zero = "0"
local nine = "9"
return (k:byte() >= zero:byte() and k:byte() <= nine:byte()) or (k:byte() >= a:byte() and k:byte() <= z:byte())
end
function savessstate:keypressed(k)
if k:sub(1,2) == "kp" then
k = k:sub(3)
if k=="enter" then
k = "return"
end
end
if state.import ~= nil then
if k == "backspace" then
self.import = self.import:sub(1,-2)
local butt = self.byletter['<-']
if butt then
butt.tween.clicktime = butt.tween.mclicktime
audio:playSfx("butt")
end
elseif #k==1 and self.is_ok(k) then
self.import = self.import .. k
local butt = self.byletter[k]
if butt then
butt.tween.clicktime = butt.tween.mclicktime
audio:playSfx("butt")
end
elseif #k==1 then
self.import = self.import .. "-"
local butt = self.byletter['-']
if butt then
butt.tween.clicktime = butt.tween.mclicktime
audio:playSfx("butt")
end
elseif k=="return" or k=="kpenter" then
self.keyboard.list[#self.keyboard.list].click()
end
end
end