1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2024-12-25 18:20:38 +01:00

Improve node name normalization in case of multi-line descriptions

This commit is contained in:
sfan5 2020-03-29 21:55:47 +02:00
parent 06a3b63578
commit 5e8bfd5166

View File

@ -122,8 +122,9 @@ local function check_region(name)
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
end end
-- Strips any kind of escape codes (translation, colors) from a string
-- https://github.com/minetest/minetest/blob/53dd7819277c53954d1298dfffa5287c306db8d0/src/util/string.cpp#L777 -- https://github.com/minetest/minetest/blob/53dd7819277c53954d1298dfffa5287c306db8d0/src/util/string.cpp#L777
local function strip_translation_escapes(input) local function strip_escapes(input)
local s = function(idx) return input:sub(idx, idx) end local s = function(idx) return input:sub(idx, idx) end
local out = "" local out = ""
local i = 1 local i = 1
@ -169,7 +170,7 @@ worldedit.normalize_nodename = function(nodename)
end end
end end
for key, value in pairs(minetest.registered_nodes) do for key, value in pairs(minetest.registered_nodes) do
local desc = strip_translation_escapes(value.description):lower() local desc = strip_escapes(value.description):gsub("\n.*", "", 1):lower()
if desc == nodename then -- matches description if desc == nodename then -- matches description
return key return key
end end