mirror of
https://github.com/minetest-mods/craftguide.git
synced 2025-06-29 22:50:41 +02:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
b07f0c0ecd | |||
92c5b1ab8e | |||
62d2b302ed | |||
8b4ef8a4b7 | |||
35b2ecfdc1 | |||
edbed14d9b | |||
4e4cb0625c | |||
77dbe040b8 | |||
d6bd17f6b3 | |||
b12502a7da | |||
e707db9ab9 | |||
270dc19ec1 | |||
c9c2bf03de | |||
ee1eac039e |
16
API.md
16
API.md
@ -5,6 +5,9 @@
|
|||||||
Custom recipes are nonconventional crafts outside the main crafting grid.
|
Custom recipes are nonconventional crafts outside the main crafting grid.
|
||||||
They can be registered in-game dynamically and have a size beyond 3x3 items.
|
They can be registered in-game dynamically and have a size beyond 3x3 items.
|
||||||
|
|
||||||
|
**Note:** the registration format differs from the default registration format in everything.
|
||||||
|
The width is automatically calculated depending where you place the commas. Look at the examples attentively.
|
||||||
|
|
||||||
#### Registering a custom crafting type (example)
|
#### Registering a custom crafting type (example)
|
||||||
|
|
||||||
```Lua
|
```Lua
|
||||||
@ -65,15 +68,6 @@ craftguide.register_craft({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
result = "default:mese 2",
|
|
||||||
items = {
|
|
||||||
"default:mese_crystal, default:mese_crystal",
|
|
||||||
"default:mese_crystal, default:mese_crystal",
|
|
||||||
"default:mese_crystal, default:mese_crystal",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
big = {
|
big = {
|
||||||
result = "default:mese 4",
|
result = "default:mese 4",
|
||||||
items = {
|
items = {
|
||||||
@ -86,11 +80,11 @@ craftguide.register_craft({
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
Recipes can be registered via an URL (HTTP support is required¹):
|
Recipes can be registered from a given URL containing a JSON file (HTTP support is required¹):
|
||||||
|
|
||||||
```Lua
|
```Lua
|
||||||
craftguide.register_craft({
|
craftguide.register_craft({
|
||||||
url = https://raw.githubusercontent.com/minetest-mods/craftguide/master/test.json
|
url = "https://raw.githubusercontent.com/minetest-mods/craftguide/master/test.json"
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
265
init.lua
265
init.lua
@ -66,7 +66,7 @@ local fmt, find, gmatch, match, sub, split, upper, lower =
|
|||||||
string.sub, string.split, string.upper, string.lower
|
string.sub, string.split, string.upper, string.lower
|
||||||
|
|
||||||
local min, max, floor, ceil = math.min, math.max, math.floor, math.ceil
|
local min, max, floor, ceil = math.min, math.max, math.floor, math.ceil
|
||||||
local pairs, next, type = pairs, next, type
|
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 ROWS = 9
|
local ROWS = 9
|
||||||
@ -75,7 +75,7 @@ local IPP = ROWS * LINES
|
|||||||
local WH_LIMIT = 8
|
local WH_LIMIT = 8
|
||||||
|
|
||||||
local XOFFSET = sfinv_only and 3.83 or 11.2
|
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 = {
|
local PNG = {
|
||||||
bg = "craftguide_bg.png",
|
bg = "craftguide_bg.png",
|
||||||
@ -89,6 +89,11 @@ local PNG = {
|
|||||||
book = "craftguide_book.png",
|
book = "craftguide_book.png",
|
||||||
sign = "craftguide_sign.png",
|
sign = "craftguide_sign.png",
|
||||||
selected = "craftguide_selected.png",
|
selected = "craftguide_selected.png",
|
||||||
|
|
||||||
|
search_hover = "craftguide_search_icon_hover.png",
|
||||||
|
clear_hover = "craftguide_clear_icon_hover.png",
|
||||||
|
prev_hover = "craftguide_next_icon_hover.png^\\[transformFX",
|
||||||
|
next_hover = "craftguide_next_icon_hover.png",
|
||||||
}
|
}
|
||||||
|
|
||||||
local FMT = {
|
local FMT = {
|
||||||
@ -100,9 +105,20 @@ local FMT = {
|
|||||||
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]",
|
||||||
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^\\[colorize:yellow:255]",
|
arrow = "image_button[%f,%f;0.8,0.8;%s;%s;;;false;%s]",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local function mul_elem(elem, n)
|
||||||
|
local fstr, elems = "", {}
|
||||||
|
|
||||||
|
for i = 1, n do
|
||||||
|
fstr = fstr .. "%s"
|
||||||
|
elems[i] = elem
|
||||||
|
end
|
||||||
|
|
||||||
|
return fmt(fstr, unpack(elems))
|
||||||
|
end
|
||||||
|
|
||||||
craftguide.group_stereotypes = {
|
craftguide.group_stereotypes = {
|
||||||
dye = "dye:white",
|
dye = "dye:white",
|
||||||
wool = "wool:white",
|
wool = "wool:white",
|
||||||
@ -121,7 +137,6 @@ local function msg(name, str)
|
|||||||
return chat_send(name, fmt("[craftguide] %s", clr("#FFFF00", str)))
|
return chat_send(name, fmt("[craftguide] %s", clr("#FFFF00", str)))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function is_str(x)
|
local function is_str(x)
|
||||||
return type(x) == "string"
|
return type(x) == "string"
|
||||||
end
|
end
|
||||||
@ -142,6 +157,14 @@ local function is_group(item)
|
|||||||
return sub(item, 1, 6) == "group:"
|
return sub(item, 1, 6) == "group:"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function clean_item(item)
|
||||||
|
if sub(item, 1, 1) == ":" then
|
||||||
|
item = sub(item, 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
return item
|
||||||
|
end
|
||||||
|
|
||||||
local function array_diff(t1, t2)
|
local function array_diff(t1, t2)
|
||||||
local hash = {}
|
local hash = {}
|
||||||
|
|
||||||
@ -177,8 +200,8 @@ local function table_eq(T1, T2)
|
|||||||
return t1 == t2
|
return t1 == t2
|
||||||
end
|
end
|
||||||
|
|
||||||
if avoid_loops[t1] then return
|
if avoid_loops[t1] then
|
||||||
avoid_loops[t1] == t2
|
return avoid_loops[t1] == t2
|
||||||
end
|
end
|
||||||
|
|
||||||
avoid_loops[t1] = t2
|
avoid_loops[t1] = t2
|
||||||
@ -593,11 +616,15 @@ local function groups_to_items(groups, get_all)
|
|||||||
local names = {}
|
local names = {}
|
||||||
for name, def in pairs(reg_items) do
|
for name, def in pairs(reg_items) do
|
||||||
if item_has_groups(def.groups, groups) then
|
if item_has_groups(def.groups, groups) then
|
||||||
|
if get_all then
|
||||||
names[#names + 1] = name
|
names[#names + 1] = name
|
||||||
|
else
|
||||||
|
return name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return names
|
return get_all and names or ""
|
||||||
end
|
end
|
||||||
|
|
||||||
local function repairable(tool)
|
local function repairable(tool)
|
||||||
@ -613,7 +640,7 @@ local function get_desc(name)
|
|||||||
S("Unknown Item (@1)", name))
|
S("Unknown Item (@1)", name))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_tooltip(item, info)
|
local function get_tooltip(name, info)
|
||||||
local tooltip
|
local tooltip
|
||||||
|
|
||||||
if info.groups then
|
if info.groups then
|
||||||
@ -626,12 +653,10 @@ local function get_tooltip(item, info)
|
|||||||
|
|
||||||
groupstr = concat(groupstr, ", ")
|
groupstr = concat(groupstr, ", ")
|
||||||
tooltip = S("Any item belonging to the group(s): @1", groupstr)
|
tooltip = S("Any item belonging to the group(s): @1", groupstr)
|
||||||
|
else
|
||||||
return fmt("tooltip[%s;%s]", item, ESC(tooltip))
|
tooltip = get_desc(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
tooltip = get_desc(item)
|
|
||||||
|
|
||||||
local function add(str)
|
local function add(str)
|
||||||
return fmt("%s\n%s", tooltip, str)
|
return fmt("%s\n%s", tooltip, str)
|
||||||
end
|
end
|
||||||
@ -665,7 +690,7 @@ local function get_tooltip(item, info)
|
|||||||
tooltip = add(S("@1 of chance to drop", clr("yellow", chance .. "%")))
|
tooltip = add(S("@1 of chance to drop", clr("yellow", chance .. "%")))
|
||||||
end
|
end
|
||||||
|
|
||||||
return fmt("tooltip[%s;%s]", item, ESC(tooltip))
|
return fmt("tooltip[%s;%s]", name, ESC(tooltip))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_output_fs(fs, L)
|
local function get_output_fs(fs, L)
|
||||||
@ -705,11 +730,12 @@ local function get_output_fs(fs, L)
|
|||||||
1.1, 1.1, PNG.fire)
|
1.1, 1.1, PNG.fire)
|
||||||
else
|
else
|
||||||
local item = L.recipe.output
|
local item = L.recipe.output
|
||||||
|
item = clean_item(item)
|
||||||
local name = match(item, "%S*")
|
local name = match(item, "%S*")
|
||||||
|
|
||||||
fs[#fs + 1] = fmt(FMT.item_image_button,
|
fs[#fs + 1] = fmt(FMT.item_image_button,
|
||||||
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, item, ESC(name), "")
|
1.1, 1.1, item, name, "")
|
||||||
|
|
||||||
if CORE_VERSION >= 510 then
|
if CORE_VERSION >= 510 then
|
||||||
fs[#fs + 1] = fmt(FMT.image,
|
fs[#fs + 1] = fmt(FMT.image,
|
||||||
@ -718,6 +744,7 @@ local function get_output_fs(fs, L)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local infos = {
|
local infos = {
|
||||||
|
unknown = not reg_items[name] or nil,
|
||||||
burntime = fuel_cache[name],
|
burntime = fuel_cache[name],
|
||||||
repair = repairable(name),
|
repair = repairable(name),
|
||||||
rarity = L.rarity,
|
rarity = L.rarity,
|
||||||
@ -740,7 +767,6 @@ local function get_output_fs(fs, L)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_grid_fs(fs, rcp, spacing)
|
local function get_grid_fs(fs, rcp, spacing)
|
||||||
if not rcp then return end
|
|
||||||
local width = rcp.width or 1
|
local width = rcp.width or 1
|
||||||
local replacements = rcp.replacements
|
local replacements = rcp.replacements
|
||||||
local rarity = rcp.rarity
|
local rarity = rcp.rarity
|
||||||
@ -774,6 +800,9 @@ local function get_grid_fs(fs, rcp, spacing)
|
|||||||
|
|
||||||
for i = 1, width * rows do
|
for i = 1, width * rows do
|
||||||
local item = rcp.items[i] or ""
|
local item = rcp.items[i] or ""
|
||||||
|
item = clean_item(item)
|
||||||
|
local name = match(item, "%S*")
|
||||||
|
|
||||||
local X = ceil((i - 1) % width - width) + XOFFSET
|
local X = ceil((i - 1) % width - width) + XOFFSET
|
||||||
local Y = ceil(i / width) + YOFFSET - min(2, rows) + spacing
|
local Y = ceil(i / width) + YOFFSET - min(2, rows) + spacing
|
||||||
|
|
||||||
@ -798,10 +827,9 @@ local function get_grid_fs(fs, rcp, spacing)
|
|||||||
|
|
||||||
local groups
|
local groups
|
||||||
|
|
||||||
if is_group(item) then
|
if is_group(name) then
|
||||||
groups = extract_groups(item)
|
groups = extract_groups(name)
|
||||||
local items = groups_to_items(groups)
|
item = groups_to_items(groups)
|
||||||
item = items[1] or items
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local label = groups and "\nG" or ""
|
local label = groups and "\nG" or ""
|
||||||
@ -810,8 +838,8 @@ local function get_grid_fs(fs, rcp, spacing)
|
|||||||
if replacements then
|
if replacements then
|
||||||
for j = 1, #replacements do
|
for j = 1, #replacements do
|
||||||
local replacement = replacements[j]
|
local replacement = replacements[j]
|
||||||
if replacement[1] == item then
|
if replacement[1] == name then
|
||||||
label = "\nR"
|
label = (label ~= "" and "\n" or "") .. label .. "\nR"
|
||||||
replace = replacement[2]
|
replace = replacement[2]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -819,12 +847,12 @@ local function get_grid_fs(fs, rcp, spacing)
|
|||||||
|
|
||||||
fs[#fs + 1] = fmt(FMT.item_image_button,
|
fs[#fs + 1] = fmt(FMT.item_image_button,
|
||||||
X, Y + (sfinv_only and 0.7 or 0),
|
X, Y + (sfinv_only and 0.7 or 0),
|
||||||
btn_size, btn_size, item, match(item, "%S*"), ESC(label))
|
btn_size, btn_size, item, item, ESC(label))
|
||||||
|
|
||||||
local infos = {
|
local infos = {
|
||||||
unknown = reg_items[item] and nil,
|
unknown = not reg_items[name] or nil,
|
||||||
groups = groups,
|
groups = groups,
|
||||||
burntime = fuel_cache[item],
|
burntime = fuel_cache[name],
|
||||||
cooktime = cooktime,
|
cooktime = cooktime,
|
||||||
replace = replace,
|
replace = replace,
|
||||||
}
|
}
|
||||||
@ -876,46 +904,71 @@ local function get_panels(data, fs)
|
|||||||
-0.2 + spacing, PNG.bg_full)
|
-0.2 + spacing, PNG.bg_full)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local rn = #v
|
||||||
|
local _rn = tostring(rn)
|
||||||
|
local xof_u = tostring(data.unum) .. _rn
|
||||||
|
local xof_r = tostring(data.rnum) .. _rn
|
||||||
|
xof_u = max(-0.3, -((#xof_u - 3) * 0.15))
|
||||||
|
xof_r = max(-0.3, -((#xof_r - 3) * 0.15))
|
||||||
|
|
||||||
|
local is_recipe = k == "recipes"
|
||||||
local btn_lab
|
local btn_lab
|
||||||
|
|
||||||
if not sfinv_only and #v == 0 then
|
if not sfinv_only and rn == 0 then
|
||||||
btn_lab = clr("red", k == "recipes" and
|
btn_lab = clr("red", is_recipe and
|
||||||
ESC(S("No recipes")) or ESC(S("No usages")))
|
ESC(S("No recipes")) or ESC(S("No usages")))
|
||||||
|
|
||||||
elseif (not sfinv_only and k == "recipes") 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
|
||||||
btn_lab = ESC(S("Recipe @1 of @2", data.rnum, #v))
|
btn_lab = ESC(S("Recipe @1 of @2", data.rnum, rn))
|
||||||
|
|
||||||
elseif not sfinv_only or (sfinv_only and data.show_usages) then
|
elseif not sfinv_only or (sfinv_only and data.show_usages) then
|
||||||
btn_lab = ESC(S("Usage @1 of @2", data.unum, #v))
|
btn_lab = ESC(S("Usage @1 of @2", data.unum, rn))
|
||||||
|
|
||||||
elseif sfinv_only then
|
elseif sfinv_only then
|
||||||
btn_lab = data.show_usages and
|
btn_lab = data.show_usages and
|
||||||
ESC(S("Usage @1 of @2", data.unum, #v)) or
|
ESC(S("Usage @1 of @2", data.unum, rn)) or
|
||||||
ESC(S("Recipe @1 of @2", data.rnum, #v))
|
ESC(S("Recipe @1 of @2", data.rnum, rn))
|
||||||
end
|
end
|
||||||
|
|
||||||
fs[#fs + 1] = fmt(FMT.label,
|
fs[#fs + 1] = fmt(FMT.label,
|
||||||
XOFFSET + (sfinv_only and 2.3 or 1.6),
|
XOFFSET + (sfinv_only and 2.3 or 1.6) + (is_recipe and xof_r or xof_u),
|
||||||
YOFFSET + (sfinv_only and 2.2 or 1.5 + spacing),
|
YOFFSET + (sfinv_only and 3.35 or 1.5 + spacing),
|
||||||
btn_lab)
|
btn_lab)
|
||||||
|
|
||||||
if #v > 1 then
|
if rn > 1 then
|
||||||
local btn_suffix = k == "recipes" and "recipe" or "usage"
|
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 x_arrow = XOFFSET + (sfinv_only and 1.7 or 1)
|
||||||
local y_arrow = YOFFSET + (sfinv_only and 2.1 or 1.4 + spacing)
|
local y_arrow = YOFFSET + (sfinv_only and 3.25 or 1.4 + spacing)
|
||||||
|
|
||||||
fs[#fs + 1] = fmt(FMT.arrow .. FMT.arrow,
|
if CORE_VERSION >= 520 then
|
||||||
x_arrow, y_arrow, PNG.prev,
|
fs[#fs + 1] = fmt([[
|
||||||
fmt("prev_%s", btn_suffix), PNG.prev,
|
style[%s;border=false;bgimg=%s;bgimg_hovered=%s]
|
||||||
x_arrow + 1.8, y_arrow, PNG.next,
|
style[%s;border=false;bgimg=%s;bgimg_hovered=%s]
|
||||||
fmt("next_%s", btn_suffix), PNG.next)
|
]],
|
||||||
|
prev_name, PNG.prev, PNG.prev_hover,
|
||||||
|
next_name, PNG.next, PNG.next_hover)
|
||||||
|
|
||||||
|
fs[#fs + 1] = fmt(mul_elem(FMT.button, 2),
|
||||||
|
x_arrow + (is_recipe and xof_r or xof_u),
|
||||||
|
y_arrow, 0.8, 0.8, prev_name, "",
|
||||||
|
x_arrow + 1.8, y_arrow, 0.8, 0.8, next_name, "")
|
||||||
|
else
|
||||||
|
fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
|
||||||
|
x_arrow + (is_recipe and xof_r or xof_u),
|
||||||
|
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 = k == "recipes" and v[data.rnum] or v[data.unum]
|
local rcp = is_recipe and v[data.rnum] or v[data.unum]
|
||||||
|
if rcp then
|
||||||
get_grid_fs(fs, rcp, spacing)
|
get_grid_fs(fs, rcp, spacing)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function make_formspec(name)
|
local function make_formspec(name)
|
||||||
local data = pdata[name]
|
local data = pdata[name]
|
||||||
@ -946,22 +999,41 @@ local function make_formspec(name)
|
|||||||
]],
|
]],
|
||||||
sfinv_only and 2.76 or 2.72, ESC(data.filter))
|
sfinv_only and 2.76 or 2.72, ESC(data.filter))
|
||||||
|
|
||||||
|
if CORE_VERSION >= 520 then
|
||||||
fs[#fs + 1] = fmt([[
|
fs[#fs + 1] = fmt([[
|
||||||
image_button[%f,-0.05;0.85,0.85;%s;search;;;false;%s^\[colorize:yellow:255]
|
style[search;border=false;bgimg=%s;bgimg_hovered=%s]
|
||||||
image_button[%f,-0.05;0.85,0.85;%s;clear;;;false;%s^\[colorize:red:255]
|
style[clear;border=false;bgimg=%s;bgimg_hovered=%s]
|
||||||
|
style[prev_page;border=false;bgimg=%s;bgimg_hovered=%s]
|
||||||
|
style[next_page;border=false;bgimg=%s;bgimg_hovered=%s]
|
||||||
]],
|
]],
|
||||||
sfinv_only and 2.6 or 2.54, PNG.search, PNG.search,
|
PNG.search, PNG.search_hover,
|
||||||
sfinv_only and 3.3 or 3.25, PNG.clear, PNG.clear)
|
PNG.clear, PNG.clear_hover,
|
||||||
|
PNG.prev, PNG.prev_hover,
|
||||||
|
PNG.next, PNG.next_hover)
|
||||||
|
|
||||||
fs[#fs + 1] = fmt("label[%f,%f;%s / %u]",
|
fs[#fs + 1] = fmt(mul_elem(FMT.button, 4),
|
||||||
sfinv_only and 6.35 or (ROWS * 7.85) / 11,
|
sfinv_only and 2.6 or 2.54, -0.12, 0.85, 1, "search", "",
|
||||||
0.06, clr("yellow", data.pagenum), data.pagemax)
|
sfinv_only and 3.3 or 3.25, -0.12, 0.85, 1, "clear", "",
|
||||||
|
sfinv_only and 5.45 or (ROWS * 6.83) / 11, -0.12, 0.85, 1, "prev_page", "",
|
||||||
|
sfinv_only and 7.2 or (ROWS * 8.75) / 11, -0.12, 0.85, 1, "next_page", "")
|
||||||
|
else
|
||||||
|
fs[#fs + 1] = fmt([[
|
||||||
|
image_button[%f,-0.12;0.85,1;%s;search;;;false;%s]
|
||||||
|
image_button[%f,-0.12;0.85,1;%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(FMT.arrow .. FMT.arrow,
|
fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
|
||||||
sfinv_only and 5.45 or (ROWS * 6.83) / 11,
|
sfinv_only and 5.45 or (ROWS * 6.83) / 11,
|
||||||
-0.05, PNG.prev, "prev_page", PNG.prev,
|
-0.05, PNG.prev, "prev_page", PNG.prev,
|
||||||
sfinv_only and 7.2 or (ROWS * 8.75) / 11,
|
sfinv_only and 7.2 or (ROWS * 8.75) / 11,
|
||||||
-0.05, PNG.next, "next_page", PNG.next)
|
-0.05, PNG.next, "next_page", PNG.next)
|
||||||
|
end
|
||||||
|
|
||||||
|
fs[#fs + 1] = fmt("label[%f,%f;%s / %u]",
|
||||||
|
sfinv_only and 6.35 or (ROWS * 7.85) / 11,
|
||||||
|
0.06, clr("yellow", data.pagenum), data.pagemax)
|
||||||
|
|
||||||
if #data.items == 0 then
|
if #data.items == 0 then
|
||||||
local no_item = S("No item to show")
|
local no_item = S("No item to show")
|
||||||
@ -1012,21 +1084,6 @@ local show_fs = function(player, name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
craftguide.add_search_filter("groups", function(item, groups)
|
|
||||||
local itemdef = reg_items[item]
|
|
||||||
local has_groups = true
|
|
||||||
|
|
||||||
for i = 1, #groups do
|
|
||||||
local group = groups[i]
|
|
||||||
if not itemdef.groups[group] then
|
|
||||||
has_groups = nil
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return has_groups
|
|
||||||
end)
|
|
||||||
|
|
||||||
craftguide.register_craft_type("digging", {
|
craftguide.register_craft_type("digging", {
|
||||||
description = ESC(S("Digging")),
|
description = ESC(S("Digging")),
|
||||||
icon = "default_tool_steelpick.png",
|
icon = "default_tool_steelpick.png",
|
||||||
@ -1037,6 +1094,16 @@ craftguide.register_craft_type("digging_chance", {
|
|||||||
icon = "default_tool_mesepick.png",
|
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 function search(data)
|
||||||
local filter = data.filter
|
local filter = data.filter
|
||||||
|
|
||||||
@ -1058,28 +1125,28 @@ local function search(data)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local filtered_list, c = {}, 0
|
local filtered_list, order, c = {}, {}, 0
|
||||||
|
|
||||||
for i = 1, #data.items_raw do
|
for i = 1, #data.items_raw do
|
||||||
local item = data.items_raw[i]
|
local item = data.items_raw[i]
|
||||||
local def = reg_items[item]
|
local def = reg_items[item]
|
||||||
local desc = (def and def.description) and lower(def.description) or ""
|
local desc = (def and def.description) and lower(def.description) or ""
|
||||||
local search_in = fmt("%s %s", item, desc)
|
|
||||||
local to_add
|
local to_add
|
||||||
|
|
||||||
if search_filter then
|
if search_filter then
|
||||||
for filter_name, values in pairs(filters) do
|
for filter_name, values in pairs(filters) do
|
||||||
local func = search_filters[filter_name]
|
local func = search_filters[filter_name]
|
||||||
to_add = func(item, values) and (search_filter == "" or
|
to_add = func(item, values) and (search_filter == "" or
|
||||||
find(search_in, search_filter, 1, true))
|
(sfind(item, search_filter) or sfind(desc, search_filter)))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
to_add = find(search_in, filter, 1, true)
|
to_add = sfind(item, filter) or sfind(desc, filter)
|
||||||
end
|
end
|
||||||
|
|
||||||
if to_add then
|
if to_add then
|
||||||
c = c + 1
|
c = c + 1
|
||||||
filtered_list[c] = item
|
filtered_list[c] = item
|
||||||
|
order[item] = to_add
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1092,9 +1159,28 @@ local function search(data)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sort(filtered_list, function(a, b)
|
||||||
|
return order[a] < order[b]
|
||||||
|
end)
|
||||||
|
|
||||||
data.items = filtered_list
|
data.items = filtered_list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
craftguide.add_search_filter("groups", function(item, groups)
|
||||||
|
local def = reg_items[item]
|
||||||
|
local has_groups = true
|
||||||
|
|
||||||
|
for i = 1, #groups do
|
||||||
|
local group = groups[i]
|
||||||
|
if not def.groups[group] then
|
||||||
|
has_groups = nil
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return has_groups
|
||||||
|
end)
|
||||||
|
|
||||||
--[[ As `core.get_craft_recipe` and `core.get_all_craft_recipes` do not
|
--[[ As `core.get_craft_recipe` and `core.get_all_craft_recipes` do not
|
||||||
return the replacements and toolrepair, we have to override
|
return the replacements and toolrepair, we have to override
|
||||||
`core.register_craft` and do some reverse engineering.
|
`core.register_craft` and do some reverse engineering.
|
||||||
@ -1256,7 +1342,9 @@ end
|
|||||||
|
|
||||||
local function handle_aliases(hash)
|
local function handle_aliases(hash)
|
||||||
for oldname, newname in pairs(reg_aliases) do
|
for oldname, newname in pairs(reg_aliases) do
|
||||||
|
cache_recipes(oldname)
|
||||||
local recipes = recipes_cache[oldname]
|
local recipes = recipes_cache[oldname]
|
||||||
|
|
||||||
if recipes then
|
if recipes then
|
||||||
if not recipes_cache[newname] then
|
if not recipes_cache[newname] then
|
||||||
recipes_cache[newname] = {}
|
recipes_cache[newname] = {}
|
||||||
@ -1284,7 +1372,7 @@ local function handle_aliases(hash)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if recipes_cache[oldname] and not hash[newname] then
|
if newname ~= "" and recipes_cache[oldname] and not hash[newname] then
|
||||||
init_items[#init_items + 1] = newname
|
init_items[#init_items + 1] = newname
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1296,9 +1384,42 @@ local function show_item(def)
|
|||||||
def.description and def.description ~= ""
|
def.description and def.description ~= ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function tablelen(t)
|
||||||
|
local c = 0
|
||||||
|
for _ in pairs(t) do
|
||||||
|
c = c + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return c
|
||||||
|
end
|
||||||
|
|
||||||
local function get_init_items()
|
local function get_init_items()
|
||||||
|
local ic, it, last_str = 0, tablelen(reg_items), ""
|
||||||
local hash = {}
|
local hash = {}
|
||||||
|
|
||||||
|
local function iop(str)
|
||||||
|
io.write(("\b \b"):rep(#last_str))
|
||||||
|
io.write(str)
|
||||||
|
io.flush()
|
||||||
|
last_str = str
|
||||||
|
end
|
||||||
|
|
||||||
|
local full_char, empty_char = "▰", "▱"
|
||||||
|
|
||||||
for name, def in pairs(reg_items) do
|
for name, def in pairs(reg_items) do
|
||||||
|
ic = ic + 1
|
||||||
|
local percent, bar, len = (ic * 100) / it, "", 20
|
||||||
|
|
||||||
|
for i = 1, len do
|
||||||
|
if i <= percent / (100 / len) then
|
||||||
|
bar = bar .. full_char
|
||||||
|
else
|
||||||
|
bar = bar .. empty_char
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
iop(fmt("[craftguide] Caching data %s (%u%%)\r", bar, percent))
|
||||||
|
|
||||||
if show_item(def) then
|
if show_item(def) then
|
||||||
if not fuel_cache[name] then
|
if not fuel_cache[name] then
|
||||||
cache_fuel(name)
|
cache_fuel(name)
|
||||||
@ -1311,7 +1432,7 @@ local function get_init_items()
|
|||||||
cache_usages(name)
|
cache_usages(name)
|
||||||
register_drops(name, def)
|
register_drops(name, def)
|
||||||
|
|
||||||
if recipes_cache[name] or usages_cache[name] then
|
if name ~= "" and recipes_cache[name] or usages_cache[name] then
|
||||||
init_items[#init_items + 1] = name
|
init_items[#init_items + 1] = name
|
||||||
hash[name] = true
|
hash[name] = true
|
||||||
end
|
end
|
||||||
@ -1333,6 +1454,8 @@ local function get_init_items()
|
|||||||
post_data = write_json(post_data),
|
post_data = write_json(post_data),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
print()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function init_data(name)
|
local function init_data(name)
|
||||||
|
@ -21,3 +21,6 @@ Show recipe(s) of the pointed node=Mostra la ricetta del nodo puntato
|
|||||||
No node pointed=Nessun nodo puntato
|
No node pointed=Nessun nodo puntato
|
||||||
You don't know a recipe for this node=Non conosci una ricetta per questo nodo
|
You don't know a recipe for this node=Non conosci una ricetta per questo nodo
|
||||||
No recipe for this node=Nessuna ricetta per questo nodo
|
No recipe for this node=Nessuna ricetta per questo nodo
|
||||||
|
Digging=Scavando
|
||||||
|
Digging Chance=Probabilità di scavare
|
||||||
|
@1 of chance to drop=@1 di probabilità di rilascio
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 5.7 KiB |
Reference in New Issue
Block a user