-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlayout_168.nut
18871 lines (16005 loc) · 636 KB
/
layout_168.nut
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
// Arcadeflow - v 16.6
// Attract Mode Theme by zpaolo11x
//
// Based on carrier.nut scrolling module by Radek Dutkiewicz (oomek)
// Including code from the KeyboardSearch plugin by Andrew Mickelson (mickelson)
// Load file nut
fe.do_nut("nut_file.nut")
fe.do_nut("nut_textboard.nut")
local comma = ','.tochar()
local nbsp = "^"
function split_complete(str_in, separator) {
local outarray = []
local index = str_in.find(separator)
while (index != null) {
outarray.push(str_in.slice(0, index))
str_in = str_in.slice(index + separator.len())
index = str_in.find(separator)
}
outarray.push(str_in)
return outarray
}
function char_replace(inputstring, old, new) {
local out = ""
local splitarray = split_complete (inputstring, old)
foreach (id, item in splitarray) {
out = out + (id > 0 ? new : "") + item
}
return out
}
function subst_replace(inputstring, old, new) {
local st = inputstring.find(old)
while (st != null) {
inputstring = (inputstring.slice(0, st) + new + inputstring.slice(st + old.len()))
st = inputstring.find(old, st + new.len())
}
return inputstring
}
function strepeat(character, length){
local out = ""
for (local i = 0; i < length; i++) out += character
return out
}
// COME CAMBIA AR DA AF98
/*
Modificare la funzione GetAR in modo che restituisca l'AR _DA MOSTRARE_ pre-clamp,
così per il GG è 4/3 come letto da System, per MAME è 3:4 o 4:3 secondo "orientation"
per altri handheld è texture W/H stretto, se siamo in boxart mode è semplicemente texture W/H
l'AR poi viene clampato o snapcroppato, a quel punto viene definita la dimensione dell'artwork.
*/
//EASE PRINT
local easeprint = {
status = false
counter = 0
}
local elapse = {
timer = false
name = ""
t1 = 0
t2 = 0
timetable = {}
}
function timestart(name) {
if (!elapse.timer) return
print("\n " + name + " START\n")
elapse.timetable.rawset(name, fe.layout.time)
}
function timestop(name) {
if (!elapse.timer) return
elapse.t2 = fe.layout.time
print(" " + name + " STOP: " + (elapse.t2 - elapse.timetable[name]) + "\n")
}
local IDX = array(100000)
// Support array for quick sort
foreach (i, item in IDX) {IDX[i] = format("%s%5u", "\x00", i)}
/// Main layout structures setup ///
// General AF data table
local AF = {
version = "16.6" // AF version in string form
vernum = 0 // AF version as a number
LNG = ""
WARN = ""
dat_freeze = true
dat_freezecount = 0
bgs_freezecount = 0
frost_freezecount = 0
zmenu_freezecount = 0
// Paths variable to different AM and AF locations
folder = fe.path_expand(fe.script_dir)
subfolder = ""
romlistfolder = fe.path_expand(FeConfigDirectory + "romlists/")
emulatorsfolder = fe.path_expand(FeConfigDirectory + "emulators/")
statsfolder = fe.path_expand(FeConfigDirectory + "stats/")
amfolder = fe.path_expand(FeConfigDirectory)
songdir = ""
bgsongs = []
config = null //Data structure with all the information from the attract.cfg file
emulatordata = {} // Data table with all the properties of all the emulators from the AM folder
soundvolume = 0
prefs = {
l0 = []
a0 = []
l1 = []
gl0 = [] //glyph array
imgpath = "help_images/"
imgext = ".jpg"
getout = false
defaults = null
driveletters = null
}
req = {
keyboard = -1
executef = -2
filereqs = -3
menusort = -4
exenoret = -5
textentr = -6
rgbvalue = -7
huevalue = -8
slideint = -9
liner = -100
}
updatechecking = false
msgbox = {
obj = null
scroller = null
back = null
columns = 60
separator1 = strepeat("-", 60)
separator2 = strepeat("=", 60)
title = ""
body = ""
numlines = 0
visiblelines = 0
lock = false
inline = 0
pulsetime0 = 0
pulsecounter = 0
}
tsc = 60.0 / ScreenRefreshRate // Pre-scaling of timer for different parameters
fps = ScreenRefreshRate
scrape = null
splash = {
time0 = 0
time1 = 0
progress = 0
waitframes = 5//0.25 * ScreenRefreshRate
syncsecs = 0.05
text = null
bg = null
pic = null
picbg = null
size = 290 //WAS 300
dark = 60
darkalpha = 90
charscale = 0.28 //WAS 0.35
tscalerate = fe.layout.width >= fe.layout.height ? fe.layout.height / 1200.0 : fe.layout.width / 1200.0
count = 0
start = "start"
stop = "stop"
pulse = "pulse"
}
bootplane1 = null
bootplane2 = null
boottext = null
bootalpha = 60
logo = null
}
function AFscrapeclear() {
AF.scrape = {
regiontable = ["wor", "us", "eu", "ss", "jp"]
regionprefs = [] //This will be populated by options table
checktable = {}
purgedromdirlist = null
listoflists = null
emudata = null
forcemedia = false
romlist = ""
inprf = {}
scrapelist_file = null
scrapelist_lines = null
romlist_file = null
romlist_lines = null
quit = false
totalroms = 0
doneroms = 0
timeoutroms = []
onegame = ""
dispatchid = 0
requests = ""
report = {}
threads_scr = 0
threads_dld = 0
threadsmax_ss = 20 // actual SS cap
threadsmax_scr = 20 // cap for scrape threads
threadsmax_dld = 20 // cap for download threads
}
}
AFscrapeclear()
AF.vernum = AF.version.tofloat() * 10
// GitHub versioning data table
local gh = {
latest_version = 0
release_notes = 0
taglist = []
branchlist = []
releasedatelist = []
commitlist = []
}
function gly(number){
if ((number == null) || (number <= 0) || (number == "")) return ""
number = number.tointeger()
local byte1 = 0xf0 | number >> 18
local byte2 = 0x80 | (number >> 12) & 0x3f
local byte3 = 0x80 | (number >> 6) & 0x3f
local byte4 = 0x80 | number & 0x3f
return (byte1.tochar() + byte2.tochar() + byte3.tochar() + byte4.tochar())
}
AF.subfolder = AF.folder.slice(AF.folder.find("layouts"))
local zmenu = null
local frost = null
// Load language file
// Language is first taken from file if present. If it's not present "EN" is used. After settings the language is updated and file is updated too.
fe.do_nut("nut_language2.nut")
AF.LNG = "EN"
try {AF.LNG = loadlanguage()} catch(err) {}
// font definition
local uifonts = {
gui = "fonts/font_Roboto-Allcaps-EXT4X.ttf"
general = "fonts/font_Roboto-Bold.ttf"
condensed = "fonts/font_Roboto-Condensed-Bold.ttf"
lite = "fonts/font_Roboto-Regular.ttf"
arcade = "fonts/font_CPMono_Black.otf"
arcadeborder = "fonts/font_CPMono_BlackBorder2.otf"
glyphs = "fonts/font_glyphs.ttf"
mono = "fonts/font_RobotoMono-VariableFont_wght.ttf"
monodata = "fonts/font_CQMono.otf"
pixel = 0.711
title = "fonts/Figtree-Bold.ttf"
metapics = "fonts/font_metapics.ttf"
}
function get_png_crc(path){
local f_in = file(path, "rb" )
local blb = f_in.readblob(20*1000*1000)
local IDATcrc = 33
if ((blb[37] == 112) && (blb[38] == 72) && (blb[39] == 89) && (blb[40] == 115)) {
IDATcrc = 33 + blb[36] + 12
}
local bytesize = (blb[IDATcrc] << 24) + (blb[IDATcrc+1] << 16) + (blb[IDATcrc+2] << 8) + blb[IDATcrc+3]
local startpos = IDATcrc + 8 + bytesize
local crcpng = (blb[startpos] << 24) + (blb[startpos+1] << 16) + (blb[startpos+2] << 8) + blb[startpos+3]
return (("0"+format("%X",crcpng)).slice(-8))
}
/// SPLASH SCREEN ///
// Create proxy splash in fullscreen, before even reading options
// this can be used for emergency messages
AF.splash.bg = fe.add_rectangle(0, 0, fe.layout.width, fe.layout.height)
AF.splash.text = fe.add_text("", 0, 0, fe.layout.width, fe.layout.height)
AF.splash.picbg = fe.add_text("", floor(0.5 * (fe.layout.width - AF.splash.size * AF.splash.tscalerate)), floor(0.5 * (fe.layout.height - AF.splash.size * AF.splash.tscalerate)), floor(AF.splash.size * AF.splash.tscalerate), floor(AF.splash.size * AF.splash.tscalerate))
AF.splash.pic = fe.add_text("", AF.splash.picbg.x, AF.splash.picbg.y, AF.splash.picbg.width, AF.splash.picbg.height)
AF.splash.pic.font = AF.splash.picbg.font = uifonts.glyphs
AF.splash.text.font = uifonts.gui
AF.splash.pic.margin = AF.splash.picbg.margin = AF.splash.text.margin = 0
AF.splash.pic.align = AF.splash.picbg.align = AF.splash.text.align = Align.MiddleCentre
AF.splash.pic.charsize = AF.splash.size * AF.splash.tscalerate
AF.splash.picbg.charsize = AF.splash.size * AF.splash.tscalerate
AF.splash.text.charsize = 0.25 * AF.splash.pic.height
AF.splash.bg.zorder = 100000
AF.splash.text.zorder = 100001
AF.splash.picbg.zorder = 100002
AF.splash.pic.zorder = 100003
AF.splash.pic.word_wrap = AF.splash.picbg.word_wrap = AF.splash.text.word_wrap = true
AF.splash.pic.visible = AF.splash.picbg.visible = AF.splash.bg.visible = AF.splash.text.visible = false
AF.splash.pic.set_rgb(255, 255, 255)
AF.splash.picbg.set_rgb(AF.splash.dark, AF.splash.dark, AF.splash.dark)
AF.splash.text.set_rgb(255, 255, 255)
AF.splash.bg.set_rgb(30, 30, 30)
AF.splash.bg.alpha = 190
// command = bar.start to start cycle
// command = bar.stop to stop cycle
function splash_message(command, message = "", seconds = 1) {
if (command == AF.splash.start) {
AF.splash.pic.visible = false
AF.splash.picbg.visible = false
AF.splash.text.msg = message
AF.splash.text.visible = AF.splash.bg.visible = true
fe.layout.redraw()
return
}
if (command == AF.splash.stop) {
AF.splash.pic.visible = false
AF.splash.picbg.visible = false
AF.splash.text.msg = ""
AF.splash.text.visible = AF.splash.bg.visible = false
fe.layout.redraw()
return
}
if (command == AF.splash.pulse) {
AF.splash.time0 = fe.layout.time
AF.splash.pic.visible = false
AF.splash.picbg.visible = false
AF.splash.text.msg = message
AF.splash.text.visible = AF.splash.bg.visible = true
fe.layout.redraw()
while (fe.layout.time - AF.splash.time0 <= 1000 * seconds){
}
AF.splash.pic.visible = false
AF.splash.picbg.visible = false
AF.splash.text.msg = ""
AF.splash.text.visible = AF.splash.bg.visible = false
fe.layout.redraw()
return
}
}
function splash_cycle(command, message = "") {
if (command == AF.splash.start) {
AF.splash.time0 = 0
AF.splash.time1 = 0
AF.splash.progress = 0
AF.splash.pic.visible = true
AF.splash.picbg.visible = true
AF.splash.pic.alpha = 255
AF.splash.picbg.alpha = AF.splash.darkalpha
AF.splash.picbg.msg = gly(0xeafb + 12)
AF.splash.pic.msg = gly(0xeafb)
AF.splash.count = 0
if (message != "") {
AF.splash.text.msg = message + "\n\n\n\n\n"
AF.splash.text.visible = AF.splash.bg.visible = true
}
return
}
if (command == AF.splash.stop) {
AF.splash.time0 = 0
AF.splash.time1 = 0
AF.splash.progress = 0
AF.splash.pic.visible = false
AF.splash.picbg.visible = false
AF.splash.count = 0
AF.splash.text.msg = ""
AF.splash.text.visible = AF.splash.bg.visible = false
return
}
}
function splash_cycle_update(command){
local redraw = false
AF.splash.time1 = fe.layout.time
if (AF.splash.time1 - AF.splash.time0 >= 1000 * AF.splash.syncsecs) {
AF.splash.count = AF.splash.count + 1
if (AF.splash.count == 10) AF.splash.count = 0
AF.splash.pic.msg = gly(0xeb08 + AF.splash.count)
redraw = true
AF.splash.time0 = AF.splash.time1
if (redraw) fe.layout.redraw()
}
}
function splash_progress(i, init, max) {
local redraw = false
if (i == init) {
AF.splash.time0 = 0
AF.splash.time1 = 0
AF.splash.progress = 0
AF.splash.pic.visible = true
AF.splash.picbg.visible = true
AF.splash.pic.alpha = 255
AF.splash.picbg.alpha = AF.splash.darkalpha
AF.splash.picbg.msg = gly(0xeafb + 12)
AF.splash.pic.msg = gly(0xeafb)
return
}
if (i == max - 1) {
AF.splash.pic.visible = false
AF.splash.picbg.visible = false
return
}
AF.splash.time1 = fe.layout.time
if (AF.splash.time1 - AF.splash.time0 >= 1000 * AF.splash.syncsecs) {
if (i <= max * 0.2) {
redraw = true
AF.splash.pic.alpha = 255 * i / (max * 0.2)
AF.splash.picbg.alpha = AF.splash.darkalpha * i / (max * 0.2)
}
else if (i >= max * 0.9) {
redraw = true
AF.splash.pic.alpha = 255 * (1.0 - (i - max * 0.9) / (max * 0.1))
AF.splash.picbg.alpha = 0
}
if (floor(11 * i * 1.0 / max) != AF.splash.progress) {
AF.splash.progress = floor(11 * i * 1.0 / max)
AF.splash.pic.msg = gly(0xeafb + AF.splash.progress)
redraw = true
}
AF.splash.time0 = AF.splash.time1
if (redraw) fe.layout.redraw()
}
}
if (FeVersionNum < 306) {
print ("Arcadeflow requires AM+ 3.0.6+\n")
splash_message(AF.splash.pulse,"Arcadeflow requires AM+ 3.0.6+",5)
}
/// Config management ///
/* Principles of ALLGAMES collections:
FUNCTIONS AND DATA STRUCTURES
parseconfig ()
scans the attract.cfg and returns a table with all the
config data.
During this scan the string "# Enable AF Collections" is
checekd and is used to determine if the function is
enabled as out.collections
The function is called at the beginning of the layout and
results passed to AF.config
z_af_collections
data structure of ALLGAMES collections including a table with
collections names and data and an array that is used to
force the sorting of the collections
buildconfig (allgames)
works directly on AF.config, runs through the AF.config and
removes all the entries related to the ALLGAMES, then
rebuilds the list with all the ALLGAMES entries at the end
of the list.
After rebuilding the config it writes the attract.cfg adding
the ""# Enable AF Collections" if prf.ALLGAMES is true
WORKFLOW
1) AF.config = parseconfig()
Populates the AF.config table, AF.config.collections is true or
false depending on the found string, but notice that this does
not guarantee that ALLGAMES displays are actually there
(someone could've altered them manually)
2) Load the whole layout data
3) prf.ALLGAMES != AF.config.collections
if prf.ALLGAMES is not coherent with AF.config.collections
buildconfig(prf.ALLGAMES) is called, this cleans the attract.cfg
and makes it coherent with the preference set.
After this, if prf.ALLGAMES is true all games collections
are updated using update_allgames_collections (true)
In the end the layout must be reloaded
*/
function restartAM() {
fe.signal("exit_to_desktop")
if (OS == "Windows") system ("start attractplus-console.exe")
else if (OS == "OSX") system ("./attractplus &")
else system ("attractplus &")
}
// This function parses the attract.cfg and returns a table with all useful
// data obtained by the config scan
function parseconfig() {
local cfgfile = ReadTextFile (AF.amfolder + "attract.cfg")
local displaytable = []
local inline = ""
local displayname = ""
local predisplays = []
local postdisplays = []
local id = 0
local af_collections = false
local exitcommand = null
inline = cfgfile.read_line_wtab()
while (inline[0].tochar() == "#") {
if (inline.find("# Enable AF Collections") == 0) af_collections = true
else predisplays.push(inline)
inline = cfgfile.read_line_wtab()
}
while (inline.find("display\t") != 0) {
predisplays.push(inline)
inline = cfgfile.read_line_wtab()
}
while (!cfgfile.eos()) {
//inline = cfgfile.read_line()
if (inline.find("display\t") == 0) {
displayname = split(inline, "\t")[1]
displaytable.push({"display": displayname})
inline = cfgfile.read_line_wtab()
displaytable[id].rawset("filters", [])
while (inline != "") {
switch (split(inline, "\t ")[0]) {
case "layout":
case "romlist":
case "in_cycle":
case "in_menu":
displaytable[id].rawset(split(inline, "\t ")[0], strip(inline).slice(21))
break
case "filter":
case "sort_by":
case "list_limit":
case "exception":
case "global_filter":
case "rule":
displaytable[id].filters.push(inline)
break
}
inline = cfgfile.read_line_wtab()
}
id ++
inline = cfgfile.read_line_wtab()
}
else {
postdisplays.push(inline)
inline = cfgfile.read_line_wtab()
}
}
//Add last read line from stream, which for sure is not a "display"
postdisplays.push(inline)
local warning = false
local tempval = null
local warnstatus = false
local warningstrings = {
"image_cache_mbytes": {checktest = false, checkval = "0", comment = "Should be 0"}
"menu_layout": {checktest = true, checkval = "Arcadeflow", comment = "Don't use AF as menu layout"}
"startup_mode": {checktest = false, checkval = "default", comment = "Use Default startup mode"}
"power_saving": {checktest = false, checkval = "no", comment = "Power Saving can cause glitches"}
}
foreach(i, item in postdisplays) {
item = strip(item) //Remove leading tabs
warnstatus = false
foreach (checkstring, checktable in warningstrings){
if (item.find(checkstring) == 0){
tempval = split(item, " ")
if (tempval.len() > 1){
if (checktable.checktest)
warnstatus = (tempval[1].find(checktable.checkval) == 0)
else
warnstatus = (tempval[1] != checktable.checkval)
if (warnstatus) {
AF.WARN = AF.WARN + subst_replace(char_replace(item," ",""), checkstring, checkstring + ":") + " (" + checktable.comment + ")\n"
warning = true
}
}
}
}
if (item.find("exit_command") == 0) {
exitcommand = strip(item.slice(12, item.len()))
}
}
if (warning) print("\n\nWARNING: some options in attract.cfg clash with Arcadeflow\n\n"+AF.WARN+"\n")
local out = {
header = predisplays
displays = displaytable
footer = postdisplays
collections = af_collections
exitcommand = exitcommand
}
//foreach(i, val in out.footer) print(i + " " + val + "\n")
return (out)
}
// Define AF custom collections
local z_af_collections = {
tab = {}
arr = []
}
z_af_collections.arr = [
{
id = "AF All Games"
group = "COLLECTIONS"
groupedname = "All Games"
ungroupedname = "All Games"
filename = "_all_all"
},
{
id = "AF Favourites"
group = "COLLECTIONS"
groupedname = "Favourites"
ungroupedname = "Favourites"
filename = "_favourites_all"
},
{
id = "AF Last Played"
group = "COLLECTIONS"
groupedname = "Last Played"
ungroupedname = "Last Played"
filename = "_lastplayed_all"
},
{
id = "AF All Arcade Games"
group = "ARCADE"
groupedname = "All Games"
ungroupedname = "All Arcade Games"
filename = "_arcade_all"
},
{
id = "AF All Console Games"
group = "CONSOLE"
groupedname = "All Games"
ungroupedname = "All Console Games"
filename = "_console_all"
},
{
id = "AF All Handheld Games"
group = "HANDHELD"
groupedname = "All Games"
ungroupedname = "All Handheld Games"
filename = "_handheld_all"
},
{
id = "AF All Computer Games"
group = "COMPUTER"
groupedname = "All Games"
ungroupedname = "All Computer Games"
filename = "_computer_all"
},
{
id = "AF All Pinball Games"
group = "PINBALL"
groupedname = "All Games"
ungroupedname = "All Pinball Games"
filename = "_pinball_all"
}
]
foreach(i, item in z_af_collections.arr) {
z_af_collections.tab[item.id] <- item
}
// Update the attract.cfg to incorporate all the collections
// This function doesn't reboot the layout, so changes are not effective
// until AM re-reads the config file
function buildconfig(allgames, tempprf) {
local cfgtable = AF.config
// First step purges special AF collections
local i = 0
while (i < cfgtable.displays.len()) {
if (cfgtable.displays[i].romlist.find("AF ") == 0) cfgtable.displays.remove(i)
else i++
}
// then rebuilds the display list with all collections at the end of the list
if (allgames) {
foreach (item, val in z_af_collections.tab) {
cfgtable.displays.push({
display = item
layout = fe.displays[fe.list.display_index].layout
romlist = item
in_cycle = "yes"
in_menu = "no"
filters = tempprf.MASTERLIST ? ["\tglobal_filter", "\t\trule FileIsAvailable equals 1", "\tfilter All", "\tfilter Favourites", "\t\trule Favourite equals 1"] : ["\tfilter All", "\tfilter Favourites", "\t\trule Favourite equals 1"]
})
}
}
// Starts writing the text file
local cfgfile = WriteTextFile(AF.amfolder + "attract.cfg")
foreach (id, item in cfgtable.header) {
cfgfile.write_line(item + "\n")
}
if (allgames) cfgfile.write_line ("# Enable AF Collections\n")
foreach (item, value in cfgtable.displays) {
cfgfile.write_line ("display\t" + value.display + "\n")
cfgfile.write_line ("\tlayout " + value.layout + "\n")
cfgfile.write_line ("\tromlist " + value.romlist + "\n")
cfgfile.write_line ("\tin_cycle " + value.in_cycle + "\n")
cfgfile.write_line ("\tin_menu " + value.in_menu + "\n")
foreach (item2, val2 in value.filters) {
cfgfile.write_line(((val2.slice(0, 6) == "filter") || (val2 == "global_filter")) ? "\t" + val2 + "\n" : val2 + "\n")
}
cfgfile.write_line("\n")
}
foreach (id, item in cfgtable.footer) {
cfgfile.write_line(item + "\n")
}
cfgfile.close_file()
}
AF.config = parseconfig()
// for debug purposes
function loaddebug() {
local debugpath = AF.folder + "pref_debug.txt"
local debugfile = ReadTextFile (debugpath)
local out = debugfile.read_line()
return (out == "true")
}
function savedebug(savecode) {
local debugpath = AF.folder + "pref_debug.txt"
local debugfile = WriteTextFile(debugpath)
debugfile.write_line(savecode)
debugfile.close_file()
}
local DBGON = false
try {DBGON = loaddebug()} catch(err) {}
function debugpr(instring) {
if (DBGON) print(instring)
}
local download = {
list = [],
num = 0,
numpre = 0,
blanks = null
time0 = 0
time1 = 0
timestep = (OS == "Windows" ? 5000 : 500)
}
local dispatcher = []
local dispatchernum = 0
function scraprt(instring) {
print("DS:" + dispatchernum + " DL:" + download.num + " TR:" + AF.scrape.threads_scr + " - " + AF.scrape.threads_dld+ " " + instring)
}
function testpr(instring) {
print(instring)
}
function testprln(instring) {
print(instring + "\n")
}
function testprln2(instring) {
print("\n" + instring + "\n\n")
}
function unzipfile(zipfilepath, outputpath, updatecycle = false) {
local zipdir = zip_get_dir (zipfilepath)
local blb = null
local fout = null
// Create output folder if needed
system ("mkdir \"" + outputpath + "\"")
foreach (id, item in zipdir) {
if (updatecycle) splash_cycle(null)
// Item is a folder, create it
if ((item.slice(-1) == "/") && (!(split(item, "/")[split(item, "/").len() - 1].slice(0, 1) == "."))) {
system ("mkdir \"" + outputpath + item + "\"")
}
// Item is a file, unpack it to the proper folder
if ((item.slice(-1)!="/") && (!(split(item, "/")[split(item, "/").len() - 1].slice(0, 1) == "."))) {
local savepath = fe.path_expand(outputpath + item)
fout = file(savepath, "wb")
blb = zip_extract_file(zipfilepath, item)
fout.writeblob(blb)
fout.close()
}
}
}
function vartotext(variablein, lev){
local indt = [" "," "," "," "," "," "," "]
local textout = ""
switch (typeof variablein) {
case "table":
textout = textout + ((lev != 0 ? "" : indt[lev]) + "{"+ (variablein.len() == 0 ? "" : "\n"))
foreach (item, val in variablein) {
textout = textout + (indt[lev+1] + "\"" + item + "\" : ") + vartotext(val, lev + 1) + ("\n")
}
textout = textout + (variablein.len() == 0 ? "" : indt[lev]) + ("}\n")
break
case "array":
textout = textout + (lev == 0 ? indt[lev] : "")+ ("[")
foreach (i, val in variablein) {
textout = textout + vartotext(val, lev)
if ((typeof val == "table")) textout = textout + indt[lev]
if (i < variablein.len() - 1) textout = textout + (",")
}
textout = textout + ("]\n")
break
case "string":
textout = textout + ("\""+variablein+"\"")
break
case "integer":
case "bool":
case "float":
textout = textout + (variablein)
break
}
return textout
}
fe.do_nut("nut_picfunctions.nut")
fe.do_nut("nut_gauss.nut")
fe.do_nut("nut_scraper.nut")
dofile(AF.folder + "nut_fileutil.nut")
function savevar(variablein, outfile){
local outarray = split(vartotext(variablein,0),"\n")
outarray.insert(0,"return(")
outarray.push(")")
local f_out = WriteTextFile(fe.path_expand(AF.folder + outfile))
foreach(i, item in outarray){
f_out.write_line (item+"\n")
}
f_out.close_file()
}
function loadvar(infile){
if (!(file_exist(fe.path_expand(AF.folder + infile)))) return null
try {return(dofile(fe.path_expand(AF.folder + infile)))} catch (err){return(null)}
}
function printblanks(){
local dir = DirectoryListing(AF.folder + "/blanks")
local blanks = {}
local tempcrc = null
foreach (item in dir.results) {
tempcrc = get_png_crc(item)
if (!blanks.rawin(tempcrc)) {
blanks.rawset(tempcrc,0)
}
}
savevar(blanks, "data_blanks.txt")
}
//printblanks()
download.blanks = loadvar("data_blanks.txt")
function checkmsec(delay){
download.time1 = fe.layout.time
if ((download.time1 - download.time0) >= delay) {
download.time0 = download.time1
return true
}
else return false
}
/// Preferences functions and table ///
function letterdrives() {
local letters = "CDEFGHIJKLMNOPQRSTUVWXYZ"
local drives = []
foreach (i, item in letters) {
if (fe.path_test (item.tochar() + ":", PathTest.IsDirectory)) drives.push(item.tochar() + ":\\")
}
return drives
}
AF.prefs.driveletters = letterdrives()
local prf = null
local selection_pre = null
local umtable = []
local umpresel = 0
local umvisible = false
local multifilterz = {}
multifilterz.l0 <- {}
function umtablenames(tablein) {
local n0 = []
tablein.sort(@(a, b) a.id <=> b.id)
foreach (i, item in tablein) {
n0.push((item.glyph == -1) ? "----- " + item.label: item.label)
}
return n0
}
function mfztablenames(tablein) {
local outnames = []
foreach (item, val in tablein) {
outnames.push(item)
}
outnames.sort(@(a, b) ltxt(a, AF.LNG).tolower() <=> ltxt(b, AF.LNG).tolower())
foreach (i, item in outnames) {
outnames[i] = ltxt(item, AF.LNG)
}
return (outnames)
}
function sortstring(num) {
local strz = ""
for (local i = 1; i <= num; i++) {
strz = strz + i + comma
}
return strz
}
function languageflags() {
local inputarray = languagetokenarray()
local out = inputarray
foreach (i, item in inputarray) {
out[i] = "flags" + out[i] + AF.prefs.imgext
}
return out
}
function monitorlist() {
local out = []
foreach (id, item in fe.monitors) {
out.push(id.tostring())
}
return (out)
}
local menucounter = 0
local sorter = {}
AF.prefs.l0.push({label = "GENERAL", glyph = 0xe993, description = "Define the main options of Arcadeflow like number of rows, general layout, control buttons, language, thumbnail source etc"})
AF.prefs.l1.push([
{v = 10.2, varname = "LAYOUTLANGUAGE", glyph = 0xe9ca, title = "Layout language", help = "Chose the language of the layout", options = languagearray(), values = languagetokenarray(), selection = 1},
{v = 16.4, varname = "POWERMENU", glyph = 0xe9b6, title = "Power and Exit menu", help = "Customise exit menu with power options", options = ["Exit and Power", "Exit only", "Power only"], values = [true, false, null], selection = 1},