@@ -155,18 +155,6 @@ function craftguide.register_craft_type(name, def)
155
155
craft_types [name ] = def
156
156
end
157
157
158
- local function get_width (recipe )
159
- if is_table (recipe ) then
160
- sort (recipe , function (a , b )
161
- return # a > # b
162
- end )
163
-
164
- return # recipe [1 ]
165
- end
166
-
167
- return 0
168
- end
169
-
170
158
local function clean_name (item )
171
159
return match (item , " %S+" )
172
160
end
@@ -198,7 +186,11 @@ function craftguide.register_craft(def)
198
186
end
199
187
200
188
local cp = copy (def .grid )
201
- def .width = get_width (cp )
189
+ sort (cp , function (a , b )
190
+ return # a > # b
191
+ end )
192
+
193
+ def .width = # cp [1 ]
202
194
203
195
for i = 1 , # def .grid do
204
196
while # def .grid [i ] < def .width do
@@ -294,6 +286,7 @@ local function groups_item_in_recipe(item, recipe)
294
286
for _ , recipe_item in pairs (recipe .items ) do
295
287
if is_group (recipe_item ) then
296
288
local groups = extract_groups (recipe_item )
289
+
297
290
if item_has_groups (item_groups , groups ) then
298
291
local usage = copy (recipe )
299
292
table_replace (usage .items , recipe_item , item )
@@ -338,6 +331,7 @@ local function get_usages(item)
338
331
for _ , recipes in pairs (recipes_cache ) do
339
332
for i = 1 , # recipes do
340
333
local recipe = recipes [i ]
334
+
341
335
if item_in_recipe (item , recipe ) then
342
336
c = c + 1
343
337
usages [c ] = recipe
@@ -424,18 +418,7 @@ local function repairable(tool)
424
418
end
425
419
426
420
local function get_tooltip (item , info )
427
- local function get_desc (def , name )
428
- name = name or item
429
- return def and def .description or
430
- (def and match (name , " :.*" ):gsub (" %W%l" , upper ):sub (2 ):gsub (" _" , " " ) or
431
- S (" Unknown Item (@1)" , name ))
432
- end
433
-
434
- local tooltip = get_desc (reg_items [item ])
435
-
436
- local function add (str )
437
- return tooltip .. " \n " .. str
438
- end
421
+ local tooltip
439
422
440
423
if info .groups then
441
424
local groupstr , c = {}, 0
@@ -447,6 +430,21 @@ local function get_tooltip(item, info)
447
430
448
431
groupstr = concat (groupstr , " , " )
449
432
tooltip = S (" Any item belonging to the group(s): @1" , groupstr )
433
+
434
+ return fmt (" tooltip[%s;%s]" , item , ESC (tooltip ))
435
+ end
436
+
437
+ local function get_desc (def , name )
438
+ name = name or item
439
+ return def and def .description or
440
+ (def and match (name , " :.*" ):gsub (" %W%l" , upper ):sub (2 ):gsub (" _" , " " ) or
441
+ S (" Unknown Item (@1)" , name ))
442
+ end
443
+
444
+ tooltip = get_desc (reg_items [item ])
445
+
446
+ local function add (str )
447
+ return tooltip .. " \n " .. str
450
448
end
451
449
452
450
if info .cooktime then
@@ -614,7 +612,7 @@ local function get_recipe_fs(data, fs)
614
612
for j = 1 , # replacements do
615
613
local replacement = replacements [j ]
616
614
if replacement [1 ] == item then
617
- label = ( label ~= " " and " \n " or " " ) .. label .. " \n R"
615
+ label = label .. " \n R"
618
616
replace = replacement [2 ]
619
617
end
620
618
end
@@ -626,25 +624,20 @@ local function get_recipe_fs(data, fs)
626
624
627
625
local burntime = fuel_cache [item ] and fuel_cache [item ].burntime
628
626
629
- local more_info
630
- local infos = {
627
+ local info = {
631
628
groups = groups ,
632
629
burntime = burntime ,
633
630
cooktime = cooktime ,
634
631
replace = replace ,
635
632
repair = nil ,
636
633
}
637
634
638
- for _ , v in pairs (infos ) do
635
+ for _ , v in pairs (info ) do
639
636
if v then
640
- more_info = true
637
+ fs [ # fs + 1 ] = get_tooltip ( item , info )
641
638
break
642
639
end
643
640
end
644
-
645
- if more_info then
646
- fs [# fs + 1 ] = get_tooltip (item , infos )
647
- end
648
641
end
649
642
650
643
get_output_fs (fs , {
@@ -836,14 +829,14 @@ end
836
829
837
830
-- As `core.get_craft_recipe` and `core.get_all_craft_recipes` do not return the replacements,
838
831
-- we have to override `core.register_craft` and `core.register_alias` and do some reverse engineering.
839
- -- See engine's issue #4901.
832
+ -- See engine's issues #4901 and #8920 .
840
833
841
834
local old_register_alias = core .register_alias
842
835
local current_alias = {}
843
836
844
837
core .register_alias = function (old , new )
845
- current_alias = {old , new }
846
838
old_register_alias (old , new )
839
+ current_alias = {old , new }
847
840
end
848
841
849
842
local old_register_craft = core .register_craft
@@ -889,7 +882,7 @@ core.register_craft = function(recipe)
889
882
recipe .items [# recipe .items + 1 ] = recipe .recipe [j ]
890
883
end
891
884
else
892
- recipe .width = get_width ( recipe .recipe )
885
+ recipe .width = # recipe .recipe [ 1 ]
893
886
local c = 1
894
887
895
888
for j = 1 , # recipe .recipe do
@@ -944,10 +937,9 @@ on_joinplayer(function(player)
944
937
init_data (name )
945
938
end )
946
939
947
- local function _fields (player , fields )
940
+ local function fields (player , _f )
948
941
local name = player :get_player_name ()
949
942
local data = pdata [name ]
950
- local _f = fields
951
943
952
944
if _f .clear then
953
945
reset_data (data )
@@ -963,10 +955,10 @@ local function _fields(player, fields)
963
955
return true
964
956
965
957
elseif (_f .key_enter_field == " filter" or _f .search ) and _f .filter ~= " " then
966
- local fltr = lower (_f .filter )
967
- if data .filter == fltr then return end
958
+ local str = lower (_f .filter )
959
+ if data .filter == str then return end
968
960
969
- data .filter = fltr
961
+ data .filter = str
970
962
data .pagenum = 1
971
963
search (data )
972
964
@@ -1039,14 +1031,14 @@ if sfinv_only then
1039
1031
end
1040
1032
end ,
1041
1033
1042
- on_player_receive_fields = function (self , player , context , fields )
1043
- _fields (player , fields )
1034
+ on_player_receive_fields = function (self , player , context , _f )
1035
+ fields (player , _f )
1044
1036
end ,
1045
1037
})
1046
1038
else
1047
- on_receive_fields (function (player , formname , fields )
1039
+ on_receive_fields (function (player , formname , _f )
1048
1040
if formname == " craftguide" then
1049
- _fields (player , fields )
1041
+ fields (player , _f )
1050
1042
end
1051
1043
end )
1052
1044
0 commit comments