@@ -61,14 +61,23 @@ function creative.init_creative_inventory(player)
61
61
return player_inventory [player_name ]
62
62
end
63
63
64
+ local NO_MATCH = 999
64
65
local function match (s , filter )
65
66
if filter == " " then
66
67
return 0
67
68
end
68
69
if s :lower ():find (filter , 1 , true ) then
69
70
return # s - # filter
70
71
end
71
- return nil
72
+ return NO_MATCH
73
+ end
74
+
75
+ local function description (def , lang_code )
76
+ local s = def .description
77
+ if lang_code then
78
+ s = minetest .get_translated_string (lang_code , s )
79
+ end
80
+ return s :gsub (" \n .*" , " " ) -- First line only
72
81
end
73
82
74
83
function creative .update_creative_inventory (player_name , tab_content )
@@ -84,13 +93,26 @@ function creative.update_creative_inventory(player_name, tab_content)
84
93
85
94
local items = inventory_cache [tab_content ] or init_creative_cache (tab_content )
86
95
96
+ local lang
97
+ local player_info = minetest .get_player_information (player_name )
98
+ if player_info and player_info .lang_code ~= " " then
99
+ lang = player_info .lang_code
100
+ end
101
+
87
102
local creative_list = {}
88
103
local order = {}
89
104
for name , def in pairs (items ) do
90
- local m = match (def .description , inv .filter ) or match (def .name , inv .filter )
91
- if m then
105
+ local m = match (description (def ), inv .filter )
106
+ if m > 0 then
107
+ m = math.min (m , match (description (def , lang ), inv .filter ))
108
+ end
109
+ if m > 0 then
110
+ m = math.min (m , match (name , inv .filter ))
111
+ end
112
+
113
+ if m < NO_MATCH then
92
114
creative_list [# creative_list + 1 ] = name
93
- -- Sort by description length first so closer matches appear earlier
115
+ -- Sort by match value first so closer matches appear earlier
94
116
order [name ] = string.format (" %02d" , m ) .. name
95
117
end
96
118
end
0 commit comments