-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdata.lua
More file actions
804 lines (678 loc) · 23.2 KB
/
data.lua
File metadata and controls
804 lines (678 loc) · 23.2 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
zgc = zgc or {}
zgc.cnt = 0
zgc.itemtypes = {
"mining-tool", "repair-tool", "rail-planner", "blueprint-book", "blueprint", "deconstruction-item", "gun", "ammo", "armor","virtual-signal", "module", "tool", "capsule", "selection-tool", "item-with-entity-data"}
zgc.restrictedtypes = {
"assembling-machine","virtual-signal"}
zgc.brutgroups = {
"yuoki","Yuoki","yuoki-energy","yuoki_liquids","yi_engines","yuoki_railway","yie_harvest"}
zgc.grp_list = {
"gathering","production","resources","plates","liquids","chemistry","automatization","transport","defense","energy","logistic","module","intermediate","armor","weaponry","trains-vehicles","decorative","alien","other"}
zgc.mgq = {
{"gathering","production"},
{"automatization","transport","logistic","energy","defense"},
{"intermediate"},
{"trains-vehicles"},
}
zgc.new_ressourse_list = {}
zgc.name_list = {}
function _log(msg,...)
if not z_debug then return "" end
return log("[[ZGC]] "..string.format(msg,...))
end
function table.merge(tab1, tab2)
if type(tab1) == 'table' and type(tab2) == 'table' then
for k,v in pairs(tab2) do
if type(v)=='table' and type(tab1[k] or false)=='table' then
table.merge(tab1[k],v)
elseif type(k) == "number" then
table.insert(tab1,v)
else
tab1[k]=v
end
end
end
return tab1
end
function table.deepcopy(tab)
local tab_type = type(tab)
local copy
if tab_type == 'table' then
copy = {}
for tab_key, tab_value in next, tab, nil do
copy[table.deepcopy(tab_key)] = table.deepcopy(tab_value)
end
setmetatable(copy, table.deepcopy(getmetatable(tab)))
else -- number, string, boolean, etc
copy = tab
end
return copy
end
function table.removekey(tab, key)
local element = tab[key]
tab[key] = nil
_log("Remove key %s from [%s] table",key,tostring(tab))
return element
end
function table.has_value(tab, val)
for index, value in ipairs (tab) do
if value == val then
return true
end
end
return false
end
function dumpvar(data, depth, sortdepth)
local tablecache = {}
local buffer = ""
local padder = " "
local depth = depth or 30
local sortdepth = sortdepth or 0
local function dumpvar(d, _depth)
local t = type(d)
local str = tostring(d)
if (t == "table") then
if (tablecache[str]) then
-- table already dumped before, so we dont
-- dump it again, just mention it
buffer = buffer.."<"..str..">\n"
else
tablecache[str] = (tablecache[str] or 0) + 1
if _depth >= depth then buffer = buffer.."\n"; return end
buffer = buffer..string.format(" {%s-- <%s>\n",padder,str)
if _depth <= sortdepth then
for k, v in pairsByKeys(d) do
buffer = buffer..string.rep(padder, _depth+1).."["..k.."]"
if _depth+1 < depth then buffer = buffer.." => " end
dumpvar(v, _depth+1)
end
else for k, v in pairs(d) do
buffer = buffer..string.rep(padder, _depth+1).."["..k.."]"
if _depth+1 < depth then buffer = buffer.." => " end
dumpvar(v, _depth+1)
end
end
buffer = buffer..string.rep(padder, _depth).."}\n"
end
elseif (t == "number") then
buffer = buffer.."("..t..") "..str.."\n"
else
buffer = buffer.."("..t..") \""..str.."\"\n"
end
end
dumpvar(data, 0)
return buffer
end
function pairsByKeys(t, f)
local a = {}
for n in pairs(t) do table.insert(a, n) end
table.sort(a, f)
local i = 0 -- iterator variable
local iter = function () -- iterator function
i = i + 1
if a[i] == nil then return nil
else return a[i], t[a[i]]
end
end
return iter
end
function zgc.i_get_type(name)
local item_type = nil
local itemtypes_all = table.deepcopy(zgc.itemtypes)
table.insert(itemtypes_all,"fluid")
table.insert(itemtypes_all,"item")
for _,type_name in pairs(itemtypes_all) do
if type_name ~= "recipe" and data.raw[type_name][name] then
if type_name ~= "item" then return type_name end
item_type = type_name
end
end
return item_type
end
function zgc.i_get_basic_type(name)
if data.raw["item-with-entity-data"][name] then return "item-with-entity-data" end
if data.raw.item[name] then return "item" end
if data.raw.fluid[name] then return "fluid" end
return nil
end
function zgc.i_basic_item(inputs)
local item = {}
item.name = inputs.name or inputs[1]
item.amount = inputs.amount or inputs[2] or 1
item.type = inputs.type or zgc.i_get_basic_type(item.name) or "item"
return item
end
function zgc.i_item(inputs)
local item = {}
item.name = inputs.name or inputs[1]
item.amount = inputs.amount or inputs[2]
item.probability = inputs.probability or nil
item.type = inputs.type or zgc.i_get_basic_type(item.name) or "item"
if not item.amount then
item.amount_min = inputs.amount_min or nil
item.amount_max = inputs.amount_max or nil
else item.amount = 1 end
return item
end
function zgc.i_combine(item1_in, item2_in)
local item = {}
local item1 = zgc.i_item(item1_in)
local item2 = zgc.i_item(item2_in)
item.name = item1.name
item.type = item1.type
if item1.amount then
item.amount = item1.amount + (item2.amount or 0)
else
item.amount_min = (item1.amount_min or item1.amount or 1) + (item2.amount_min or item2.amount or 0)
item.amount_max = (item1.amount_max or item1.amount or 1) + (item2.amount_max or item2.amount or 0)
end
item1.probability = (item1.probability or 1) + (item2.probability or 1) / 2
return item
end
function zgc.i_add_inc(list, item_in)
local item = zgc.i_item(item_in)
local flag = true
for i, obj in pairs(list) do
if obj[1] == item.name or obj.name == item.name then
flag = false
obj = zgc.i_combine(obj, item)
end
end
if flag then table.insert(list, item) end
end
function zgc.i_add_new(list, item_in)
local item = zgc.i_item(item_in)
for _,object in pairs(list) do
if item.name == zgc.i_basic_item(object).name then return end
end
table.insert(list, item)
end
function zgc.i_remove(list, item)
for i, obj in ipairs(list) do
if obj[1] == item or obj.name == item then
table.remove(list, i)
end
end
end
function zgc.r_remove_ingredient(recipe, item)
if data.raw.recipe[recipe] then
zgc.i_remove(data.raw.recipe[recipe].ingredients, item)
else
_log("Recipe %s does not exist.",recipe)
end
end
function zgc.r_remove_ingredient_in_all(item)
for recipe_name,recipe in pairs(data.raw.recipe) do
local _ingr = false
for _,ingredient in pairs(recipe) do
if ingredient[1] == item or (ingredient.name and ingredient.name == item) then _ingr = true end
end
if _ingr then zgc.r_remove_ingredient(recipe_name,item) end
end
end
function zgc.r_add_new_ingredient(recipe, item)
if data.raw.recipe[recipe] and zgc.i_get_type(i_basic_item(item).name) then
zgc.i_add_new(data.raw.recipe[recipe].ingredients, zgc.i_basic_item(item))
else
if not data.raw.recipe[recipe] then
_log("Recipe %s does not exist.",recipe)
end
if not zgc.i_get_type(item) then
_log("Ingredient %s does not exist.",i_basic_item(item).name)
end
end
end
function zgc.r_add_ingredient(recipe, item)
if data.raw.recipe[recipe] and zgc.i_get_type(zgc.i_basic_item(item).name) then
zgc.i_add_inc(data.raw.recipe[recipe].ingredients, zgc.i_basic_item(item))
else
if not data.raw.recipe[recipe] then
_log("Recipe %s does not exist.",recipe)
end
if not zgc.i_get_basic_type(zgc.i_basic_item(item).name) then
_log("Ingredient %s does not exist.",i_basic_item(item).name)
end
end
end
function zgc.r_replace_ingredient(recipe, old, new)
local new = new or "raw-wood"
if data.raw.recipe[recipe] and zgc.i_get_type(new) then
local amount = 0
for i, ingredient in pairs(data.raw.recipe[recipe].ingredients) do
if ingredient[1] == old then
amount = ingredient[2] + amount
end
if ingredient.name == old then
amount = ingredient.amount + amount
end
end
if amount > 0 then
zgc.r_remove_ingredient(recipe, old)
zgc.r_add_ingredient(recipe, {new, amount})
end
else
if not data.raw.recipe[recipe] then
_log("Recipe %s does not exist.",recipe)
end
if not zgc.i_get_type(new) then
_log("Ingredient %s does not exist.",new)
end
end
end
function zgc.r_replace_ingredient_in_all(old, new)
local new = new or "raw-wood"
if zgc.i_get_basic_type(new) then
for i, recipe in pairs(data.raw.recipe) do
zgc.r_replace_ingredient(recipe.name, old, new)
end
else
_log("Ingredient %s does not exist.",new)
end
end
function zgc.t_add_recipe_unlock(technology, recipe)
if data.raw.technology[technology] and data.raw.recipe[recipe] then
data.raw.technology[technology].effects = data.raw.technology[technology].effects or {}
for i, effect in pairs(data.raw.technology[technology].effects) do
if effect.type == "unlock-recipe" and effect.recipe == recipe then return end
end
table.insert(data.raw.technology[technology].effects,{type = "unlock-recipe", recipe = recipe})
else
if not data.raw.technology[technology] then
_log("technology %s does not exist.",technology)
end
if not data.raw.recipe[recipe] then
_log("Recipe %s does not exist.",recipe)
end
end
end
function zgc.t_remove_prerequisite(technology, prerequisite)
if data.raw.technology[technology] then
for i, check in ipairs(data.raw.technology[technology].prerequisites) do
if check == prerequisite then
table.remove(data.raw.technology[technology].prerequisites, i)
end
end
else
_log("technology %s does not exist.",technology)
end
end
function zgc.t_remove_recipe_unlock(technology, recipe)
if data.raw.technology[technology] and data.raw.technology[technology].effects then
for i, effect in pairs(data.raw.technology[technology].effects) do
if effect.type == "unlock-recipe" and effect.recipe == recipe then
table.remove(data.raw.technology[technology].effects,i)
end
end
elseif not data.raw.technology[technology] then
_log("technology %s does not exist.",technology)
end
end
function i_exist(item)
for _,v in pairs(zgc.name_list) do
if v == item then return true end
end
return false
end
function i_not_exist(item)
return not i_exist(item)
end
function iadd(group,name,order,ico,anim)
local group = zgc.get_group_name(group,name)
if not order then zgc.cnt = zgc.cnt+1 end
local order = order or "z"..zgc.cnt
local typeof = zgc.i_get_type(name) or "item"
local ico = ico or false
local anim = anim or false
--# Item
if table.has_value(zgc.itemtypes, typeof) then
if not data.raw[typeof][name] then return end
data.raw[typeof][name].subgroup = group
data.raw[typeof][name].order = order
data.raw[typeof][name].flags = data.raw[typeof][name].oldflags or data.raw[typeof][name].flags
if ico then data.raw[typeof][name].icon = ico end
if anim then data.raw[typeof][name].animation.filename = anim end
_log("ADD (%s) %s to %s : %s",string.upper(typeof),name,group,order)
return
elseif data.raw["fluid"][name] then
data.raw["fluid"][name].subgroup = group
data.raw["fluid"][name].order = order
data.raw["fluid"][name].flags = data.raw["fluid"][name].oldflags or data.raw["fluid"][name].flags
if ico then data.raw["fluid"][name].icon = ico end
_log("ADD (%s) %s to %s : %s",string.upper(typeof),name,group,order)
return
end
if not data.raw.item[name] then return end
data.raw.item[name].subgroup = group
data.raw.item[name].order = order
data.raw.item[name].flags = data.raw.item[name].oldflags or data.raw.item[name].flags
if ico then data.raw.item[name].icon = ico end
if anim then data.raw.item[name].animation.filename = anim end
_log("ADD ITEM %s to %s : %s",name,group,order)
end
function radd(group,recipe,order,ico)
local group = zgc.get_group_name(group,name)
if not order then zgc.cnt = zgc.cnt+1 end
local order = order or "z"..zgc.cnt
local recipe = recipe or zgc.find_recipe(name)
local ico = ico or false
--# Recipe
if data.raw.recipe[recipe] then
data.raw.recipe[recipe].subgroup = group
data.raw.recipe[recipe].order = order
data.raw.recipe[recipe].hidden = false
if ico then data.raw.recipe[recipe].icon = ico end
_log("ADD RECIPE %s to %s : %s",recipe,group,order)
end
end
function aadd(group,name,order,ico,anim,addrecipe)
if not order then zgc.cnt = zgc.cnt+1 end
local order = order or "z"..zgc.cnt
local typeof = zgc.i_get_type(name) or "item"
local ico = ico or false
local anim = anim or false
local recipe = zgc.find_recipe(name)
local addrecipe = addrecipe or true
iadd(group,name,order,ico,anim)
if addrecipe then radd(group,recipe,order,ico) end
end
function ihide(name,replase,typeof)
if z_balance_Prevent_hiding then return end
local replase = replase or false
local typeof = typeof or zgc.i_get_type(name) or "item"
--# Item
if not data.raw[typeof][name] then return end
data.raw[typeof][name].flags = data.raw[typeof][name].flags or {}
data.raw[typeof][name].oldflags = data.raw[typeof][name].flags
data.raw[typeof][name].flags = {"hidden"}
--# Replace items
if replase then
_log("REPLACE %s => %s",name,replase)
zgc.r_replace_ingredient_in_all(name, replase)
end
end
function rhide(name,recipe)
if z_balance_Prevent_hiding then return end
local recipe = recipe or zgc.find_recipe(name)
--# technology
local tech_name = ""
for t_name,t_data in pairs(data.raw.technology) do
if t_data.effects then
for _,effect in ipairs(t_data.effects) do
if effect.recipe and effect.recipe == recipe
then tech_name = t_name end
end
end
end
if #tech_name > 0 then
_log("[[REMOVE]] %s from [%s]",name,tech_name)
zgc.t_remove_recipe_unlock(tech_name, name)
end
--# Recipe
if data.raw.recipe[recipe] then
data.raw.recipe[recipe].hidden = true
end
end
function ahide(name,replase)
if z_balance_Prevent_hiding then return end
local typeof = zgc.i_get_type(name) or "item"
local replase = replase or false
local recipe = zgc.find_recipe(name)
ihide(name,replase,typeof)
rhide(name,recipe)
end
function switch_tech(tname,flag)
if z_balance_Prevent_hiding then return end
if data.raw.technology[tname] then
local flag = flag or false
if flag then
if data.raw.technology[tname].hidden_effects then
data.raw.technology[tname].effects = table.deepcopy(data.raw.technology[tname].hidden_effects)
data.raw.technology[tname].hidden_effects = nil
end
else
if data.raw.technology[tname].effects then
data.raw.technology[tname].hidden_effects = table.deepcopy(data.raw.technology[tname].effects)
data.raw.technology[tname].effects = nil
end
end
data.raw.technology[tname].enabled = flag
end
end
function zgc.find_recipe(item, brute)
if not item or data.raw.recipe[item] then return item end
local r_list = {}
table.insert(r_list, item)
table.insert(r_list, item.."-recipe")
table.insert(r_list, item.."_recipe")
if string.find(item,"-") then
table.insert(r_list, string.gsub(item,"(-)","_").."")
table.insert(r_list, string.gsub(item,"(-)","_").."-recipe")
table.insert(r_list, string.gsub(item,"(-)","_").."_recipe")
end
if string.find(item,"_") then
table.insert(r_list, string.gsub(item,"(_)","-").."")
table.insert(r_list, string.gsub(item,"(_)","-").."-recipe")
table.insert(r_list, string.gsub(item,"(_)","-").."_recipe")
end
for _,v in pairs(r_list) do
if data.raw.recipe[v] then
if item ~= v then _log("FIND RECIPE (%s) for %s",v,item) end
return v
end
end
local recipe
local brute = brute or false
if not brute and data.raw.item[item] and data.raw.item[item].group then
brute = table.has_value(zgc.brutgroups, data.raw.item[item].group)
end
if brute then
for _name,_data in pairs(data.raw.recipe) do
if _data.result then
if (type(_data.result) == "table" and _data.result.name == item)
or (type(_data.result) == "string" and _data.result == item) then
_log("BRUTE RECIPE (%s) for %s",_name,item)
return _name
end
elseif _data.results and type(_data.results) == "table" then
for _,v in pairs(_data.results) do
if v.name and v.name == item then
_log("BRUTE RECIPE (%s) for %s",_name,item)
return _name
end
end
end
end
end
return item
end
function zgc.add_recipe_to_tech(t,r)
local _r = zgc.find_recipe(r)
if data.raw.technology[t] and data.raw.recipe[_r] then
_log('RECIPE2TECH "%s"',_r)
data.raw.recipe[_r].enabled = false
data.raw.technology[t].enabled = true
data.raw.technology[t].hidden = false
zgc.t_add_recipe_unlock(t,_r)
else
_log('[[RECIPE2TECH FAIL]] "%s"',_r)
end
end
function zgc.add_newRessource_min_max(main_source, it, mn, mx, pb, it2, mn2, mx2, pb2)
if not data.raw.item[it] then return end
local _res1 = {
type = "item",
name = it,
amount_min = mn,
amount_max = mx,
probability = pb
}
local _res2 = {
type = "item",
name = it2,
amount_min = mn2,
amount_max = mx2,
probability = pb2
}
if main_source == "raw-wood" then
local tree_names = {"green-coral","tree-01","tree-02","tree-02-red","tree-03","tree-04","tree-05","tree-06","tree-06-brown","tree-07","tree-08","tree-08-brown","tree-08-red","tree-09","tree-09-brown","tree-09-red"}
for k in pairs(tree_names) do
local tree = data.raw.tree[k]
if tree and type(tree.minable) == "table" then
if zgc.new_ressourse_list[k] == nil then zgc.new_ressourse_list[k] = {} end
if type(tree.minable.results) == "table" then
for _,v in pairs(tree.minable.results) do
table.insert(zgc.new_ressourse_list[k],v) end
table.insert(zgc.new_ressourse_list[k],_res1)
if it2 ~= nil and data.raw.item[it2] then table.insert(zgc.new_ressourse_list[k],_res2) end
elseif tree.minable.result ~= nil then
local count = tree.minable.count or 2
table.insert(zgc.new_ressourse_list[k],{
type = "item",
name = "raw-wood",
amount_min = tree.minable.amount_min or math.ceil(count/2),
amount_max = tree.minable.amount_max or count,
probability = 1
})
table.insert(zgc.new_ressourse_list[k],_res1)
if it2 ~= nil and data.raw.item[it2] then table.insert(zgc.new_ressourse_list[k],_res2) end
end
end
end
elseif data.raw.resource[main_source] and type(data.raw.resource[main_source].minable) == "table" then
local source_col = {main_source, main_source.."__tm", "infinite-"..main_source, "infinite-"..main_source.."__tm"}
for _,source in pairs(source_col) do if data.raw.resource[source] then
if type(data.raw.resource[source].minable.results) == "table" then
zgc.new_ressourse_list[source] = table.deepcopy(data.raw.resource[source].minable.results)
else
zgc.new_ressourse_list[source] = zgc.new_ressourse_list[source] or {}
local count = data.raw.resource[source].minable.count or 2
table.insert(zgc.new_ressourse_list[source],{
type = "item",
name = main_source,
amount_min = data.raw.resource[source].minable.amount_min or math.ceil(count/2),
amount_max = data.raw.resource[source].minable.amount_max or count,
probability = 1
})
end
table.insert(zgc.new_ressourse_list[source],_res1)
if it2 ~= nil and data.raw.item[it2] then table.insert(zgc.new_ressourse_list[source],_res2) end
end end
end
end
function zgc.add_newRessource_finalize()
for k,v in pairs(data.raw.tree) do
if zgc.new_ressourse_list[k] ~= nil then
v.minable.result = nil
v.minable.count = nil
v.minable.results = {}
v.minable.results = table.deepcopy(zgc.new_ressourse_list[k])
end
end
for k,v in pairs(data.raw.resource) do
if zgc.new_ressourse_list[k] ~= nil then
v.minable.result = nil
v.minable.count = nil
v.minable.results = {}
v.minable.results = table.deepcopy(zgc.new_ressourse_list[k])
end
end
end
function zgc.generate_main_groups()
local c = 0
local z = ""
for _,g in pairs(zgc.grp_list) do c=c+1
if c<10 then z="0" else z="" end
zgc.add_main_group(g)
end
end
function zgc.add_main_group(name,order)
local order = order or ""
data:extend({{
type = "item-group",
name = "zgc-"..name,
order = "0 0 zgc-"..order,
inventory_order = "0 0 zgc-"..order,
icon = "__ZGroupChange__/graphics/icons/cat/"..name..".png",
}})
end
function zgc.ig(name)
return data.raw["item-group"][name] or data.raw["item-group"]["zgc-"..name] or nil
end
function zgc.isg(name)
return data.raw["item-subgroup"][name] or data.raw["item-subgroup"]["zgc-"..name] or nil
end
function zgc.resort_main_groups(que)
local cnt = 1
for r=1,5 do for c=1,6 do
if zgc.mgq[r] and zgc.mgq[r][c] then
zgc.group_order("zgc-"..zgc.mgq[r][c], "0 0 zgc-"..r..c)
elseif que and que[cnt] then
zgc.group_order("zgc-"..que[cnt], "0 0 zgc-"..r..c)
cnt = cnt+1
else break end
end end
end
function zgc.get_base_name(name,plus)
if name:match('^z[-]%a+[-]%d+$') then name = name:match("^z[-](%a+)[-]%d+$"):gsub("-","") end
return name
end
function zgc.get_main_group(name)
local name = zgc.get_base_name(name)
if string.find(name,"trains") or string.find(name,"vehicles") then
name = string.gsub(name,"(trains)(vehicles)", "trains-vehicles")
end
for k,_ in pairs(data.raw["item-group"]) do
if string.find(k,name) and k:match('^zgc[-]') then return k end
end
return false
end
function zgc.get_group_name(name,item)
if data.raw["item-subgroup"][name] then return name end
local _name = name:match("^z[-](%a+[-]%d%d?)$") or name
_name = "zgc-".._name
if data.raw["item-subgroup"][_name] then return _name end
local order = name:match('[-](%d%d?)$')
if tonumber(order) then
if tonumber(order) < 10 then order = '0'..order end
else
_log("[get_group_name] tonumber(%s) = %s",name,order or "nil")
order = name
end
if string.find(name, "trains") then order = "t "..order end
if string.find(name, "vehicles") then order = "v "..order end
local main_group = zgc.get_main_group(name)
if main_group then
_log("ADD NEW SUB GROUP [%s] for %s",_name,main_group)
data.raw["item-subgroup"][_name] = {
type = "item-subgroup",
name = _name,
group = main_group,
order = order
}
else
_log("ADD UNKNOWN SUB GROUP [%s] to OTHER (reason: %s)",_name,item)
data.raw["item-subgroup"][_name] = {
type = "item-subgroup",
name = _name,
group = "zgc-other",
order = order
}
end
return _name
end
function zgc.group_order(g_name,order)
if data.raw["item-group"][g_name] then
data.raw["item-group"][g_name].order = order
data.raw["item-group"][g_name].inventory_order = order
end
end
function zgc.set_icon(item,ico)
local typeof = zgc.i_get_type(item) or "item"
local recipe = zgc.find_recipe(item)
if data.raw[typeof][item] then
data.raw[typeof][item].icon = ico
end
if data.raw.recipe[recipe] then
data.raw.recipe[recipe].icon = ico
end
end