-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.lua
2422 lines (2282 loc) · 87.6 KB
/
main.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
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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import("CoreLibs/graphics")
import("CoreLibs/keyboard")
import("CoreLibs/timer")
import("CoreLibs/object")
import("CoreLibs/sprites")
import("options")
gameInfo, groups = nil, nil
gameIcons = {}
gameGrid = {}
gfx = playdate.graphics
fle = playdate.file
gme = playdate.system.game
cursorx,cursory = 1,1
cursordrawx,cursordrawy = 1,1
columns,rows = 1,3
iconsImage = nil
iconOffsetX = 0
iconOffsetY = 12
season_1 = {
"com.a-m.beats-bleeps-boogie",
"com.crookedpark.demonquest85",
"com.dadako.questychess",
"com.davemakes.execgolf",
"com.gregorykogos.omaze",
"com.nelsanderson.forrest",
"com.NicMagnier.PickPackPup",
"com.panic.b360",
"com.panic.inventoryhero",
"com.panic.starsled",
"com.radstronomical.CasualBirder",
"com.samanthazero.echoicmemory",
"com.serenityforge.elevator",
"com.shauninman.ratcheteer",
"com.spectrecollie.sasquatchers",
"com.sweetbabyinc.lostyourmarbles",
"com.teambottle.spellcorked",
"com.tpmcosoft.battleship",
"com.uvula.crankin",
"com.vertexpop.hypermeteor",
"com.vitei.whitewater",
"com.wildrose.saturday",
"net.foddy.zipper",
"net.stfj.snak",
}
recentCursorDown = 0
recentCursorRight = 0
inputDelay = 0
badgeIcons = {}
labels = {}
currentLabel = ""
labelMaxSize = 8
organizeMode = false
selectedBadge = nil
selectedBadgeImage = nil
reloadIconsNextFrame = false
iconPlacements = nil
drawIconBorders = true
local bottomBar = true
local useCustomIconAnimation = false
selectedBadgeOriginX = 0
selectedBadgeOriginY = 0
labelImage = nil
movedLabels = false
paddingOffset = 0
editingLabel = 0
firstEdit = true
local cursorImg = nil
local cursorGif = nil
local cursorGifFrame = 1
local cursorGifNextFrameCounter = 0
local gameTimeList = nil
local showBatteryPercent = false
keyTimer = nil
local canLaunch = true
local initialDelay = 300
local repeatDelay = 40
local cardYpos = 218
local cardYposTarget = -10
local cardInfoShowing = false
blankImg = nil
first_load = true
local cardLaunchGame = nil
local cardImg = nil
cardShowing = false
contentWarningState = 0
local noCrankFrames = 5
local bgdither = 0
local bgditherimg = nil
local invertborders = false
local invertlabels = false
local invertcursor = false
local invertblanks = false
local emptydither = 0.75
local cardAnimationLoops = 0
local cardAnimationFrame = 0
local cardAnimationProps = {}
local cardAnimationState = "off" --off, highlighted, launch
local cardAnimationDoneIntro = false
local cardAnimationStayFrames = 0
local cardAnimationLaunch = true
local iconAnimationLoops = 0
local iconAnimationFrame = 0
local iconAnimationProps = {}
local iconAnimationState = "highlighted" --off, highlighted
local iconAnimationDoneIntro = false
local iconAnimationStayFrames = 0
local noToggleLabelFrames = 3
local unwrapAnimating = false
local music = nil
local musicOn = true
local movingFast = false
local bgImg = nil
local kPDGameStateFreshlyInstalled, kPDGameStateInstalled
if playdate.system ~= nil then
kPDGameStateFreshlyInstalled = playdate.system.game.kPDGameStateFreshlyInstalled
kPDGameStateInstalled = playdate.system.game.kPDGameStateInstalled
end
local invertedColors = {[true] = gfx.kColorWhite, [false] = gfx.kColorBlack}
local invertedDrawModes = {[true] = gfx.kDrawModeFillBlack, [false] = gfx.kDrawModeFillWhite}
local skipCard = false
local showBattery = false
Opts = Options(
{
{
header="Customization", options = {
{
name = "Reduce stuttering",
key = "reducestuttering",
default = false,
tooltip = "If enabled, icons are processed when the launcher starts instead of as you scroll. Longer load times, less stuttering. Open and close a game for this to take effect."
},
{
name = "Music",
key = "musicon",
default = true,
tooltip = "Whether your music placed in /Shared/FunnyOS will play."
},
{
name = "Skip Card",
key = "skipcard",
default = false,
tooltip = "When you click on an icon, launch the game without going to the card menu."
},
{
name = "Show Battery",
key = "showbattery",
default = false,
tooltip = "Switch out the bottom bar for battery and time instead of controls."
},
{
name = "Battery Percent",
key = "batterypercent",
default = false,
tooltip = "If show battery is selected, this changes the battery icon to show exact percents."
},
{
name = "Icon Borders",
key = "iconborders",
default = true,
tooltip = "Show borders around list view icons."
},
{
name = "Invert Borders",
key = "invertborders",
default = false,
tooltip = "Make list view icons borders white."
},
{
name = "Invert Cursor",
key = "invertcursor",
default = false,
tooltip = "Make the cursor white."
},
{
name = "Invert Labels",
key = "invertlabels",
default = false,
tooltip = "Make labels white."
},
{
name = "Invert Blanks",
key = "invertblanks",
default = false,
tooltip = "Make blanks dither white instead of black (good for dark backgrounds)."
},
{
name = "Background Dither",
key = "bgdither",
tooltip = "Controls dithering strength applied to background.",
style = Options.SLIDER,
min = 0,
max = 4,
default = 0
},
{
name = "Blank Space Dither",
key = "emptydither",
tooltip = "Controls dithering strength on spaces without an icon.",
style = Options.SLIDER,
min = 0,
max = 4,
default = 1
}
}
}
},
true,
"Funny OS/pdoptions",
function()
loadOptions()
noToggleLabelFrames = 3
end
)
local unwrapx = 0
local unwrapy = 0
local unwrapxvel = 0
local unwrapyvel = 0
local unwrapmaxvel = 25
local stockLauncherImg = gfx.image.new("images/stocklauncher")
local loadingImg = gfx.image.new("images/loading")
local batteryImg = gfx.image.new("images/battery")
local batteryImgs = gfx.imagetable.new("images/battery-bars")
local wrappedImg = gfx.image.new("images/wrapped")
local newGame = gfx.image.new("images/newgame")
local newGameMask = gfx.image.new("images/newgame_mask")
local crankChange = 0
local crankIncrement = 45
local reduceStuttering = false
function loadOptions(initial)
gfx.sprite.update()
reloadIconsNextFrame = true
if drawIconBorders == nil then drawIconBorders = true Opts:write("iconborders", 2) end
if showBattery == nil then showBattery = false Opts:write("showbattery", 1) end
if reduceStuttering == nil then reduceStuttering = false Opts:write("reducestuttering", 1) end
if showBatteryPercent == nil then showBatteryPercent = false Opts:write("batterypercent", 1) end
if skipCard == nil then skipCard = false Opts:write("skipcard", 1) end
if musicOn == nil then drawIconBorders = true Opts:write("musicon", 2) loadMusic() end
skipCard = Opts:read("skipcard", true, true)
showBattery = Opts:read("showbattery", true, true)
reduceStuttering = Opts:read("reducestuttering", true, true)
showBatteryPercent = Opts:read("batterypercent", true, true)
if (musicOn ~= Opts:read("musicon", true, true) or initial) and Opts:read("musicon", true, true) == true then
loadMusic()
end
if Opts:read("musicon", true, true) == false then
if music~= nil then music:stop() end
end
musicOn = Opts:read("musicon", true, true)
if not musicOn then
if music then music:stop() end
end
local i = Opts:read("bgdither", true, true)
i = 1- 0.25*i
if i ~= bgdither or initial == true then
changeBgDither(i)
end
i = Opts:read("emptydither", true, true)
i = 1- 0.25*i
if i ~= emptydither or initial == true then
setEmptyIcon(i)
end
if Opts:read("iconborders", true, true) ~= drawIconBorders or Opts:read("invertlabels", true, true) ~= invertlabels
or Opts:read("invertborders", true, true) ~= invertborders or Opts:read("invertcursor", true, true) ~= invertcursor
or Opts:read("invertblanks", true, true) ~= invertblanks then
invertborders = Opts:read("invertborders", true, true)
invertlabels = Opts:read("invertlabels", true, true)
invertcursor = Opts:read("invertcursor", true, true)
invertblanks = Opts:read("invertblanks", true, true)
drawIconBorders = Opts:read("iconborders", true, true)
i = Opts:read("emptydither", true, true)
i = 1- 0.25*i
setEmptyIcon(i)
for k,v in pairs(gameInfo) do
if not (v["group"] == "System") then
loadIcon(k,nil,true)
end
end
end
reloadIconsNextFrame = true
end
function collapseEmptyExpansions()
for i,v in ipairs(labels) do
local collapse = false
local currentx = v["x"]
if gameGrid[indexFromPos(currentx-1,1)] == ".empty" and gameGrid[indexFromPos(currentx-1,2)] == ".empty" and gameGrid[indexFromPos(currentx-1,3)] == ".empty" then
collapse = true
end
if collapse then
table.remove(gameGrid,indexFromPos(currentx-1,1))
table.remove(gameGrid,indexFromPos(currentx-1,1))
table.remove(gameGrid,indexFromPos(currentx-1,1))
local newLabels = {}
for j,v2 in ipairs(labels) do
if v2["x"] < currentx then
table.insert(newLabels,v2)
else
local newLabel = {["name"] = v2["name"], ["x"] = v2["x"]-1}
table.insert(newLabels,newLabel)
end
end
labels = newLabels
end
end
while gameGrid[#gameGrid] == ".empty" do
table.remove(gameGrid,#gameGrid)
end
while indexFromPos(cursorx,cursory) > #gameGrid do
moveLeft(true)
end
reloadIconsNextFrame = true
iconSaveNuclearOption()
end
function setEmptyIcon(n)
emptydither = n
gfx.setImageDrawMode(gfx.kDrawModeCopy)
gfx.setColor(invertedColors[invertblanks])
blankImg = gfx.image.new(66,66)
gfx.lockFocus(blankImg)
gfx.setDitherPattern(n,gfx.image.kDitherTypeBayer4x4)
gfx.fillRoundRect(0,0,66,66,8)
gfx.unlockFocus()
reloadIconsNextFrame = true
loadOptions()
end
function changeBgDither(n)
bgdither = n
gfx.setImageDrawMode(gfx.kDrawModeCopy)
gfx.setColor(gfx.kColorBlack)
local img = gfx.image.new(402,240)
gfx.lockFocus(img)
gfx.setDitherPattern(n)
gfx.fillRect(0,0,402,240)
gfx.unlockFocus()
bgditherimg = img
reloadIconsNextFrame = true
loadOptions()
end
function cleanUpIconPlacements()
local newIconPlacements = {}
for i,v in ipairs(iconPlacements) do
if v ~= ".tempblank" then
table.insert(newIconPlacements,v)
end
end
iconPlacements = newIconPlacements
end
function removeKeyTimer()
movingFast = false
if keyTimer ~= nil then
keyTimer:pause()
keyTimer:remove()
keyTimer = nil
end
end
function sortLabels()
local newLabels = {}
for i,v in ipairs(labels) do
if i == 1 then
table.insert(newLabels,v)
else
local found = false
for j,v2 in ipairs(newLabels) do
if (indexFromPos(v.x,1) < indexFromPos(v2.x,1)) and not found then
table.insert(newLabels,j,v)
found = true
end
end
if not found then
table.insert(newLabels,#newLabels+1,v)
found = true
end
end
end
labels = newLabels
end
function saveConfig()
local datastore = {}
datastore["iconPlacements"] = iconPlacements
datastore["labels"] = labels
datastore["cursorx"] = cursorx
datastore["cursory"] = cursory
playdate.datastore.write(datastore,"/Shared/FunnyOS/funnyConfig")
end
targetcx = 1
targetcy = 1
function loadConfig()
local datastore = playdate.datastore.read("/Shared/FunnyOS/funnyConfig")
if datastore == nil then
datastore = playdate.datastore.read("Funny OS/funnyConfig")
playdate.datastore.write(datastore,"/Shared/FunnyOS/funnyConfig")
fle.delete("/System/Data/Funny OS/funnyConfig.json")
saveConfig()
end
if datastore then
iconPlacements = datastore["iconPlacements"]
labels = datastore["labels"]
targetcx = datastore["cursorx"]
targetcy = datastore["cursory"]
else
first_load = true
end
if not iconPlacements then iconPlacements = {} end
if not targetcx then targetcx = 1 end
if not targetcy then targetcy = 1 end
if not labels or labels == {} then labels = {{["name"] = "Home", ["x"] = 1}} end
if #labels < 1 then
table.insert(labels, {["name"] = "Home", ["x"] = 1})
end
currentLabel = labels[1]["name"]
sortLabels()
end
function indexFromPos(x,y)
local i = (x*rows) - (rows - y)
return i
end
function posFromIndex(i)
local gridy = (i-1)%rows + 1
local gridx = math.ceil(i/rows)
return gridx,gridy
end
function generateDrawTextScaledImage(text, x, y, scale, font)
local padding = string.upper(text) == text and 6 or 0 -- Weird padding hack?
local w <const> = font:getTextWidth(text)
local h <const> = font:getHeight() - padding
local img <const> = gfx.image.new(w, h, gfx.kColorClear)
local img2 <const> = gfx.image.new(w*scale*2, h*scale*2, gfx.kColorClear)
gfx.lockFocus(img)
gfx.setFont(font)
gfx.drawTextAligned(text, w / 2, 0, kTextAlignment.center)
gfx.unlockFocus()
gfx.lockFocus(img2)
img:drawScaled((scale * w) / 2, (scale * h) / 2, scale)
gfx.unlockFocus()
return img2
end
function listCopy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in pairs(orig) do
copy[orig_key] = orig_value
end
else -- number, string, boolean, etc
copy = orig
end
return copy
end
function sortGameGrid()
local newGameGrid = {}
for i,v in ipairs(gameGrid) do
if i == 1 then
table.insert(newGameGrid,v)
else
local found = false
for j,v2 in ipairs(newGameGrid) do
if not (string.lower(gameInfo[v]["name"]) > string.lower(gameInfo[v2]["name"])) and not found then
table.insert(newGameGrid,j,v)
found = true
end
end
if not found then
table.insert(newGameGrid,#newGameGrid+1,v)
found = true
end
end
end
gameGrid = newGameGrid
end
function placeIcons()
sortIconPlacements()
for i,v in ipairs(iconPlacements) do
if v["name"] == ".empty" then
while indexFromPos(v["x"],v["y"]) > #gameGrid-1 do
table.insert(gameGrid,#gameGrid-1,".empty")
end
table.insert(gameGrid,indexFromPos(v["x"],v["y"]),".empty")
else
local found = false
for j,v2 in ipairs(gameGrid) do
if v2 == v["name"] and not found then
while indexFromPos(v["x"],v["y"]) > #gameGrid-1 do
table.insert(gameGrid,#gameGrid-1,".empty")
end
gameGrid[j] = gameGrid[indexFromPos(v["x"],v["y"])]
table.insert(gameGrid,indexFromPos(v["x"],v["y"]),v["name"])
table.remove(gameGrid,indexFromPos(v["x"],v["y"])+1)
found = true
end
end
if not found and (v["x"] ~= nil and v["y"] ~= nil) then
while indexFromPos(v["x"],v["y"]) > #gameGrid-1 do
table.insert(gameGrid,#gameGrid-1,".empty")
end
table.insert(gameGrid,indexFromPos(v["x"],v["y"]),v["name"])
end
end
end
end
function getOffset(x)
local displayOffsetX = 0
for j,v2 in ipairs(labels) do
if v2["x"] == x then
displayOffsetX += 1
end
if v2["x"] >= x then
displayOffsetX += 1
break
elseif v2["x"] < x then
displayOffsetX += 1
if j == #labels then
displayOffsetX += 1
end
end
end
return displayOffsetX
end
local actualIconOffsetX = 0
function drawIcons()
local paddingAmount = 30
gfx.clear()
if bgImg then
bgImg:drawCentered(200,120)
end
if bgditherimg then
bgditherimg:draw(0,0)
end
for i,v in ipairs(gameGrid) do
if not (cardShowing and contentWarningState > 0) then
local found = false
gridx,gridy = posFromIndex(i)
local drawx = ((gridx*72)-52)-actualIconOffsetX*72 + 2 - getOffset(cursorx)*paddingAmount
local drawy = ((gridy*72)-56)-iconOffsetY
drawx,drawy = math.floor(drawx),math.floor(drawy)
drawx+=getOffset(gridx)*paddingAmount
if (drawx < 500 and drawx > -100) then
for j,v2 in ipairs(labels) do
if indexFromPos(v2["x"],1) == i and not found then
found = true
currentLabelIndex = j
gfx.setColor(invertedColors[invertlabels])
gfx.fillRect(drawx-3 - paddingAmount + 9,0,paddingAmount-10,240)
local t = "*"..labels[j]["name"].."*"
local w,h = gfx.getTextSize(t)
w = w * 1.2
local img = gfx.image.new(w,h)
gfx.lockFocus(img)
gfx.setImageDrawMode(invertedDrawModes[invertlabels])
gfx.drawText(t, 0, 0)
gfx.setImageDrawMode(gfx.kDrawModeCopy)
gfx.lockFocus(drawIconsImg)
w,h = img:getSize()
img = img:rotatedImage(270)
img:drawAnchored(drawx-3 - paddingAmount/2 - 3, 210, 0,1)
end
end
if v:sub(1,7) == ".badge:" then
local img = badgeIcons[v]
local w,h = img:getSize()
local back = 0
if w == 72 then
back = 3
end
img:drawCentered(drawx + w/2 -back,drawy + h/2 -back)
elseif v == ".empty" or v == ".tempblank" then
local xoff = 0
if drawx%2 == 0 then
xoff = 1
end
blankImg:draw(drawx-xoff,drawy)
elseif v == ".stockLauncher" then
stockLauncherImg:draw(drawx,drawy)
elseif gameInfo[v] then
if not gameInfo[v]["icon"] then
loadIcon(v)
end
gameInfo[v]["icon"]:draw(drawx,drawy)
end
end
end
end
local game = gameInfo[gameGrid[indexFromPos(cursorx,cursory)]]
local t = ""
if game then
t = game.name
elseif gameGrid[indexFromPos(cursorx,cursory)] == ".stockLauncher" then
t = "Boot to Stock Launcher"
end
if not (cardShowing and contentWarningState > 0) and t ~= "" then
local img = generateDrawTextScaledImage("*"..t.."*",0,0,1,gfx.getFont())
w,h = img:getSize()
if recentCursorDown == 0 then
basey = cursordrawy*72+21
else
basey = cursordrawy*72 - 55 - h
end
if recentCursorRight == 0 then
basex = cursordrawx*72-55
else
basex = cursordrawx*72 + 6 - w/2
end
gfx.setColor(gfx.kColorWhite)
gfx.fillRoundRect(basex,basey-iconOffsetY,w/2+10,h/2+8,6)
gfx.setColor(gfx.kColorBlack)
gfx.setLineWidth(4)
gfx.drawRoundRect(basex,basey-iconOffsetY,w/2+10,h/2+8,6)
gfx.setColor(gfx.kColorWhite)
img:draw(basex+5 - w/4,basey+5 - h/4 - iconOffsetY)
end
iconsImage = gfx.getWorkingImage()
end
function reloadBadges()
local files = fle.listFiles("/Shared/FunnyOS/Badges")
local added = 0
local badgeCountInit = 0
for i,v in ipairs(iconPlacements) do
if v["name"] then
if v["name"]:sub(1,7) == ".badge:" then
badgeCountInit += 1
end
end
end
for i,v in ipairs(files) do
if v:sub(#v-3,#v) == ".pdi" then
local found = false
for j,v2 in ipairs(iconPlacements) do
if v2["name"] == ".badge:"..v:sub(1,#v-4) and v2["name"]:sub(1,7) == ".badge:" then
found = true
added+=1
end
end
if not found then
local x,y = posFromIndex(#gameGrid+1+added+badgeCountInit)
table.insert(iconPlacements, {["name"] = ".badge:"..v:sub(1,#v-4), ["x"] = x,["y"] = y})
added+=1
end
end
end
local newIconPlacements = {}
for i,v in ipairs(iconPlacements) do
if v["name"] then
if v["name"]:sub(1,7) == ".badge:" then
local img = gfx.image.new("/Shared/FunnyOS/Badges/"..v["name"]:sub(8,#v["name"])..".pdi")
if img then
local w,h = img:getSize()
if w <= 68 then size = 64 else size = 72 end
img = img:scaledImage(1/(w/size))
badgeIcons[v["name"]] = img
table.insert(newIconPlacements, v)
end
else
table.insert(newIconPlacements, v)
end
end
end
iconPlacements = newIconPlacements
end
function sortIconPlacements()
newIconPlacements = {}
for i,v in ipairs(iconPlacements) do
if i == 1 then
table.insert(newIconPlacements,v)
else
local found = false
if v.x ~= nil and v.y ~= nil then
for j,v2 in ipairs(newIconPlacements) do
if (indexFromPos(v.x,v.y) < indexFromPos(v2.x,v2.y)) and not found then
table.insert(newIconPlacements,j,v)
found = true
end
end
if not found then
table.insert(newIconPlacements,#newIconPlacements+1,v)
found = true
end
end
end
end
iconPlacements = newIconPlacements
newIconPlacements = {}
for i,v in ipairs(iconPlacements) do
if gameInfo[v["name"]] or v["name"] == ".empty" or v["name"]:sub(1,7) == ".badge:" or v["name"] == ".stockLauncher" then
table.insert(newIconPlacements,v)
else
table.insert(newIconPlacements,{["name"] = ".empty", ["x"] = v["x"], ["y"] = v["y"]})
end
end
iconPlacements = newIconPlacements
if iconPlacements == {} then
iconPlacements={{["name"]=".empty",["x"]=1,["y"]=1}}
end
end
function badgeSetup()
if not fle.isdir("/Shared/FunnyOS/Badges") then
fle.mkdir("/Shared/FunnyOS/Badges")
end
--playdate.datastore.write(badges, "/Shared/FunnyOSBadges/badges")
reloadBadges()
end
function dirSetup()
if fle.isdir("/Shared/FunnyOSBadges") then
local data = playdate.datastore.read("/Shared/FunnyOSBadges/funnyConfigBackup")
if data then playdate.datastore.write(data,"/Shared/FunnyOS/funnyConfig") end
local files = fle.listFiles("/Shared/FunnyOSBadges")
for i,v in ipairs(files) do
if v:sub(#v-3,#v) == ".pdi" then
local i = playdate.datastore.readImage("/Shared/FunnyOSBadges/"..v)
playdate.datastore.writeImage(i, "/Shared/FunnyOS/Badges/"..v)
end
end
playdate.file.delete("/Shared/FunnyOSBadges", true)
end
fle.mkdir("/Shared/FunnyOS/Icons")
local img = gfx.image.new("/Shared/FunnyOS/bg.pdi")
if img then
local w,h = img:getSize()
img = img:scaledImage(1/(w/400))
bgImg = img
end
img = gfx.image.new("/Shared/FunnyOS/load.pdi")
if img then
local w,h = img:getSize()
img = img:scaledImage(1/(w/400))
loadingImg = img
end
img = gfx.imagetable.new("/Shared/FunnyOS/cursor.pdt")
if img then
cursorGif = img
else
img = gfx.image.new("/Shared/FunnyOS/cursor.pdi")
if img then
cursorImg = img
end
end
if fle.exists("/System/Data/game_metrics.json") then
gameTimeList = playdate.datastore.read("/System/Data/game_metrics")
if gameTimeList == nil then
gameTimeList = {}
end
else
gameTimeList = {}
print("WOMP WOMP")
end
end
function loadMusic()
music = playdate.sound.fileplayer.new("/Shared/FunnyOS/bgm")
if music ~= nil then
music:play()
music:setFinishCallback(function() if musicOn then loadMusic() end end)
end
end
function moveUp(fast)
loadIcon(gameGrid[indexFromPos(cursorx,cursory)])
if gameGrid[indexFromPos(cursorx,cursory-1)] and cursory > 1 then
cursory -= 1
cursordrawy -= 1
if cursory < 1 then
cursory = 1
cursordrawy = 1
end
if cursordrawy > 1 then recentCursorDown = 1 else recentCursorDown = 0 end
end
iconAnimationState = "highlighted"
if not fast then
if indexFromPos(cursorx,cursory) == #gameGrid and organizeMode then
table.insert(gameGrid,".empty")
reloadIconsNextFrame = true
end
startIconAnimation()
doLabelExpansionStuff()
end
reloadIconsNextFrame = true
end
function moveDown(fast)
loadIcon(gameGrid[indexFromPos(cursorx,cursory)])
if gameGrid[indexFromPos(cursorx,cursory+1)] and cursory < rows then
cursory += 1
cursordrawy += 1
if cursory > rows then
cursory = rows
cursordrawy = rows
end
if cursordrawy > 1 then recentCursorDown = 1 else recentCursorDown = 0 end
end
iconAnimationState = "highlighted"
if not fast then
if indexFromPos(cursorx,cursory) == #gameGrid and organizeMode then
table.insert(gameGrid,".empty")
reloadIconsNextFrame = true
end
startIconAnimation()
doLabelExpansionStuff()
end
reloadIconsNextFrame = true
end
function moveRight(fast)
loadIcon(gameGrid[indexFromPos(cursorx,cursory)])
if gameGrid[indexFromPos(cursorx+1,cursory)] then
cursorx += 1
if cursordrawx < 5 then
cursordrawx += 1
else
iconOffsetX += 1
end
if cursordrawx > 3 then recentCursorRight = 1 end
end
iconAnimationState = "highlighted"
if not fast then
if indexFromPos(cursorx,cursory) == #gameGrid and organizeMode then
table.insert(gameGrid,".empty")
reloadIconsNextFrame = true
end
startIconAnimation()
doLabelExpansionStuff()
end
reloadIconsNextFrame = true
end
function moveLeft(fast)
loadIcon(gameGrid[indexFromPos(cursorx,cursory)])
cursorx -= 1
if cursordrawx > 1 then
cursordrawx -= 1
elseif cursorx >= 1 then
iconOffsetX -= 1
end
if cursorx < 1 then
cursorx = 1
else
if cursordrawx < 3 then recentCursorRight = 0 end
end
iconAnimationState = "highlighted"
if not fast then
if indexFromPos(cursorx,cursory) == #gameGrid and organizeMode then
table.insert(gameGrid,".empty")
reloadIconsNextFrame = true
end
startIconAnimation()
doLabelExpansionStuff()
end
reloadIconsNextFrame = true
end
function wrapPatternForGame(game)
local pattern
if nil ~= game then
local info = gameInfo[game:getBundleID()]
if nil ~= info["imagepath"] then
local imagepath = info.imagepath .. "/wrapping-pattern.pdi"
if info.imagepath:sub(#info.imagepath,#info.imagepath) == "/" then
imagepath = info.imagepath .. "wrapping-pattern.pdi"
end
pattern = gfx.image.new(info["path"].."/"..imagepath)
end
end
if nil == pattern then
pattern = gfx.image.new("images/default_pattern")
end
return pattern
end
function loadCard(bundleid , i)
local imageName = i
if imageName == nil then imageName = "card" end
local icon = gfx.image.new(358, 163,gfx.kColorClear)
gfx.lockFocus(icon)
for i,v in ipairs(groups) do
if v.name == gameInfo[bundleid]["group"] then
for j,v2 in ipairs(v) do
if v2:getBundleID() == bundleid then
game = v2
end
end
break
end
end
if game and gameInfo[bundleid] then
if game:getInstalledState() == kPDGameStateFreshlyInstalled then
local pattern = wrapPatternForGame(game)
local wrappingPattern = gfx.image.new(400, 240, gfx.kColorClear)
gfx.lockFocus(wrappingPattern)
newGame:draw(0, 0)
gfx.setStencilImage(newGameMask)
pattern:draw(0, 0)
gfx.lockFocus(icon)
gameInfo[bundleid]["wrap"] = wrappingPattern
else
gameInfo[bundleid]["wrap"] = nil
end
end
local drawletter = false
local look_for_icon = true
if gameInfo[bundleid]["imagepath"] and look_for_icon then
local gameicon = gfx.image.new(gameInfo[bundleid]["path"] .."/"..gameInfo[bundleid]["imagepath"].."/"..imageName)
if gameicon then
gameicon:draw(4,4)
else
gameicon = gfx.image.new(gameInfo[bundleid]["path"] .."/"..gameInfo[bundleid]["imagepath"].."/card")
if gameicon then
gameicon:draw(4,4)
else
drawletter = true
end
end
elseif not look_for_icon then
drawletter = true
end
if drawletter and look_for_icon then
local f = gfx.getLargeUIFont()
local t = gameInfo[bundleid]["name"]
gfx.setColor(gfx.kColorBlack)
gfx.fillRoundRect(0,0,358,163,8)
gfx.setImageDrawMode(gfx.kDrawModeFillWhite)
gfx.drawTextInRect(t, 20,66,317, 50, 0, "\226\128\166", kTextAlignment.center, f)
gfx.setImageDrawMode(gfx.kDrawModeCopy)
end
gfx.unlockFocus()
gameInfo[bundleid]["card"] = icon