items/mcl_banners: reuse `escape` across functions

This commit is contained in:
E 2021-05-01 23:57:39 -04:00
parent 48dd5267dd
commit cb4173ac9e
1 changed files with 4 additions and 8 deletions

View File

@ -144,6 +144,10 @@ local on_destruct_hanging_banner = function(pos)
return on_destruct_banner(pos, true)
end
local function escape(text)
return text:gsub("%^", "\\%^"):gsub(":", "\\:") -- :gsub("%(", "\\%("):gsub("%)", "\\%)")
end
local make_banner_overlay = function(base_color, layers)
local colorize = mcl_banners.colors[base_color][4]
-- Base texture with base color
@ -163,10 +167,6 @@ local make_banner_overlay = function(base_color, layers)
lovl = (lovl ~= "" and (lovl .. "^") or "") .. layer
end
local function escape(text)
return text:gsub("%^", "\\%^"):gsub(":", "\\:") -- :gsub("%(", "\\%("):gsub("%)", "\\%)")
end
return "[combine:32x32:0,0=" .. escape(base) .. ":7,3=" .. escape("("..lovl.."^[resize:50x38)")
end
return base
@ -430,10 +430,6 @@ for colorid, colortab in pairs(mcl_banners.colors) do
local layer = "(([combine:20x40:-2,-2="..pattern.."^[resize:16x24^[colorize:"..color..":"..layer_ratio.."))"
function escape(text)
return text:gsub("%^", "\\%^"):gsub(":", "\\:") -- :gsub("%(", "\\%("):gsub("%)", "\\%)")
end
finished_banner = "[combine:32x32:0,0=" .. escape(base) .. ":8,4=" .. escape(layer)
end