Compare commits

...

30 Commits
1.11 ... 1.12.1

Author SHA1 Message Date
4483f60cbc Fix icon not showing 2020-04-06 14:39:08 +02:00
79693f5c88 Update screenshot 2020-04-05 22:57:08 +02:00
b8c491a489 Remove useless textures 2020-04-05 22:53:27 +02:00
34231e01df Minetest 5.2+ required to use craftguide 2020-04-05 22:34:46 +02:00
2d6951cd0c Config value for disabling the cache load progress bar (#101) 2020-04-04 23:45:32 +02:00
df21df2bce Add icon when no recipes 2020-04-04 20:56:51 +02:00
5669bcdcb7 Add attached_node and choppy to craftguide:sign. (#100) 2020-04-04 19:22:27 +02:00
3ad05328bf New sign texture 2020-03-31 00:56:11 +02:00
7793019357 Adapt to new engine API 2020-03-19 17:33:53 +01:00
a97c0b96b3 Fix crash 2020-02-26 20:53:11 +01:00
63769603c4 Improve loading bar 2020-02-23 13:14:42 +01:00
189a3ff971 Rollback changes in srarch() 2020-02-16 14:48:43 +01:00
ca723202d6 Improve search look 2020-02-16 14:28:33 +01:00
a3e7031c04 Add animated images 2020-02-16 14:12:38 +01:00
5fc7e7c087 Style 2020-02-09 02:08:24 +01:00
aa61333ee3 Fix 2020-02-09 02:01:51 +01:00
e2cdfc28b0 Fix 2020-02-09 01:53:35 +01:00
aa9f7d6da3 Fix crash in sfinv mode 2020-02-09 01:46:15 +01:00
d87c64618c Don't show chances to drop for usages 2020-02-04 23:42:47 +01:00
3455257df5 Code cleaning 2020-02-03 01:01:00 +01:00
251a8b1bc9 Show fav icon only once 2020-02-03 00:31:14 +01:00
4dd40e06f5 New favorite icons 2020-02-02 21:39:56 +01:00
f9f9988868 Fix crash in progressive mode 2020-01-23 00:22:05 +01:00
dcb479dc44 Fix color in HUD 2020-01-22 00:06:47 +01:00
82bb95387e style 2020-01-12 23:30:57 +01:00
8626584dbd Check formspec_version instead of CORE_VERSION 2020-01-12 23:06:53 +01:00
f7ccd282be Drop MT <= 5.0 support and fix positioning 2020-01-12 22:30:12 +01:00
c9773f1ee9 Fix crash 2020-01-12 10:01:52 +01:00
001176b124 Add forgotte files 2020-01-07 01:48:17 +01:00
2c2dbc9efc Update License 2020-01-07 01:12:04 +01:00
10 changed files with 196 additions and 208 deletions

View File

@ -19,4 +19,4 @@ For developers, `craftguide` also has a [modding API](https://github.com/minetes
Love this mod? Donations are appreciated: https://www.paypal.me/jpg84240
![Preview2](https://i.imgur.com/w7KMS9G.png)
![Preview2](https://content.minetest.net/uploads/wAGr5rE3fI.png)

395
init.lua
View File

@ -1,12 +1,5 @@
craftguide = {}
local p = 0
local CORE_VERSION = core.get_version().string:match("[^%-]*"):gsub("%.", function(a)
p = p + 1
return p == 3 and a or ""
end)
CORE_VERSION = tonumber(CORE_VERSION)
-- Caches
local pdata = {}
local init_items = {}
@ -19,6 +12,11 @@ local toolrepair
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 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()
@ -44,26 +42,19 @@ local get_player_by_name = core.get_player_by_name
local slz, dslz = core.serialize, core.deserialize
local on_mods_loaded = core.register_on_mods_loaded
local on_leaveplayer = core.register_on_leaveplayer
local get_player_info = core.get_player_information
local on_receive_fields = core.register_on_player_receive_fields
local ESC = core.formspec_escape
local S = CORE_VERSION >= 500 and core.get_translator("craftguide") or
function(...)
local args, i = {...}, 1
return args[1]:gsub("@%d+", function()
i = i + 1
return args[i]
end)
end
local S = core.get_translator("craftguide")
local ES = function(...)
return ESC(S(...))
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.insert, table.remove
table.insert, table.remove, unpack
local fmt, find, gmatch, match, sub, split, upper, lower =
string.format, string.find, string.gmatch, string.match,
@ -73,26 +64,31 @@ 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 vec_add, vec_mul = vector.add, vector.multiply
local FORMSPEC_MINIMAL_VERSION = 3
local ROWS = 9
local LINES = sfinv_only and 5 or 9
local IPP = ROWS * LINES
local WH_LIMIT = 8
local XOFFSET = sfinv_only and 3.83 or 11.2
local YOFFSET = sfinv_only and 6 or 1
local YOFFSET = sfinv_only and 4.9 or 1
local PNG = {
bg = "craftguide_bg.png",
bg_full = "craftguide_bg_full.png",
search = "craftguide_search_icon.png",
clear = "craftguide_clear_icon.png",
prev = "craftguide_next_icon.png^\\[transformFX",
next = "craftguide_next_icon.png",
arrow = "craftguide_arrow.png",
fire = "craftguide_fire.png",
book = "craftguide_book.png",
sign = "craftguide_sign.png",
selected = "craftguide_selected.png",
bg = "craftguide_bg.png",
bg_full = "craftguide_bg_full.png",
search = "craftguide_search_icon.png",
clear = "craftguide_clear_icon.png",
prev = "craftguide_next_icon.png^\\[transformFX",
next = "craftguide_next_icon.png",
arrow = "craftguide_arrow.png",
fire = "craftguide_fire.png",
fire_anim = "craftguide_fire_anim.png",
book = "craftguide_book.png",
sign = "craftguide_sign.png",
nothing = "craftguide_no.png",
selected = "craftguide_selected.png",
furnace_anim = "craftguide_furnace_anim.png",
search_hover = "craftguide_search_icon_hover.png",
clear_hover = "craftguide_clear_icon_hover.png",
@ -108,10 +104,16 @@ local FMT = {
tooltip = "tooltip[%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]",
animated_image = "animated_image[%f,%f;%f,%f;;%s;%u;%u]",
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]",
}
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 fstr, elems = "", {}
@ -590,10 +592,15 @@ local function get_recipes(item, data, player)
end
local no_recipes = not recipes or #recipes == 0
if no_recipes and not usages then
return
elseif sfinv_only and usages and no_recipes then
data.show_usages = true
elseif sfinv_only then
if usages and no_recipes then
data.show_usages = true
elseif recipes and not usages then
data.show_usages = nil
end
end
if not sfinv_only or (sfinv_only and data.show_usages) then
@ -653,6 +660,10 @@ local function is_fav(data)
end
local function get_desc(name)
if sub(name, 1, 1) == "_" then
name = sub(name, 2)
end
local def = reg_items[name]
return def and (match(def.description, "%)([%w%s]*)") or def.description) or
@ -713,7 +724,7 @@ local function get_tooltip(name, info)
return fmt("tooltip[%s;%s]", name, ESC(tooltip))
end
local function get_output_fs(fs, L)
local function get_output_fs(data, fs, L)
local custom_recipe = craft_types[L.recipe.type]
if custom_recipe or L.shapeless or L.recipe.type == "cooking" then
@ -727,14 +738,17 @@ local function get_output_fs(fs, L)
local pos_x = L.rightest + L.btn_size + 0.1
local pos_y = YOFFSET + (sfinv_only and 0.25 or -0.45)
fs[#fs + 1] = fmt(FMT.image, pos_x, pos_y + L.spacing, 0.5, 0.5, icon)
if sub(icon, 1, 18) == "craftguide_furnace" then
fs[#fs + 1] = fmt(FMT.animated_image,
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
local tooltip = custom_recipe and custom_recipe.description or
L.shapeless and S"Shapeless" or S"Cooking"
if CORE_VERSION >= 500 then
fs[#fs + 1] = fmt(FMT.tooltip, pos_x, pos_y + L.spacing, 0.5, 0.5, ESC(tooltip))
end
fs[#fs + 1] = fmt(FMT.tooltip, pos_x, pos_y + L.spacing, 0.5, 0.5, ESC(tooltip))
end
local arrow_X = L.rightest + (L._btn_size or 1.1)
@ -745,23 +759,23 @@ local function get_output_fs(fs, L)
0.9, 0.7, PNG.arrow)
if L.recipe.type == "fuel" then
fs[#fs + 1] = fmt(FMT.image,
fs[#fs + 1] = fmt(FMT.animated_image,
output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
1.1, 1.1, PNG.fire)
1.1, 1.1, PNG.fire_anim, 8, 180)
else
local item = L.recipe.output
item = clean_name(item)
local name = match(item, "%S*")
if CORE_VERSION >= 510 then
fs[#fs + 1] = fmt(FMT.image,
output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
1.1, 1.1, PNG.selected)
end
fs[#fs + 1] = fmt(FMT.item_image_button,
fs[#fs + 1] = fmt(FMT.image,
output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
1.1, 1.1, item, name, "")
1.1, 1.1, PNG.selected)
local _name = sfinv_only and name or fmt("_%s", name)
fs[#fs + 1] = fmt("item_image_button[%f,%f;%f,%f;%s;%s;%s]",
output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
1.1, 1.1, item, _name, "")
local infos = {
unknown = not reg_items[name] or nil,
@ -771,7 +785,7 @@ local function get_output_fs(fs, L)
}
if next(infos) then
fs[#fs + 1] = get_tooltip(name, infos)
fs[#fs + 1] = get_tooltip(_name, infos)
end
if infos.burntime then
@ -779,14 +793,14 @@ local function get_output_fs(fs, L)
output_X + 1, YOFFSET + (sfinv_only and 0.7 or 0.1) + L.spacing,
0.6, 0.4, PNG.arrow)
fs[#fs + 1] = fmt(FMT.image,
fs[#fs + 1] = fmt(FMT.animated_image,
output_X + 1.6, YOFFSET + (sfinv_only and 0.55 or 0) + L.spacing,
0.6, 0.6, PNG.fire)
0.6, 0.6, PNG.fire_anim, 8, 180)
end
end
end
local function get_grid_fs(fs, rcp, spacing)
local function get_grid_fs(data, fs, rcp, spacing)
local width = rcp.width or 1
local replacements = rcp.replacements
local rarity = rcp.rarity
@ -865,7 +879,7 @@ local function get_grid_fs(fs, rcp, spacing)
end
end
if CORE_VERSION >= 510 and not large_recipe then
if not large_recipe then
fs[#fs + 1] = fmt(FMT.image,
X, Y + (sfinv_only and 0.7 or 0), btn_size, btn_size, PNG.selected)
end
@ -891,7 +905,7 @@ local function get_grid_fs(fs, rcp, spacing)
fs[#fs + 1] = "style_type[item_image_button;border=false]"
end
get_output_fs(fs, {
get_output_fs(data, fs, {
recipe = rcp,
shapeless = shapeless,
rightest = rightest,
@ -903,17 +917,17 @@ local function get_grid_fs(fs, rcp, spacing)
end
local function get_panels(data, fs)
local start_y = CORE_VERSION >= 520 and 0 or 0.33
local start_y = sfinv_only and 0.33 or 0
local panels = {
{dat = data.usages or {}, height = 3.5},
{dat = data.recipes or {}, height = 3.5},
}
if CORE_VERSION >= 520 and not sfinv_only then
panels.favs = {dat = {}, height = 2.19}
elseif sfinv_only then
panels = data.show_usages and
{{dat = data.usages}} or {{dat = data.recipes}}
if not sfinv_only then
panels.favs = {height = 2.19}
else
panels = data.show_usages and {{dat = data.usages}} or {{dat = data.recipes}}
end
for k, v in pairs(panels) do
@ -921,13 +935,10 @@ local function get_panels(data, fs)
local spacing = (start_y - 1) * 3.6
if not sfinv_only then
fs[#fs + 1] = CORE_VERSION >= 510 and
fmt("background9[8.1,%f;6.6,%f;%s;false;%d]",
-0.2 + spacing, v.height, PNG.bg_full, 10) or
fmt("background[8.1,%f;6.6,%f;%s;false]",
-0.2 + spacing, v.height, PNG.bg_full)
fs[#fs + 1] = fmt("background9[8.1,%f;6.6,%f;%s;false;%d]",
-0.2 + spacing, v.height, PNG.bg_full, 10)
if k ~= "favs" then
if k == 2 then
local fav = is_fav(data)
local nfavs = #data.favs
@ -947,18 +958,23 @@ local function get_panels(data, fs)
end
end
local rn = #v.dat
local rn = v.dat and #v.dat or -1
local _rn = tostring(rn)
local xu = tostring(data.unum) .. _rn
local xr = tostring(data.rnum) .. _rn
xu = max(-0.3, -((#xu - 3) * 0.05))
xr = max(-0.3, -((#xr - 3) * 0.05))
local is_recipe = k == 2
local lbl
local is_recipe = sfinv_only and not data.show_usages or k == 2
local lbl = ""
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
(sfinv_only and not data.show_usages) then
@ -975,34 +991,27 @@ local function get_panels(data, fs)
fs[#fs + 1] = fmt(FMT.label,
XOFFSET + (sfinv_only and 2.3 or 1.6) + (is_recipe and xr or xu),
YOFFSET + (sfinv_only and 2.3 or 1.5 + spacing), lbl)
YOFFSET + (sfinv_only and 3.4 or 1.5 + spacing), lbl)
if rn > 1 then
local btn_suffix = is_recipe and "recipe" or "usage"
local prev_name = fmt("prev_%s", btn_suffix)
local next_name = fmt("next_%s", btn_suffix)
local x_arrow = XOFFSET + (sfinv_only and 1.7 or 1)
local y_arrow = YOFFSET + (sfinv_only and 2.2 or 1.4 + spacing)
local y_arrow = YOFFSET + (sfinv_only and 3.3 or 1.4 + spacing)
if CORE_VERSION >= 520 then
fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
x_arrow + (is_recipe and xr or xu), y_arrow,
PNG.prev, prev_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
fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
x_arrow + (is_recipe and xr or xu), y_arrow,
PNG.prev, prev_name, "",
x_arrow + 1.8, y_arrow, PNG.next, next_name, "")
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
get_grid_fs(fs, rcp, spacing)
get_grid_fs(data, fs, rcp, spacing)
end
if k == "favs" and CORE_VERSION >= 520 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")
for i = 1, #data.favs do
@ -1022,64 +1031,48 @@ local function get_panels(data, fs)
end
end
local function make_formspec(name)
local data = pdata[name]
local function make_fs(data)
local fs = {}
fs[#fs + 1] = fmt([[
size[%f,%f]
no_prepend[]
bgcolor[#0000]
]], ROWS + (data.query_item and 6.7 or 0) - 1.2, LINES - 0.3)
]],
ROWS + (data.query_item and 6.7 or 0) - 1.2, LINES - 0.3)
if not sfinv_only then
fs[#fs + 1] = CORE_VERSION >= 510 and
fmt("background9[-0.15,-0.2;%f,%f;%s;false;%d]",
ROWS - 0.9, LINES + 0.4, PNG.bg_full, 10) or
fmt("background[-0.15,-0.2;%f,%f;%s;false]",
ROWS - 0.9, LINES + 0.4, PNG.bg_full)
fs[#fs + 1] = fmt("background9[-0.15,-0.2;%f,%f;%s;false;%d]",
ROWS - 0.9, LINES + 0.4, PNG.bg_full, 10)
end
fs[#fs + 1] = fmt([[
field[0.25,0.2;%f,1;filter;;%s]
style[filter;border=false]
field[0.4,0.2;2.5,1;filter;;%s]
field_close_on_enter[filter;false]
box[0,0;2.4,0.6;#ffffff25]
]],
sfinv_only and 2.76 or 2.72, ESC(data.filter))
ESC(data.filter))
if CORE_VERSION >= 520 then
fs[#fs + 1] = fmt([[
style_type[image_button;border=false]
style_type[item_image_button;border=false;bgimg_hovered=%s;bgimg_pressed=%s]
style[search;fgimg=%s;fgimg_hovered=%s]
style[clear;fgimg=%s;fgimg_hovered=%s]
style[prev_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
style[next_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
]],
PNG.selected, PNG.selected,
PNG.search, PNG.search_hover,
PNG.clear, PNG.clear_hover,
PNG.prev, PNG.prev_hover, PNG.prev_hover,
PNG.next, PNG.next_hover, PNG.next_hover)
fs[#fs + 1] = fmt([[
style_type[image_button;border=false]
style_type[item_image_button;border=false;bgimg_hovered=%s;bgimg_pressed=%s]
style[search;fgimg=%s;fgimg_hovered=%s]
style[clear;fgimg=%s;fgimg_hovered=%s]
style[prev_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
style[next_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
]],
PNG.selected, PNG.selected,
PNG.search, PNG.search_hover,
PNG.clear, PNG.clear_hover,
PNG.prev, PNG.prev_hover, PNG.prev_hover,
PNG.next, PNG.next_hover, PNG.next_hover)
fs[#fs + 1] = fmt(mul_elem(FMT.image_button, 4),
sfinv_only and 2.6 or 2.54, -0.06, 0.85, 0.85, "", "search", "",
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 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,
sfinv_only and 7.2 or (ROWS * 8.75) / 11, -0.05,
PNG.next, "next_page", PNG.next)
end
fs[#fs + 1] = fmt(mul_elem(FMT.image_button, 4),
sfinv_only and 2.6 or 2.54, -0.06, 0.85, 0.85, "", "search", "",
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 7.2 or (ROWS * 8.75) / 11, -0.06, 0.85, 0.85, "", "next_page", "")
data.pagemax = max(1, ceil(#data.items / IPP))
@ -1108,7 +1101,7 @@ local function make_formspec(name)
local X = i % ROWS
local Y = (i % IPP - X) / ROWS + 1
if CORE_VERSION >= 510 and data.query_item == item then
if data.query_item == item then
fs[#fs + 1] = fmt(FMT.image,
X - (X * (sfinv_only and 0.12 or 0.14)) - 0.05,
Y - (Y * 0.1) - 0.1,
@ -1129,10 +1122,11 @@ local function make_formspec(name)
end
local show_fs = function(player, name)
local data = pdata[name]
if sfinv_only then
sfinv.set_player_inventory_formspec(player)
else
show_formspec(name, "craftguide", make_formspec(name))
show_formspec(name, "craftguide", make_fs(data))
end
end
@ -1146,16 +1140,6 @@ craftguide.register_craft_type("digging_chance", {
icon = "default_tool_mesepick.png",
})
local function sfind(str, filter)
if filter == "" then
return 0
end
if find(str, filter, 1, true) then
return #str - #filter
end
end
local function search(data)
local filter = data.filter
@ -1177,28 +1161,30 @@ local function search(data)
end
end
local filtered_list, order, c = {}, {}, 0
local filtered_list, c = {}, 0
for i = 1, #data.items_raw do
local item = data.items_raw[i]
local def = reg_items[item]
local desc = (def and def.description) and lower(def.description) or ""
local search_in = fmt("%s %s", item, desc)
local to_add
if search_filter then
for filter_name, values in pairs(filters) do
local func = search_filters[filter_name]
to_add = func(item, values) and (search_filter == "" or
(sfind(item, search_filter) or sfind(desc, search_filter)))
if values then
local func = search_filters[filter_name]
to_add = func(item, values) and (search_filter == "" or
find(search_in, search_filter, 1, true))
end
end
else
to_add = sfind(item, filter) or sfind(desc, filter)
to_add = find(search_in, filter, 1, true)
end
if to_add then
c = c + 1
filtered_list[c] = item
order[item] = to_add
end
end
@ -1211,10 +1197,6 @@ local function search(data)
end
end
sort(filtered_list, function(a, b)
return order[a] < order[b]
end)
data.items = filtered_list
end
@ -1471,17 +1453,19 @@ local function get_init_items()
last_str = str
end
local full_char, empty_char = "", ""
local full_char, empty_char = "#", " "
for name, def in pairs(reg_items) do
ic = ic + 1
local percent, bar, len = (ic * 100) / it, "", 20
local percent, bar, len = (ic * 100) / it, "[", 20
for i = 1, len do
bar = bar .. (i <= percent / (100 / len) and full_char or empty_char)
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 not fuel_cache[name] then
@ -1522,15 +1506,13 @@ local function get_init_items()
end
local function init_data(name)
local items = CORE_VERSION >= 500 and init_items or
(#init_items == 0 and get_init_items() or init_items)
pdata[name] = {
filter = "",
pagenum = 1,
items = items,
items_raw = items,
favs = {},
filter = "",
pagenum = 1,
items = init_items,
items_raw = init_items,
favs = {},
fs_version = get_fs_version(name),
}
end
@ -1546,9 +1528,7 @@ local function reset_data(data)
data.items = data.items_raw
end
if CORE_VERSION >= 500 then
on_mods_loaded(get_init_items)
end
on_mods_loaded(get_init_items)
on_joinplayer(function(player)
local name = player:get_player_name()
@ -1558,22 +1538,25 @@ end)
local function fields(player, _f)
local name = player:get_player_name()
local data = pdata[name]
--print(dump(_f))
if _f.clear then
reset_data(data)
return true, show_fs(player, name)
elseif _f.prev_recipe or _f.next_recipe then
local num = data.rnum + (_f.prev_recipe and -1 or 1)
data.rnum = data.recipes[num] and num or (_f.prev_recipe and #data.recipes or 1)
return true, show_fs(player, name)
elseif _f.prev_usage or _f.next_usage then
local num = data.unum + (_f.prev_usage and -1 or 1)
data.unum = data.usages[num] and num or (_f.prev_usage and #data.usages or 1)
return true, show_fs(player, name)
elseif (_f.key_enter_field == "filter" or _f.search) and _f.filter ~= "" then
elseif _f.key_enter_field == "filter" or _f.search then
if _f.filter == "" then
reset_data(data)
return true, show_fs(player, name)
end
local str = lower(_f.filter)
if data.filter == str then return end
@ -1581,8 +1564,6 @@ local function fields(player, _f)
data.pagenum = 1
search(data)
return true, show_fs(player, name)
elseif _f.prev_page or _f.next_page then
if data.pagemax == 1 then return end
data.pagenum = data.pagenum - (_f.prev_page and 1 or -1)
@ -1593,8 +1574,6 @@ local function fields(player, _f)
data.pagenum = data.pagemax
end
return true, show_fs(player, name)
elseif _f.fav then
local fav, i = is_fav(data)
local total = #data.favs
@ -1604,8 +1583,6 @@ local function fields(player, _f)
elseif fav then
remove(data.favs, i)
end
return true, show_fs(player, name)
else
local item
for field in pairs(_f) do
@ -1619,6 +1596,8 @@ local function fields(player, _f)
return
elseif sub(item, -4) == "_inv" then
item = sub(item, 1, -5)
elseif sub(item, 1, 1) == "_" then
item = sub(item, 2)
end
item = reg_aliases[item] or item
@ -1629,28 +1608,37 @@ local function fields(player, _f)
else
data.show_usages = not data.show_usages
end
elseif item == data.query_item then
return
end
local recipes, usages = get_recipes(item, data, player)
if not recipes and not usages then return end
if not recipes and not usages then return end
if data.show_usages and not usages then return end
data.query_item = item
data.recipes = recipes
data.usages = usages
data.rnum = 1
data.unum = 1
return true, show_fs(player, name)
end
return true, show_fs(player, name)
end
if sfinv_only then
sfinv.register_page("craftguide:craftguide", {
title = S"Craft Guide",
is_in_nav = function(self, player, context)
local name = player:get_player_name()
return get_fs_version(name) >= FORMSPEC_MINIMAL_VERSION
end,
get = function(self, player, context)
local name = player:get_player_name()
local formspec = make_formspec(name)
local data = pdata[name]
local formspec = make_fs(data)
return sfinv.make_formspec(player, context, formspec)
end,
@ -1678,14 +1666,28 @@ else
local function on_use(user)
local name = user:get_player_name()
local data = pdata[name]
if data.fs_version < FORMSPEC_MINIMAL_VERSION then
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.")
return show_formspec(name, "craftguide", fs)
end
if next(recipe_filters) then
local data = pdata[name]
data.items_raw = get_filtered_items(user)
search(data)
end
show_formspec(name, "craftguide", make_formspec(name))
show_formspec(name, "craftguide", make_fs(data))
end
core.register_craftitem("craftguide:book", {
@ -1708,7 +1710,7 @@ else
paramtype = "light",
paramtype2 = "wallmounted",
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 = {
type = "wallmounted",
wall_top = {-0.5, 0.4375, -0.5, 0.5, 0.5, 0.5},
@ -1954,14 +1956,9 @@ if progressive_mode then
local name = player:get_player_name()
local data = pdata[name]
if CORE_VERSION >= 500 then
local meta = player:get_meta()
data.inv_items = dslz(meta:get_string("inv_items")) or {}
data.known_recipes = dslz(meta:get_string("known_recipes")) or 0
else
data.inv_items = dslz(player:get_attribute("inv_items")) or {}
data.known_recipes = dslz(player:get_attribute("known_recipes")) or 0
end
local meta = player:get_meta()
data.inv_items = dslz(meta:get_string("inv_items")) or {}
data.known_recipes = dslz(meta:get_string("known_recipes")) or 0
data.hud = {
bg = player:hud_add{
@ -1984,34 +1981,22 @@ if progressive_mode then
hud_elem_type = "text",
position = {x = 0.84, y = 1.04},
alignment = {x = 1, y = 1},
number = 0xfff,
number = 0xffffff,
text = "",
},
}
end)
local to_save = {
"inv_items",
"known_recipes",
}
local to_save = {"inv_items", "known_recipes"}
local function save_meta(player)
local meta
local meta = player:get_meta()
local name = player:get_player_name()
local data = pdata[name]
if CORE_VERSION >= 500 then
meta = player:get_meta()
end
for i = 1, #to_save do
local meta_name = to_save[i]
if CORE_VERSION >= 500 then
meta:set_string(meta_name, slz(data[meta_name]))
else
player:set_attribute(meta_name, slz(data[meta_name]))
end
meta:set_string(meta_name, slz(data[meta_name]))
end
end

View File

@ -3,7 +3,7 @@ License of source code
The MIT License (MIT)
Copyright (c) 2015-2019 Jean-Patrick Guerrero and contributors.
Copyright (c) 2015-2020 Jean-Patrick Guerrero and contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -2,4 +2,7 @@
craftguide_progressive_mode (Progressive Mode) bool false
# 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_fav.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

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