Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
minetest_game
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
minetest_game
Commits
b1ab8d51
Unverified
Commit
b1ab8d51
authored
4 years ago
by
sfan5
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Implement searching for translated names in creative inventory (#2675)
parent
6e345cf1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mods/creative/inventory.lua
+26
-4
26 additions, 4 deletions
mods/creative/inventory.lua
with
26 additions
and
4 deletions
mods/creative/inventory.lua
+
26
−
4
View file @
b1ab8d51
...
@@ -61,6 +61,7 @@ function creative.init_creative_inventory(player)
...
@@ -61,6 +61,7 @@ function creative.init_creative_inventory(player)
return
player_inventory
[
player_name
]
return
player_inventory
[
player_name
]
end
end
local
NO_MATCH
=
999
local
function
match
(
s
,
filter
)
local
function
match
(
s
,
filter
)
if
filter
==
""
then
if
filter
==
""
then
return
0
return
0
...
@@ -68,7 +69,15 @@ local function match(s, filter)
...
@@ -68,7 +69,15 @@ local function match(s, filter)
if
s
:
lower
():
find
(
filter
,
1
,
true
)
then
if
s
:
lower
():
find
(
filter
,
1
,
true
)
then
return
#
s
-
#
filter
return
#
s
-
#
filter
end
end
return
nil
return
NO_MATCH
end
local
function
description
(
def
,
lang_code
)
local
s
=
def
.
description
if
lang_code
then
s
=
minetest
.
get_translated_string
(
lang_code
,
s
)
end
return
s
:
gsub
(
"
\n
.*"
,
""
)
-- First line only
end
end
function
creative
.
update_creative_inventory
(
player_name
,
tab_content
)
function
creative
.
update_creative_inventory
(
player_name
,
tab_content
)
...
@@ -84,13 +93,26 @@ function creative.update_creative_inventory(player_name, tab_content)
...
@@ -84,13 +93,26 @@ function creative.update_creative_inventory(player_name, tab_content)
local
items
=
inventory_cache
[
tab_content
]
or
init_creative_cache
(
tab_content
)
local
items
=
inventory_cache
[
tab_content
]
or
init_creative_cache
(
tab_content
)
local
lang
local
player_info
=
minetest
.
get_player_information
(
player_name
)
if
player_info
and
player_info
.
lang_code
~=
""
then
lang
=
player_info
.
lang_code
end
local
creative_list
=
{}
local
creative_list
=
{}
local
order
=
{}
local
order
=
{}
for
name
,
def
in
pairs
(
items
)
do
for
name
,
def
in
pairs
(
items
)
do
local
m
=
match
(
def
.
description
,
inv
.
filter
)
or
match
(
def
.
name
,
inv
.
filter
)
local
m
=
match
(
description
(
def
),
inv
.
filter
)
if
m
then
if
m
>
0
then
m
=
math.min
(
m
,
match
(
description
(
def
,
lang
),
inv
.
filter
))
end
if
m
>
0
then
m
=
math.min
(
m
,
match
(
name
,
inv
.
filter
))
end
if
m
<
NO_MATCH
then
creative_list
[
#
creative_list
+
1
]
=
name
creative_list
[
#
creative_list
+
1
]
=
name
-- Sort by
description length
first so closer matches appear earlier
-- Sort by
match value
first so closer matches appear earlier
order
[
name
]
=
string.format
(
"%02d"
,
m
)
..
name
order
[
name
]
=
string.format
(
"%02d"
,
m
)
..
name
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment