Compare commits

...

8 Commits
1.11.4 ... 1.12

4 changed files with 90 additions and 100 deletions

121
init.lua
View File

@ -12,6 +12,11 @@ local toolrepair
local progressive_mode = core.settings:get_bool("craftguide_progressive_mode") local progressive_mode = core.settings:get_bool("craftguide_progressive_mode")
local sfinv_only = core.settings:get_bool("craftguide_sfinv_only") and rawget(_G, "sfinv") local sfinv_only = core.settings:get_bool("craftguide_sfinv_only") and rawget(_G, "sfinv")
local enable_cache_progress_bar = core.settings:get_bool("craftguide_enable_cache_progress_bar")
if enable_cache_progress_bar == nil then
enable_cache_progress_bar = true
end
local http = core.request_http_api() local http = core.request_http_api()
@ -47,9 +52,9 @@ local ES = function(...)
return ESC(S(...)) return ESC(S(...))
end end
local maxn, sort, concat, copy, insert, remove = local maxn, sort, concat, copy, insert, remove, unpack =
table.maxn, table.sort, table.concat, table.copy, table.maxn, table.sort, table.concat, table.copy,
table.insert, table.remove table.insert, table.remove, unpack
local fmt, find, gmatch, match, sub, split, upper, lower = local fmt, find, gmatch, match, sub, split, upper, lower =
string.format, string.find, string.gmatch, string.match, string.format, string.find, string.gmatch, string.match,
@ -59,6 +64,8 @@ local min, max, floor, ceil = math.min, math.max, math.floor, math.ceil
local pairs, next, type, tostring, io = pairs, next, type, tostring, io local pairs, next, type, tostring, io = pairs, next, type, tostring, io
local vec_add, vec_mul = vector.add, vector.multiply local vec_add, vec_mul = vector.add, vector.multiply
local FORMSPEC_MINIMAL_VERSION = 3
local ROWS = 9 local ROWS = 9
local LINES = sfinv_only and 5 or 9 local LINES = sfinv_only and 5 or 9
local IPP = ROWS * LINES local IPP = ROWS * LINES
@ -79,6 +86,7 @@ local PNG = {
fire_anim = "craftguide_fire_anim.png", fire_anim = "craftguide_fire_anim.png",
book = "craftguide_book.png", book = "craftguide_book.png",
sign = "craftguide_sign.png", sign = "craftguide_sign.png",
nothing = "craftguide_no.png",
selected = "craftguide_selected.png", selected = "craftguide_selected.png",
furnace_anim = "craftguide_furnace_anim.png", furnace_anim = "craftguide_furnace_anim.png",
@ -96,11 +104,16 @@ local FMT = {
tooltip = "tooltip[%f,%f;%f,%f;%s]", tooltip = "tooltip[%f,%f;%f,%f;%s]",
item_image = "item_image[%f,%f;%f,%f;%s]", item_image = "item_image[%f,%f;%f,%f;%s]",
image_button = "image_button[%f,%f;%f,%f;%s;%s;%s]", image_button = "image_button[%f,%f;%f,%f;%s;%s;%s]",
animated_image = "animated_image[%f,%f;%f,%f;%s:%u,%u]", animated_image = "animated_image[%f,%f;%f,%f;;%s;%u;%u]",
item_image_button = "item_image_button[%f,%f;%f,%f;%s;%s;%s]", item_image_button = "item_image_button[%f,%f;%f,%f;%s;%s;%s]",
arrow = "image_button[%f,%f;0.8,0.8;%s;%s;;;false;%s]", arrow = "image_button[%f,%f;0.8,0.8;%s;%s;;;false;%s]",
} }
local function get_fs_version(name)
local info = get_player_info(name)
return info and info.formspec_version or 1
end
local function mul_elem(elem, n) local function mul_elem(elem, n)
local fstr, elems = "", {} local fstr, elems = "", {}
@ -725,11 +738,9 @@ local function get_output_fs(data, fs, L)
local pos_x = L.rightest + L.btn_size + 0.1 local pos_x = L.rightest + L.btn_size + 0.1
local pos_y = YOFFSET + (sfinv_only and 0.25 or -0.45) local pos_y = YOFFSET + (sfinv_only and 0.25 or -0.45)
if data.fs_version >= 3 and sub(icon, 1, 18) == "craftguide_furnace" then if sub(icon, 1, 18) == "craftguide_furnace" then
fs[#fs + 1] = fmt(FMT.animated_image, fs[#fs + 1] = fmt(FMT.animated_image,
pos_x, pos_y + L.spacing, 0.5, 0.5, PNG.furnace_anim, 8, 180) pos_x, pos_y + L.spacing, 0.5, 0.5, PNG.furnace_anim, 8, 180)
else
fs[#fs + 1] = fmt(FMT.image, pos_x, pos_y + L.spacing, 0.5, 0.5, icon)
end end
local tooltip = custom_recipe and custom_recipe.description or local tooltip = custom_recipe and custom_recipe.description or
@ -746,25 +757,17 @@ local function get_output_fs(data, fs, L)
0.9, 0.7, PNG.arrow) 0.9, 0.7, PNG.arrow)
if L.recipe.type == "fuel" then if L.recipe.type == "fuel" then
if data.fs_version >= 3 then
fs[#fs + 1] = fmt(FMT.animated_image, fs[#fs + 1] = fmt(FMT.animated_image,
output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing, output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
1.1, 1.1, PNG.fire_anim, 8, 180) 1.1, 1.1, PNG.fire_anim, 8, 180)
else
fs[#fs + 1] = fmt(FMT.image,
output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
1.1, 1.1, PNG.fire)
end
else else
local item = L.recipe.output local item = L.recipe.output
item = clean_name(item) item = clean_name(item)
local name = match(item, "%S*") local name = match(item, "%S*")
if data.fs_version >= 3 then
fs[#fs + 1] = fmt(FMT.image, fs[#fs + 1] = fmt(FMT.image,
output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing, output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
1.1, 1.1, PNG.selected) 1.1, 1.1, PNG.selected)
end
local _name = sfinv_only and name or fmt("_%s", name) local _name = sfinv_only and name or fmt("_%s", name)
@ -788,15 +791,9 @@ local function get_output_fs(data, fs, L)
output_X + 1, YOFFSET + (sfinv_only and 0.7 or 0.1) + L.spacing, output_X + 1, YOFFSET + (sfinv_only and 0.7 or 0.1) + L.spacing,
0.6, 0.4, PNG.arrow) 0.6, 0.4, PNG.arrow)
if data.fs_version >= 3 then
fs[#fs + 1] = fmt(FMT.animated_image, fs[#fs + 1] = fmt(FMT.animated_image,
output_X + 1.6, YOFFSET + (sfinv_only and 0.55 or 0) + L.spacing, output_X + 1.6, YOFFSET + (sfinv_only and 0.55 or 0) + L.spacing,
0.6, 0.6, PNG.fire_anim, 8, 180) 0.6, 0.6, PNG.fire_anim, 8, 180)
else
fs[#fs + 1] = fmt(FMT.image,
output_X + 1.6, YOFFSET + (sfinv_only and 0.55 or 0) + L.spacing,
0.6, 0.6, PNG.fire)
end
end end
end end
end end
@ -880,7 +877,7 @@ local function get_grid_fs(data, fs, rcp, spacing)
end end
end end
if data.fs_version >= 3 and not large_recipe then if not large_recipe then
fs[#fs + 1] = fmt(FMT.image, fs[#fs + 1] = fmt(FMT.image,
X, Y + (sfinv_only and 0.7 or 0), btn_size, btn_size, PNG.selected) X, Y + (sfinv_only and 0.7 or 0), btn_size, btn_size, PNG.selected)
end end
@ -918,17 +915,16 @@ local function get_grid_fs(data, fs, rcp, spacing)
end end
local function get_panels(data, fs) local function get_panels(data, fs)
local start_y = data.fs_version >= 3 and (sfinv_only and 0.33 or 0) or 0.33 local start_y = sfinv_only and 0.33 or 0
local panels = { local panels = {
{dat = data.usages or {}, height = 3.5}, {dat = data.usages or {}, height = 3.5},
{dat = data.recipes or {}, height = 3.5}, {dat = data.recipes or {}, height = 3.5},
} }
if data.fs_version >= 3 and not sfinv_only then if not sfinv_only then
panels.favs = {dat = {}, height = 2.19} panels.favs = {height = 2.19}
else
elseif sfinv_only then
panels = data.show_usages and panels = data.show_usages and
{{dat = data.usages}} or {{dat = data.recipes}} {{dat = data.usages}} or {{dat = data.recipes}}
end end
@ -941,7 +937,7 @@ local function get_panels(data, fs)
fs[#fs + 1] = fmt("background9[8.1,%f;6.6,%f;%s;false;%d]", fs[#fs + 1] = fmt("background9[8.1,%f;6.6,%f;%s;false;%d]",
-0.2 + spacing, v.height, PNG.bg_full, 10) -0.2 + spacing, v.height, PNG.bg_full, 10)
if data.fs_version >= 3 and k == 2 then if k == 2 then
local fav = is_fav(data) local fav = is_fav(data)
local nfavs = #data.favs local nfavs = #data.favs
@ -961,7 +957,7 @@ local function get_panels(data, fs)
end end
end end
local rn = #v.dat local rn = v.dat and #v.dat or -1
local _rn = tostring(rn) local _rn = tostring(rn)
local xu = tostring(data.unum) .. _rn local xu = tostring(data.unum) .. _rn
local xr = tostring(data.rnum) .. _rn local xr = tostring(data.rnum) .. _rn
@ -969,10 +965,15 @@ local function get_panels(data, fs)
xr = max(-0.3, -((#xr - 3) * 0.05)) xr = max(-0.3, -((#xr - 3) * 0.05))
local is_recipe = sfinv_only and not data.show_usages or k == 2 local is_recipe = sfinv_only and not data.show_usages or k == 2
local lbl local lbl = ""
if not sfinv_only and rn == 0 then if not sfinv_only and rn == 0 then
lbl = clr("#f00", is_recipe and ES"No recipes" or ES"No usages") fs[#fs + 1] = fmt(FMT.image,
XOFFSET - 0.7, YOFFSET - 0.4 + spacing, 2, 2, PNG.nothing)
fs[#fs + 1] = fmt(FMT.tooltip,
XOFFSET - 0.7, YOFFSET - 0.4 + spacing, 2, 2,
is_recipe and ES"No recipes" or ES"No usages")
elseif (not sfinv_only and is_recipe) or elseif (not sfinv_only and is_recipe) or
(sfinv_only and not data.show_usages) then (sfinv_only and not data.show_usages) then
@ -998,25 +999,18 @@ local function get_panels(data, fs)
local x_arrow = XOFFSET + (sfinv_only and 1.7 or 1) local x_arrow = XOFFSET + (sfinv_only and 1.7 or 1)
local y_arrow = YOFFSET + (sfinv_only and 3.3 or 1.4 + spacing) local y_arrow = YOFFSET + (sfinv_only and 3.3 or 1.4 + spacing)
if data.fs_version >= 3 then
fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2), fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
x_arrow + (is_recipe and xr or xu), y_arrow, x_arrow + (is_recipe and xr or xu), y_arrow,
PNG.prev, prev_name, "", PNG.prev, prev_name, "",
x_arrow + 1.8, y_arrow, PNG.next, next_name, "") x_arrow + 1.8, y_arrow, PNG.next, next_name, "")
else
fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
x_arrow + (is_recipe and xr or xu),
y_arrow, PNG.prev, prev_name, PNG.prev_hover,
x_arrow + 1.8, y_arrow, PNG.next, next_name, PNG.next_hover)
end
end end
local rcp = is_recipe and v.dat[data.rnum] or v.dat[data.unum] local rcp = v.dat and (is_recipe and v.dat[data.rnum] or v.dat[data.unum])
if rcp then if rcp then
get_grid_fs(data, fs, rcp, spacing) get_grid_fs(data, fs, rcp, spacing)
end end
if k == "favs" and data.fs_version >= 3 and not sfinv_only then if k == "favs" and not sfinv_only then
fs[#fs + 1] = fmt(FMT.label, 8.3, spacing - 0.1, ES"Bookmarks") fs[#fs + 1] = fmt(FMT.label, 8.3, spacing - 0.1, ES"Bookmarks")
for i = 1, #data.favs do for i = 1, #data.favs do
@ -1059,7 +1053,6 @@ local function make_fs(data)
]], ]],
ESC(data.filter)) ESC(data.filter))
if data.fs_version >= 3 then
fs[#fs + 1] = fmt([[ fs[#fs + 1] = fmt([[
style_type[image_button;border=false] style_type[image_button;border=false]
style_type[item_image_button;border=false;bgimg_hovered=%s;bgimg_pressed=%s] style_type[item_image_button;border=false;bgimg_hovered=%s;bgimg_pressed=%s]
@ -1079,20 +1072,6 @@ local function make_fs(data)
sfinv_only and 3.3 or 3.25, -0.06, 0.85, 0.85, "", "clear", "", sfinv_only and 3.3 or 3.25, -0.06, 0.85, 0.85, "", "clear", "",
sfinv_only and 5.45 or (ROWS * 6.83) / 11, -0.06, 0.85, 0.85, "", "prev_page", "", sfinv_only and 5.45 or (ROWS * 6.83) / 11, -0.06, 0.85, 0.85, "", "prev_page", "",
sfinv_only and 7.2 or (ROWS * 8.75) / 11, -0.06, 0.85, 0.85, "", "next_page", "") sfinv_only and 7.2 or (ROWS * 8.75) / 11, -0.06, 0.85, 0.85, "", "next_page", "")
else
fs[#fs + 1] = fmt([[
image_button[%f,-0.06;0.85,0.85;%s;search;;;false;%s]
image_button[%f,-0.06;0.85,0.85;%s;clear;;;false;%s]
]],
sfinv_only and 2.6 or 2.54, PNG.search, PNG.search_hover,
sfinv_only and 3.3 or 3.25, PNG.clear, PNG.clear_hover)
fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
sfinv_only and 5.45 or (ROWS * 6.83) / 11, -0.05,
PNG.prev, "prev_page", PNG.prev_hover,
sfinv_only and 7.2 or (ROWS * 8.75) / 11, -0.05,
PNG.next, "next_page", PNG.next_hover)
end
data.pagemax = max(1, ceil(#data.items / IPP)) data.pagemax = max(1, ceil(#data.items / IPP))
@ -1121,7 +1100,7 @@ local function make_fs(data)
local X = i % ROWS local X = i % ROWS
local Y = (i % IPP - X) / ROWS + 1 local Y = (i % IPP - X) / ROWS + 1
if data.fs_version >= 3 and data.query_item == item then if data.query_item == item then
fs[#fs + 1] = fmt(FMT.image, fs[#fs + 1] = fmt(FMT.image,
X - (X * (sfinv_only and 0.12 or 0.14)) - 0.05, X - (X * (sfinv_only and 0.12 or 0.14)) - 0.05,
Y - (Y * 0.1) - 0.1, Y - (Y * 0.1) - 0.1,
@ -1473,17 +1452,19 @@ local function get_init_items()
last_str = str last_str = str
end end
local full_char, empty_char = "", "" local full_char, empty_char = "#", " "
for name, def in pairs(reg_items) do for name, def in pairs(reg_items) do
ic = ic + 1 ic = ic + 1
local percent, bar, len = (ic * 100) / it, "", 20 local percent, bar, len = (ic * 100) / it, "[", 20
for i = 1, len do for i = 1, len do
bar = bar .. (i <= percent / (100 / len) and full_char or empty_char) bar = bar .. (i <= percent / (100 / len) and full_char or empty_char)
end end
iop(fmt("[craftguide] Caching data %s %u%%\r", bar, percent)) if enable_cache_progress_bar then
iop(fmt("[craftguide] Caching data %s %u%%\r", bar .. "]", percent))
end
if show_item(def) then if show_item(def) then
if not fuel_cache[name] then if not fuel_cache[name] then
@ -1530,7 +1511,7 @@ local function init_data(name)
items = init_items, items = init_items,
items_raw = init_items, items_raw = init_items,
favs = {}, favs = {},
fs_version = get_player_info(name).formspec_version, fs_version = get_fs_version(name),
} }
end end
@ -1650,7 +1631,7 @@ if sfinv_only then
is_in_nav = function(self, player, context) is_in_nav = function(self, player, context)
local name = player:get_player_name() local name = player:get_player_name()
return get_player_info(name).formspec_version >= 2 return get_fs_version(name) >= FORMSPEC_MINIMAL_VERSION
end, end,
get = function(self, player, context) get = function(self, player, context)
@ -1686,9 +1667,18 @@ else
local name = user:get_player_name() local name = user:get_player_name()
local data = pdata[name] local data = pdata[name]
if data.fs_version == 1 then if data.fs_version < FORMSPEC_MINIMAL_VERSION then
return msg(name, "Your Minetest client is outdated. " .. local fs = fmt([[
size[6.6,1.3]
image[0,0;1,1;%s]
label[1,0;%s]
button_exit[2.8,0.8;1,1;;OK]
]],
PNG.nothing,
"Your Minetest client is outdated.\n" ..
"Get the latest version on minetest.net to use the Crafting Guide.") "Get the latest version on minetest.net to use the Crafting Guide.")
return show_formspec(name, "craftguide", fs)
end end
if next(recipe_filters) then if next(recipe_filters) then
@ -1719,7 +1709,7 @@ else
paramtype = "light", paramtype = "light",
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
sunlight_propagates = true, sunlight_propagates = true,
groups = {oddly_breakable_by_hand = 1, flammable = 3}, groups = {choppy = 1, attached_node = 1, oddly_breakable_by_hand = 1, flammable = 3},
node_box = { node_box = {
type = "wallmounted", type = "wallmounted",
wall_top = {-0.5, 0.4375, -0.5, 0.5, 0.5, 0.5}, wall_top = {-0.5, 0.4375, -0.5, 0.5, 0.5, 0.5},
@ -1996,10 +1986,7 @@ if progressive_mode then
} }
end) end)
local to_save = { local to_save = {"inv_items", "known_recipes"}
"inv_items",
"known_recipes",
}
local function save_meta(player) local function save_meta(player)
local meta = player:get_meta() local meta = player:get_meta()

View File

@ -3,3 +3,6 @@ craftguide_progressive_mode (Progressive Mode) bool false
# Integration in the default Minetest Game inventory. # Integration in the default Minetest Game inventory.
craftguide_sfinv_only (Sfinv only) bool false craftguide_sfinv_only (Sfinv only) bool false
# Display the cache-building progress bar in the server console.
craftguide_enable_cache_progress_bar (Enable console cache progress bar) bool true

BIN
textures/craftguide_no.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB