-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfactorioTreeGen.lua
More file actions
1757 lines (1641 loc) · 52.1 KB
/
Copy pathfactorioTreeGen.lua
File metadata and controls
1757 lines (1641 loc) · 52.1 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
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
--Factorio tree graph generator
--by Microeinstein
--[[
Personal factorio notes:
- For recipes:
If there are "normal" and "expensive",
choose the right one,
else
choose base table;
- For technologies:
Multiply by price multiplier;
Difficulty doesn't have any effect in vanilla;
]]--
local framework, loadError = loadfile("personalFramework.lua")
if loadError then
error(loadError)
end
framework()
local pref = {
nl = "\n",
font = "Calibri",--"Titillium Web",
font2 = "Calibri",
fsizen = 16,
fsizee = 12,--9,
fsizeg = 15,
rotangle = 0,--270,
}
local graphML = {
-- (nodes+edges; resources)
boilerplate = table.concat({
[[<?xml version="1.0" encoding="UTF-8" standalone="no"?>]],
[[<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:java="http://www.yworks.com/xml/yfiles-common/1.0/java" xmlns:sys="http://www.yworks.com/xml/yfiles-common/markup/primitives/2.0" xmlns:x="http://www.yworks.com/xml/yfiles-common/markup/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xmlns:yed="http://www.yworks.com/xml/yed/3" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">]],
--[[<!--Created by yEd 3.18.1.1-->]]
[[<!--Created by Factorio Tree Graph Generator (by Microeinstein)-->]],
[[<key attr.name="Description" attr.type="string" for="graph" id="d0"/>]],
[[<key for="port" id="d1" yfiles.type="portgraphics"/>]],
[[<key for="port" id="d2" yfiles.type="portgeometry"/>]],
[[<key for="port" id="d3" yfiles.type="portuserdata"/>]],
[[<key attr.name="url" attr.type="string" for="node" id="d4"/>]],
[[<key attr.name="description" attr.type="string" for="node" id="d5"/>]],
[[<key for="node" id="d6" yfiles.type="nodegraphics"/>]],
[[<key for="graphml" id="d7" yfiles.type="resources"/>]],
[[<key attr.name="url" attr.type="string" for="edge" id="d8"/>]],
[[<key attr.name="description" attr.type="string" for="edge" id="d9"/>]],
[[<key for="edge" id="d10" yfiles.type="edgegraphics"/>]],
[[<graph edgedefault="directed" id="G">]],
[[<data key="d0"/>]],
[[%s</graph>]],
[[<data key="d7">]],
[[%s</data>]],
[[</graphml>]],
}, pref.nl)..pref.nl,
-- (id; fillColor; labels)
node = table.concat({
[[<node id="%s">]],
[[<data key="d6">]],
[[<y:ShapeNode>]],
[[<y:Geometry height="32.0" width="94.033203125"/>]],
[[<y:Fill color="#%s" transparent="false"/>]],
[[<y:BorderStyle hasColor="false" raised="false" type="line" width="1.0"/>]],
[[%s<y:Shape type="roundrectangle"/>]],
[[</y:ShapeNode>]],
[[</data>]],
[[</node>]],
}, pref.nl)..pref.nl,
-- (id; fillColor; labels; resource)
imageNode = table.concat({
[[<node id="%s">]],
[[<data key="d5"/>]],
[[<data key="d6">]],
[[<y:ImageNode>]],
[[<y:Geometry width="%s" height="%s"/>]],
[[<y:Fill color="#%s" transparent="false"/>]],
[[<y:BorderStyle color="#000000" type="line" width="1.0"/>]],
[[%s<y:Image alphaImage="true" refid="%d"/>]],
[[</y:ImageNode>]],
[[</data>]],
[[</node>]],
}, pref.nl)..pref.nl,
-- (number; source; target; lineColor; lineType; sourceArrow; targetArrow; labels)
edge = table.concat({
[[<edge id="e%d" source="%s" target="%s">]],
[[<data key="d10">]],
[[<y:QuadCurveEdge straightness="1.0">]],
[[<y:Path sx="0.0" sy="0.0" tx="0.0" ty="0.0"/>]],
[[<y:LineStyle color="#%s" type="%s" width="1.0"/>]],
[[<y:Arrows source="%s" target="%s"/>]],
[[%s</y:QuadCurveEdge>]],
[[</data>]],
[[</edge>]],
}, pref.nl)..pref.nl,
-- (backgroundColor; lineColor; color; text)
labels = {
N22 = table.concat({
[[<y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="]]..pref.font..[[" fontSize="]]..pref.fsizen..[[" fontStyle="plain" %s %s height="19.9609375" horizontalTextPosition="center" iconTextGap="4" modelName="custom" textColor="#%s" verticalTextPosition="bottom" visible="true" width="10.46875">%s<y:LabelModel>]],
[[<y:SmartNodeLabelModel distance="4.0"/>]],
[[</y:LabelModel>]],
[[<y:ModelParameter>]],
[[<y:SmartNodeLabelModelParameter labelRatioX="0.0" labelRatioY="0.0" nodeRatioX="0.0" nodeRatioY="0.0" offsetX="0.0" offsetY="0.0" upX="0.0" upY="-1.0"/>]],
[[</y:ModelParameter>]],
[[</y:NodeLabel>]],
}, pref.nl)..pref.nl,
N23 = [[<y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="]]..pref.font..[[" fontSize="]]..pref.fsizen..[[" fontStyle="plain" %s %s height="18.701171875" horizontalTextPosition="center" iconTextGap="4" modelName="sandwich" modelPosition="s" textColor="#%s" verticalTextPosition="bottom" visible="true" width="22.673828125">%s</y:NodeLabel>]]..pref.nl,
E21 = table.concat({
[[<y:EdgeLabel alignment="center" rotationAngle="]]..pref.rotangle..[[" distance="2.0" fontFamily="]]..pref.font2..[[" fontSize="]]..pref.fsizee..[[" fontStyle="plain" %s %s height="18.701171875" horizontalTextPosition="center" iconTextGap="4" modelName="three_center" modelPosition="scentr" preferredPlacement="source_on_edge" ratio="0.5" textColor="#%s" verticalTextPosition="bottom" visible="true" width="10.673828125">%s]],
[[<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" placement="source" side="on_edge" sideReference="relative_to_edge_flow"/>]],
[[</y:EdgeLabel>]],
}, pref.nl)..pref.nl,
E23 = table.concat({
[[<y:EdgeLabel alignment="center" rotationAngle="]]..pref.rotangle..[[" distance="2.0" fontFamily="]]..pref.font2..[[" fontSize="]]..pref.fsizee..[[" fontStyle="plain" %s %s height="18.701171875" horizontalTextPosition="center" iconTextGap="4" modelName="three_center" modelPosition="tcentr" preferredPlacement="target_on_edge" ratio="0.5" textColor="#%s" verticalTextPosition="bottom" visible="true" width="10.673828125">%s]],
[[<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" placement="target" side="on_edge" sideReference="relative_to_edge_flow"/>]],
[[</y:EdgeLabel>]],
}, pref.nl)..pref.nl,
E33 = table.concat({
[[<y:EdgeLabel alignment="center" rotationAngle="]]..pref.rotangle..[[" distance="2.0" fontFamily="]]..pref.font2..[[" fontSize="]]..pref.fsizee..[[" fontStyle="plain" %s %s height="18.701171875" horizontalTextPosition="center" iconTextGap="4" modelName="six_pos" modelPosition="ttail" preferredPlacement="target_right" ratio="0.5" textColor="#%s" verticalTextPosition="bottom" visible="true" width="10.673828125">%s]],
[[<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" placement="target" side="right" sideReference="relative_to_edge_flow"/>]],
[[</y:EdgeLabel>]],
}, pref.nl)..pref.nl,
},
lineTypes = {
line = [[line]],
dashed = [[dashed]],
dashed_dotted = [[dashed_dotted]],
},
arrowTypes = {
none = [[none]],
black = [[standard]],
white = [[white_delta]],
crows_foot_optional = [[crows_foot_optional]],
},
-- (id; title; text?; id..":"; nodes)
group = table.concat({
[[<node id="%s" yfiles.foldertype="group">]],
[[<data key="d4"/>]],
[[<data key="d5"/>]],
[[<data key="d6">]],
[[<y:ProxyAutoBoundsNode>]],
[[<y:Realizers active="0">]],
[[<y:GroupNode>]],
[[<y:Geometry height="153.37646484375" width="327.0166015625"/>]],
[[<y:Fill color="#F5F5F5" transparent="false"/>]],
[[<y:BorderStyle color="#000000" type="dashed" width="1.0"/>]],
[[<y:NodeLabel alignment="right" autoSizePolicy="node_width" backgroundColor="#EBEBEB" borderDistance="0.0" fontFamily="]]..pref.font..[[" fontSize="]]..pref.fsizeg..[[" fontStyle="plain" hasLineColor="false" height="22.37646484375" horizontalTextPosition="center" iconTextGap="4" modelName="internal" modelPosition="t" textColor="#000000" verticalTextPosition="bottom" visible="true" width="327.0166015625">%s</y:NodeLabel>]],
[[<y:Shape type="roundrectangle"/>]],
[[<y:State closed="false" closedHeight="50.0" closedWidth="50.0" innerGraphDisplayEnabled="false"/>]],
[[<y:Insets bottom="15" bottomF="15.0" left="15" leftF="15.0" right="15" rightF="15.0" top="15" topF="15.0"/>]],
[[<y:BorderInsets bottom="0" bottomF="0.0" left="0" leftF="0.0" right="0" rightF="0.0" top="0" topF="0.0"/>]],
[[</y:GroupNode>]],
[[<y:GroupNode>]],
[[<y:Geometry height="50.0" width="50.0"/>]],
[[<y:Fill color="#F5F5F5" transparent="false"/>]],
[[<y:BorderStyle color="#000000" type="dashed" width="1.0"/>]],
[[<y:NodeLabel alignment="right" autoSizePolicy="node_width" backgroundColor="#EBEBEB" borderDistance="0.0" fontFamily="]]..pref.font..[[" fontSize="]]..pref.fsizeg..[[" fontStyle="plain" hasLineColor="false" height="22.37646484375" horizontalTextPosition="center" iconTextGap="4" modelName="internal" modelPosition="t" textColor="#000000" verticalTextPosition="bottom" visible="true" width="59.02685546875">%s</y:NodeLabel>]],
[[<y:Shape type="roundrectangle"/>]],
[[<y:State closed="true" closedHeight="50.0" closedWidth="50.0" innerGraphDisplayEnabled="false"/>]],
[[<y:Insets bottom="5" bottomF="5.0" left="5" leftF="5.0" right="5" rightF="5.0" top="5" topF="5.0"/>]],
[[<y:BorderInsets bottom="0" bottomF="0.0" left="0" leftF="0.0" right="0" rightF="0.0" top="0" topF="0.0"/>]],
[[</y:GroupNode>]],
[[</y:Realizers>]],
[[</y:ProxyAutoBoundsNode>]],
[[</data>]],
[[<graph edgedefault="directed" id="%s">]],
[[%s</graph>]],
[[</node>]],
}, pref.nl)..pref.nl,
resources = {
empty = [[<y:Resources/>]]..pref.nl,
notEmpty = table.concat({
[[<y:Resources>]],
[[%s</y:Resources>]],
}, pref.nl)..pref.nl,
-- (number; base64/" ")
entry = [[<y:Resource id="%d" type="java.awt.image.BufferedImage">%s</y:Resource>]]..pref.nl,
},
}
function showHelp(exitCode)
local ac = {1,2,3,5,6}
local nt
local n1 = math.random(1, #ac)
nt = n1
n1 = ac[n1]
ac[nt] = nil
ac = table.compact(ac)
local n2 = math.random(1, #ac)
nt = n2
n2 = ac[n2]
ac[nt] = nil
ac = table.compact(ac)
local c1 = "\27[0;1;3"..n1.."m"
local c2 = "\27[0;1;3"..n2.."m"
local cr = "\27[0m"
local helpText = table.concat({
"",
c1.."Factorio tree graph generator tool, by Microeinstein"..cr,
" "..c2.."Syntax"..cr..": [-h] [-e] [-t <num>] [-nl|-li -lt]",
" <factorio_dir> <output_file>",
"",
" "..c2.."Arguments"..cr..":",
" <factorio_dir> The directory of your factorio installation",
" <output_file> The output path for the graph",
"",
" "..c2.."Options"..cr..":",
" -h --help Show this text",
" -e Use expensive recipes",
" -t <num> Multiply technologies prices",
" -nl Do not group items in levels",
" -li Make links between levels instead of inputs",
" -lt Make links between levels instead of technologies",
"",
}, "\n");
print(helpText)
os.exit(exitCode or 0)
end
function loadArgs()
local argsLen = #arg
if argsLen == 0 then
showHelp(1)
end
if table.contains(arg, "-h")
or table.contains(arg, "--help")
or table.contains(arg, "/?") then
showHelp(0)
end
local optExp = false
local optTechMul = 1
local factorioDir = nil
outputFile = nil
local noMoreOptions = false
noLevels = false
lightInputs = false
lightTech = false
local function shiftArgs()
arg[1] = nil
arg = table.compact(arg)
argsLen = argsLen - 1
end
local function parseNextArg()
local a = arg[1]
local ok = false
if a == nil or argsLen == 0 then
return false
end
::retry_arg::
if noMoreOptions then
if factorioDir == nil then
factorioDir = a
ok = true
elseif outputFile == nil then
outputFile = a
ok = true
end
else
if a == "-t" then
shiftArgs()
local b = tonumber(arg[1])
if not b or b < 1 then
print("Invalid number (-t).")
os.exit(3)
end
optTechMul = b
ok = true
elseif a == "-e" then
optExp = true
ok = true
elseif a == "-nl" then
noLevels = true
ok = true
elseif a == "-li" then
lightInputs = true
ok = true
elseif a == "-lt" then
lightTech = true
ok = true
else
noMoreOptions = true
goto retry_arg
end
end
if ok then
shiftArgs()
return true
end
end
repeat until not parseNextArg()
lightInputs = not noLevels and lightInputs
lightTech = not noLevels and lightTech
if not factorioDir then
print("Please specify Factorio directory")
showHelp(1)
end
if not outputFile then
print("Please specify output file path")
showHelp(1)
end
game.dirs.root = factorioDir
game.recipes.expensive = optExp
game.technologies.multiplier = optTechMul
end
function debugFunctions()
local badstring = "\u{0061}a\u{00c5}\197\197\u{253C}\195\u{251C}"
print(badstring, "\n")
print(utf8.len(badstring), "\n")
for p, v, u in utf8.codes("abc") do print(p, v, u, v & 0xc0, v & 0x40, v & 0x80) end
print()
for p, v, u in utf8.codes(badstring) do print(p, v, u, v & 0xc0, v & 0x40, v & 0x80) end
print()
local slice = ";abc;de/;f;;ghi;"
print(slice, "\n")
for _, s in ipairs(string.split(slice, ";", "/")) do print(#s == 0 and "[empty]" or s) end
print()
local dirs = {"aa", "bb" .. path.dirSep, path.dirSep .. "cc" .. path.dirSep}
print(table.unpack(dirs))
print(path.combine(table.unpack(dirs)))
print()
local tableSample = {
2, 2, 2,
a = "b",
c = "d",
}
tableSample[tableSample] = 5
rPrint(table.makePrototype(tableSample), 10, "Prototype")
local treeSample = {
{{name="a"}, {name="b"}, {name="c"}},
{{name="d"}, {name="e"}, {name="f"}, {name="g"}}
}
rPrint(table.blend(treeSample), 10, "Blended TreeSample")
os.exit()
end
function loadConsts()
game.dirs.data = path.combine(game.dirs.root, "data")
game.dirs.base = path.combine(game.dirs.data, "base")
game.dirs.core = path.combine(game.dirs.data, "core")
game.dirs.prototypes = path.combine(game.dirs.base, "prototypes")
game.dirs.graphics = path.combine(game.dirs.base, "graphics")
game.dirs.recipes = path.combine(game.dirs.prototypes, "recipe")
game.dirs.technologies = path.combine(game.dirs.prototypes, "technology")
game.dirs.icons = {
recipes = path.combine(game.dirs.graphics, "icons"),
technologies = path.combine(game.dirs.graphics, "technology"),
}
game.files.dataloader = path.combine(game.dirs.core, "lualib", "dataloader.lua")
game.files.recipes = path.getFiles(game.dirs.recipes)
game.files.technologies = path.getFiles(game.dirs.technologies)
game.files.icons = {
recipes = path.getFiles(game.dirs.icons.recipes, true),
technologies = path.getFiles(game.dirs.icons.technologies, true),
}
end
function printFinalArgs()
--rPrint(game, 10, "Game")
local align = { true, false }
local rows1 = {
{"OS", process.isWindows and "Windows" or "Surely not windows" },
{"ANSI support", tostring(process.ansiSupported) },
{"Directory", game.dirs.root },
{"Expensive recipes", tostring(game.recipes.expensive) },
{"Tech price multiplier", tostring(game.technologies.multiplier) },
{"Use levels", tostring(not noLevels) },
{"Light input links", tostring(lightInputs) },
{"Light tech. links", tostring(lightTech) },
}
local rows2 = {
{"Data loader", game.files.dataloader },
{"Recipes folder", game.dirs.recipes },
{"Tech. folder", game.dirs.technologies },
{"Graphics folder", game.dirs.graphics },
{"Recipes images amount", tostring(#(game.files.icons.recipes)) },
{"Tech. images amount", tostring(#(game.files.icons.technologies)) },
}
printBoxes(false,
buildText(makeRows({{"Factorio recipes combiner v1.0", "by Microeinstein"}}, align), term.box1v),
buildText(makeRows(rows1, align), term.box1v),
buildText(makeRows(rows2, align), term.box1v)
)
printBoxes(false,
"Recipes",
buildText(makeRows(game.files.recipes, align), term.box1v)
)
printBoxes(false,
"Technologies",
buildText(makeRows(game.files.technologies, align), term.box1v)
)
print()
end
function loadFiles()
if table.len(game.files.recipes) < 1 then
error("No recipes found!")
end
loadfile(game.files.dataloader)()
for i, v in pairs(game.files.recipes) do
loadfile(path.combine(game.dirs.recipes, v))()
end
for i, v in pairs(game.files.technologies) do
loadfile(path.combine(game.dirs.technologies, v))()
end
game.recipes.data = data.raw.recipe
game.technologies.data = data.raw.technology
game.recipes.amount = table.len(game.recipes.data)
game.technologies.amount = table.len(game.technologies.data)
end
local lastStatus, counter, problems, notproblems
local numObj, numRec, numTec, filterRT, filterOT, filterOR, filterORT
local function startTask(str)
io.write(" " .. string.padLeft(str .. "...", 45))
lastStatus = ""
counter = 0
problems = 0
notproblems = false
end
local function printStatus(value, target)
local s
if target ~= nil then
local num = math.round(value / target * 100)
num = math.round(num / 5) * 5
s = tostring(num) .. "%"
else
s = tostring(value)
end
if s ~= lastStatus then
term.moveCursor(0, -(#lastStatus))
--io.write(string.rep(" ", #lastStatus))
--term.moveCursor(0, -(#lastStatus))
io.write(s)
lastStatus = s
end
end
local function endTask()
term.moveCursor(0, -(#lastStatus))
io.write(string.rep(" ", #lastStatus))
term.moveCursor(0, -(#lastStatus))
io.write("OK")
if problems > 0 or counter > 0 then
local perc = math.round(problems / counter * 100)
io.write(string.format(" %s: %d/%d (%d%%)", notproblems and "Skips" or "Errors", problems, counter, perc))
end
print()
end
function assembleTables()
local function collectObject(t, n, e, input, output)
local i, v = table.first(game.objects.data, function(i, v)
return v.type == t and v.name == n
end)
if i == nil then
i = #(game.objects.data) + 1
v = {
type = t,
name = n,
input = {}, --recipes or technologies containing this object as ingredient
output = {}, --recipes containing this object as result
}
game.objects.data[i] = v
end
if input then
v.input[#(v.input) + 1] = e
end
if output then
v.output[#(v.output) + 1] = e
end
return v
end
local function taskSR()
for _, r in pairs(game.recipes.data) do
if (r.normal and not r.expensive) or (not r.normal and r.expensive) then
error(r.name .. " has some problems... (difficuity)")
elseif r.expensive then --and of course "r.normal"
table.extract( --difficuity specific tables should not contain "resultS"
game.recipes.expensive and r.expensive or r.normal,
{"enabled", "energy_required", "ingredients", "result", "results", "result_count"},
r, false
)
r.normal = nil
r.expensive = nil
end
--standard results
if (not r.result and not r.results)
or (r.result and r.results)
or (r.results and r.result_count) then
error(r.name .. " has some problems... (results)")
end
--too simple to normal
for k, v in pairs(r.ingredients) do
local t, n, a = (v.type or "item"), (v.name), (v.amount)
if not n then
if #v == 2 then
n = v[1]
a = v[2]
else
error(r.name .. " has some problems... (ingredients)")
end
end
--grouping objects
local obj = collectObject(t, n, r, true, false)
v = {
amount = a,
object = obj
}
r.ingredients[k] = v
end
--too simple to normal
if r.result then
r.results = {{
name = r.result,
amount = r.result_count,
}}
end
for k, v in pairs(r.results) do
local t = v.type or "item"
local n = v.name
--grouping objects
local obj = collectObject(t, n, r, false, true)
v = {
amount = v.amount or 1,
probability = v.probability or 1,
object = obj
}
r.results[k] = v
end
r.category = r.category or "crafting"
r.energy_required = r.energy_required or 0.5 --time in seconds
--cleaning
--r.main_product = nil
r.result = nil
r.result_count = nil
r.enabled = r.enabled == nil and true or r.enabled
--r.order = nil
end
end
local function taskUT()
local function isUnlocker(t)
return table.exists(t.effects, function(k, v) return v.type == "unlock-recipe" end)
end
notproblems = true
for k, v in pairs(table.where(game.technologies.data, function(k, v) return v.unit.count_formula end)) do
if isUnlocker(v) then
error("Hey doc, we have a problem")
end
counter = counter + 1
game.technologies.data[k] = nil
end
for k, v in pairs(table.where(game.technologies.data, function(k, v) return v.upgrade or v.max_level or v.level end)) do
counter = counter + 1
if not isUnlocker(v) then
game.technologies.data[k] = nil
else
problems = problems + 1
end
end
end
local function taskMT()
for _, t in pairs(game.technologies.data) do
if not t.unit.count then
error(t.name .. " has some problems... (unit.count)")
end
t.unit.count = t.unit.count * game.technologies.multiplier
end
end
local function taskST()
for _, t in pairs(game.technologies.data) do
for k, v in pairs(t.unit.ingredients) do
if type(v[1]) == "string" and type(v[2]) == "number" then
local obj = collectObject("item", v[1], t, true, false)
v = {
amount = v[2],
object = obj
}
t.unit.count = t.unit.count * game.technologies.multiplier
t.unit.ingredients[k] = v
else
error(t.name .. " has some problems... (ingredients)")
end
end
--t.unit.count = nil
t.effects = t.effects or {}
--[[Technologies can have no effects (aka just unlock other technologies)
if #(t.effects) < 1 then
error(t.name .. " has some problems... (effects)")
end]]
for k, v in pairs(t.effects) do
if v.type == "unlock-recipe" then
v.recipe = game.recipes.data[v.recipe]
end
end
t.prerequisites = t.prerequisites or {}
for k, v in pairs(t.prerequisites) do
if type(v) ~= "string" then
error(t.name .. " has some problems... (prerequisites)")
end
t.prerequisites[k] = game.technologies.data[v]
end
end
end
local function taskIR()
for _, r in pairs(game.recipes.data) do
r.icon = table.first(game.files.icons.recipes, function(k,v) return string.contains(v, r.name) end)
if not r.icon then
problems = problems + 1
end
printStatus(counter, game.recipes.amount)
counter = counter + 1
end
end
local function taskIT()
for _, t in pairs(game.technologies.data) do
t.icon = table.first(game.files.icons.technologies, function(k,v) return string.contains(v, t.name) end)
if not t.icon then
problems = problems + 1
end
printStatus(counter, game.technologies.amount)
counter = counter + 1
end
end
local function taskTN()
numObj = table.allNumerical(game.objects.data)
numRec = table.allNumerical(game.recipes.data)
numTec = table.allNumerical(game.technologies.data)
printStatus(1, 2)
filterRT = table.combine{numRec, numTec}
filterOT = table.combine{numObj, numTec}
filterOR = table.combine{numObj, numRec}
filterORT = table.combine{numObj, numRec, numTec}
printStatus(2, 2)
end
local function taskBA()
local function filterTint(a)
return
a.primary ~= nil and
a.secondary ~= nil and
a.tertiary ~= nil and
type(a.primary) == "table" and
type(a.secondary) == "table" and
type(a.tertiary) == "table" and
#a == 0 and
table.len(a) == 3
end
printStatus(0, 3)
game.objects.blended = table.blend(numObj, filterRT)
printStatus(1, 3)
game.recipes.blended = table.blend(numRec, filterOT, filterTint)
printStatus(2, 3)
game.technologies.blended = table.blend(numTec, filterOR)
printStatus(3, 3)
end
local function taskDE()
notproblems = true
local treeLevel = 0
local index = 1
local function addTo(lvl, k, tab, element)
if not table.contains(tab, element) then
local i = lvl.amounts[k] + 1
tab[i] = element
lvl.amounts[k] = i
end
end
local function removeAndCompact(from, elements)
for _, v1 in pairs(elements) do
for k2, _ in pairs(table.where(from, function(k, v) return v == v1 end)) do
from[k2] = nil
end
end
return table.compact(from)
end
local function makeNextLevel()
local level = {
technologies = {},
recipes = {},
inputs = {},
outputs = {},
amounts = {
t = 0,
r = 0,
i = 0,
o = 0
}
}
local debugName = "speed-module"
local debugTech = false
local debugRecipe = false
local function lvl1()
level.outputs = table.takeWhere(game.objects.data, function(i, o)
return #(o.output) == 0
end)
level.amounts.o = #(level.outputs)
end
local function lvlNext()
local blended = table.blend(game.tree, filterORT)
for k, v in pairs(blended.amounts) do
if type(v) == "table" then
v = table.aggregate(v, function(i, a, b) return a + b end)
blended.amounts[k] = v
end
end
local function checkTech1(t)
for _, p in pairs(t.prerequisites) do
if not table.exists(blended.technologies, function(i, t) return t.name == p.name end) then
if debugTech and t.name == debugName then
print(i.object.name.." tech does not exists")
end
return false
end
end
return true
end
local function checkTech2(t)
for _, i in pairs(t.unit.ingredients) do
if not table.contains(blended.outputs, i.object) then
if debugTech and t.name == debugName then
print(i.object.name.." ingredient does not exists")
end
return false
end
end
return true
end
for n, t in pairs(game.technologies.data) do
local c1 = not table.contains(blended.technologies, t)
local c2 = c1 and checkTech1(t)
local c3 = c2 and checkTech2(t)
if debugTech and t.name == debugName then
print(treeLevel, c1, c2, c3)
end
if c3 then
addTo(level, "t", level.technologies, t)
end
end
local function checkRecipe0(r)
if r.enabled then -- (if true or object, not false or nil)
return r.enabled
end
local unlocksThis =
table.takeWhere(blended.technologies, function(i, t) return
table.exists(t.effects, function(i, e) return
e.type == "unlock-recipe" and e.recipe == r
end)
end)
if debugRecipe and r.name == debugName then
print(#unlocksThis.." unlocking technologies")
end
if #unlocksThis < 1 then
return false
end
--r.enabled = unlocksThis --CHANGED FROM ORIGINAL
return true
end
local function checkRecipe1(r)
for _, i in pairs(r.ingredients) do
if not table.contains(blended.outputs, i.object) then
if debugRecipe and r.name == debugName then
print(i.object.name.." ingredient does not exists")
end
return false
end
end
return true
end
for n, r in pairs(game.recipes.data) do
local c1 = not table.contains(blended.recipes, r)
local c2 = c1 and checkRecipe0(r)
local c3 = c2 and checkRecipe1(r)
if debugRecipe and r.name == debugName then
print(treeLevel, c1, c2, c3)
end
if c3 then
addTo(level, "r", level.recipes, r)
end
end
for i1, t in pairs(level.technologies) do
for i2, i in pairs(t.unit.ingredients) do
addTo(level, "i", level.inputs, i.object)
end
end
for i1, r in pairs(level.recipes) do
for i2, i in pairs(r.ingredients) do
addTo(level, "i", level.inputs, i.object)
end
for i2, rs in pairs(r.results) do
addTo(level, "o", level.outputs, rs.object)
end
end
end
treeLevel = treeLevel + 1
if treeLevel < 2 then
lvl1()
else
lvlNext()
end
return level
end
local lvl, notEmpty = nil, true
while notEmpty do
lvl = makeNextLevel()
notEmpty =
lvl.amounts.t > 0 or
lvl.amounts.r > 0 or
lvl.amounts.i > 0 or
lvl.amounts.o > 0
if notEmpty then
game.tree[treeLevel] = lvl
printStatus(treeLevel, 18) --change maximum in case of new Factorio version
counter = counter + 1
else
--print("Level "..treeLevel.." is empty!")
end
end
end
local allTasks = {
{ f = taskSR, n = "Standardizing recipes structures" },
{ f = taskUT, n = "Removing futile technologies" },
{ f = taskMT, n = "Multiplying technologies prices" },
{ f = taskST, n = "Standardizing technologies structures" },
--{ f = taskIR, n = "Putting recipes icons" },
--{ f = taskIT, n = "Putting technologies icons" },
{ f = taskTN, n = "Enumerating tables for filters" },
{ f = taskBA, n = "Blending tables" },
{ f = taskDE, n = "Sorting dependencies tree" },
}
print("[ASSEMBLING]")
for i, t in ipairs(allTasks) do
startTask(i .. ". " .. t.n)
t.f()
endTask()
end
print()
end
function exploreTables()
print("[EXPLORING]")
local namePrefix = ""
local prefix = " "
local pauseAtTables = true
local pauseAtValues = false
local function explore(depth, tab, title)
rPrint(tab, depth, namePrefix .. title, pauseAtTables, pauseAtValues, prefix)
end
--explore(2, data, "Data")
--explore(2, game.objects.blended, "Blended Objects")
--explore(3, game.recipes.data["iron-plate"].results[1].object, "iron-plate")
--explore(2, game.recipes.data, "Recipes")
--explore(5, game.recipes.blended, "Blended Recipes")
--explore(2, game.recipes.blended.ingredients, "Blended Recipes (ingredients)")
--explore(2, game.recipes.blended.icon, "Blended Recipes (icon)")
--explore(2, game.technologies.data, "Technologies")
--explore(5, game.technologies.blended, "Blended Technologies")
--explore(2, game.technologies.blended.prerequisites, "Blended Technologies (prerequisites)")
--explore(2, game.technologies.blended.effects, "Blended Technologies (effects)")
--[[Debug test
local blendedTree = table.blend(game.tree, filterORT)
local testName = "speed-module"
if table.exists(blendedTree.recipes, function(k, v) return v.name == testName end) then
print("That's pretty good")
else
print("Recipe not in tree!")
if table.contains(game.recipes.blended.name, testName) then
print("At least it exist...")
else
print("It does not even exist!") --this is really bad
end
error()
end]]
--explore(4, game.tree, "GeneratedTree")
--explore(3, blendedTree, "Blended Tree")
print("Everything seems ok.")
print()
end
function buildGraph()
local black = {hue = 0, saturation = 0, value = 0}
local white = {hue = 0, saturation = 0, value = 1}
local lightPurple = {hue = 270, saturation = 0.18, value = 1}
local lightBlue = {hue = 235, saturation = 0.18, value = 1}
--[[Prototypes
group = {
parent = {node},
nodes = {node..},
name = "group",
*ID
}
node = {
parent = {node},
color = {color},
labels = {label..},
data = {*}, -->node~nodes
*ID
}
edge = {
source = {node},
target = {node},
line = "lineType",
arrows = {
source = "arrow",
target = "arrow",
},
color = {color},
labels = {label..},
}
color = {
hue = 0.0,
saturation = 0.0,
value = 0.0,
*hex = "123abc",
}
label = {
type = "labelType",
color = {color},
text = "str",
}
]]
local graph = {
nodes = {}
}
local selected = graph
local edges = {}
local resources = graphML.resources.empty--""
local final
--local resourceNum = 1
local line1 = graphML.lineTypes.line
local line2 = graphML.lineTypes.dashed
local line3 = graphML.lineTypes.dashed_dotted
local arrow0 = graphML.arrowTypes.none
local arrow1 = graphML.arrowTypes.black
local arrow2 = graphML.arrowTypes.white
local arrow3 = graphML.arrowTypes.crows_foot_optional
local label1 = graphML.labels.E23
local label2 = graphML.labels.E21
local edgePresets = {
_ttg = {color=black, darker=false, arrow1=arrow3, line=line3, arrow2=arrow2},
_trg = {color=black, darker=false, arrow1=arrow3, line=line2, arrow2=arrow2},
_tt = {color=2, darker=false, arrow1=arrow0, line=line3, arrow2=arrow2},
_tr = {color=1, darker=true, arrow1=arrow0, line=line2, arrow2=arrow2},
_it = {color=1, darker=true, arrow1=arrow0, line=line1, arrow2=arrow1},
_oig = {color=black, darker=false, arrow1=arrow3, line=line1, arrow2=arrow1},
_oi = {color=1, darker=true, arrow1=arrow0, line=line1, arrow2=arrow1},
_ir = {color=1, darker=true, arrow1=arrow0, line=line1, arrow2=arrow1},
_ro = {color=1, darker=false, arrow1=arrow0, line=line1, arrow2=arrow1},
}