From 19fb5e2691f6f1c54c2a850fe0682109fa88bbe2 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Sun, 29 Sep 2019 16:58:33 +0200 Subject: [PATCH] Check compat for background[] --- API.md | 2 +- init.lua | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/API.md b/API.md index f19f475..519cc03 100644 --- a/API.md +++ b/API.md @@ -174,7 +174,7 @@ craftguide.group_stereotypes.radioactive = "mod:item" You can set a custom background theme by overriding this variable: ```Lua -craftguide.background = ":" +craftguide.background = "#" ``` diff --git a/init.lua b/init.lua index 43b31a8..5ff5f30 100644 --- a/init.lua +++ b/init.lua @@ -55,9 +55,11 @@ local WH_LIMIT = 8 local XOFFSET = sfinv_only and 3.83 or 4.66 local YOFFSET = sfinv_only and 6 or 6.6 -local DEV_CORE = sub(core.get_version().string, -3) == "dev" +local CORE_VERSION = core.get_version().string + CORE_VERSION = match(CORE_VERSION, "[^%-]*"):gsub("%.", "") + CORE_VERSION = tonumber(CORE_VERSION) -craftguide.background = "craftguide_bg_full.png:10" +craftguide.background = "craftguide_bg_full.png#10" local PNG = { bg = "craftguide_bg.png", @@ -708,17 +710,19 @@ local function make_formspec(name) local fs = {} if not sfinv_only then - local bg, middle = match(craftguide.background, "(.-):(%d+)") + local bg, middle = match(craftguide.background, "([%w_%.]*)([#%d]*)") bg = bg or "" - middle = middle or "10" + middle = tonumber(sub(middle, 2)) or 10 - fs[#fs + 1] = fmt([[ + fs[#fs + 1] = [[ size[9.5,8.4] no_prepend[] - bgcolor[#00000000;false] - background[1,1;1,1;%s;true%s] - ]], - bg, DEV_CORE and ";" .. middle or "") + bgcolor[#0000] + ]] + + fs[#fs + 1] = CORE_VERSION >= 510 and + fmt("background9[1,1;1,1;%s;true;%d]", bg, middle) or + fmt("background[1,1;1,1;%s;true]", bg) end fs[#fs + 1] = fmt([[