From c4272d8d248769f1a8efe2d9a1077904eff64f13 Mon Sep 17 00:00:00 2001 From: Wuzzy2 Date: Mon, 11 Feb 2019 00:18:10 +0100 Subject: [PATCH] Add formspec escape, apply proper format strings --- init.lua | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/init.lua b/init.lua index 1821164..d2aa6e6 100644 --- a/init.lua +++ b/init.lua @@ -13,6 +13,7 @@ local searches = {} local progressive_mode = mt.settings:get_bool("craftguide_progressive_mode") local sfinv_only = mt.settings:get_bool("craftguide_sfinv_only") and rawget(_G, "sfinv") +local fs_esc = mt.formspec_escape local reg_items = mt.registered_items local get_result = mt.get_craft_result local show_formspec = mt.show_formspec @@ -293,22 +294,22 @@ local function get_tooltip(item, groups, cooktime, burntime) end groupstr = concat(groupstr, ", ") - tooltip = S("Any item belonging to the group(s):") .. " " .. groupstr + tooltip = S("Any item belonging to the group(s): @1", groupstr) else tooltip = reg_items[item].description end if cooktime then - tooltip = tooltip .. "\n" .. S("Cooking time:") .. " " .. - mt.colorize("yellow", cooktime) + tooltip = tooltip .. "\n" .. S("Cooking time: @1", + mt.colorize("yellow", cooktime)) end if burntime then - tooltip = tooltip .. "\n" .. S("Burning time:") .. " " .. - mt.colorize("yellow", burntime) + tooltip = tooltip .. "\n" .. S("Burning time: @1", + mt.colorize("yellow", burntime)) end - return "tooltip[" .. item .. ";" .. tooltip .. "]" + return "tooltip[" .. item .. ";" .. fs_esc(tooltip) .. "]" end local function get_recipe_fs(data, iY) @@ -332,7 +333,7 @@ local function get_recipe_fs(data, iY) fs[#fs + 1] = fmt(fmt_label, (data.iX / 2) - 2, iY + 2.2, - S("Recipe is too big to be displayed (@1x@2)", width, rows)) + fs_esc(S("Recipe is too big to be displayed (@1x@2)", width, rows))) return concat(fs) end @@ -368,7 +369,7 @@ local function get_recipe_fs(data, iY) btn_size, item, item:match("%S*"), - label) + fs_esc(label)) local burntime = fuel_cache[item] @@ -402,7 +403,7 @@ local function get_recipe_fs(data, iY) iY + (sfinv_only and 2.2 or 1.7), 0.5, 0.5, - tooltip) + fs_esc(tooltip)) end local arrow_X = rightest + (s_btn_size or 1.1) @@ -432,7 +433,7 @@ local function get_recipe_fs(data, iY) 1.1, 1.1, recipe.output, - output_name) + fs_esc(output_name)) if burntime then fs[#fs + 1] = get_tooltip(output_name, nil, nil, burntime) @@ -459,9 +460,9 @@ local function get_recipe_fs(data, iY) 2.2, 1, "alternate", - data.show_usages and S("Usage") or S("Recipe"), + data.show_usages and fs_esc(S("Usage")) or fs_esc(S("Recipe")), data.rnum, - S("of"), + fs_esc(S("of")), #data.recipes) return concat(fs) @@ -483,8 +484,8 @@ local function make_formspec(name) background[1,1;1,1;craftguide_bg.png;true] ]] - fs[#fs + 1] = "tooltip[size_inc;" .. S("Increase window size") .. "]" - fs[#fs + 1] = "tooltip[size_dec;" .. S("Decrease window size") .. "]" + fs[#fs + 1] = "tooltip[size_inc;" .. fs_esc(S("Increase window size")) .. "]" + fs[#fs + 1] = "tooltip[size_dec;" .. fs_esc(S("Decrease window size")) .. "]" fs[#fs + 1] = "image_button[" .. (data.iX * 0.47) .. ",0.12;0.8,0.8;craftguide_zoomin_icon.png;size_inc;]" @@ -498,10 +499,10 @@ local function make_formspec(name) field_close_on_enter[filter;false] ]] - fs[#fs + 1] = "tooltip[search;" .. S("Search") .. "]" - fs[#fs + 1] = "tooltip[clear;" .. S("Reset") .. "]" - fs[#fs + 1] = "tooltip[prev;" .. S("Previous page") .. "]" - fs[#fs + 1] = "tooltip[next;" .. S("Next page") .. "]" + fs[#fs + 1] = "tooltip[search;" .. fs_esc(S("Search")) .. "]" + fs[#fs + 1] = "tooltip[clear;" .. fs_esc(S("Reset")) .. "]" + fs[#fs + 1] = "tooltip[prev;" .. fs_esc(S("Previous page")) .. "]" + fs[#fs + 1] = "tooltip[next;" .. fs_esc(S("Next page")) .. "]" fs[#fs + 1] = "image_button[" .. (data.iX - (sfinv_only and 2.6 or 3.1)) .. ",0.12;0.8,0.8;craftguide_prev_icon.png;prev;]" @@ -515,13 +516,13 @@ local function make_formspec(name) (sfinv_only and 0.7 or 1.2) - (data.iX >= 11 and 0.08 or 0)) .. ",0.12;0.8,0.8;craftguide_next_icon.png;next;]" - fs[#fs + 1] = "field[0.3,0.32;2.5,1;filter;;" .. mt.formspec_escape(data.filter) .. "]" + fs[#fs + 1] = "field[0.3,0.32;2.5,1;filter;;" .. fs_esc(data.filter) .. "]" if #data.items == 0 then fs[#fs + 1] = fmt(fmt_label, (data.iX / 2) - 1, 2, - S("No item to show")) + fs_esc(S("No item to show"))) end local first_item = (data.pagenum - 1) * ipp @@ -739,7 +740,7 @@ end) if sfinv_only then sfinv.register_page("craftguide:craftguide", { - title = "Craft Guide", + title = S("Craft Guide"), get = function(self, player, context) local name = player:get_player_name()