mirror of
https://github.com/minetest-mods/craftguide.git
synced 2025-06-28 22:26:28 +02:00
Compare commits
14 Commits
be4aebdacd
...
1.14.2
Author | SHA1 | Date | |
---|---|---|---|
efe7434dd4 | |||
df26d31a2d | |||
50d19faa48 | |||
d93f5b0cf2 | |||
f83bc9cccf | |||
f88e0412fc | |||
6e6ff93d29 | |||
2fd3604cac | |||
96f9c85c77 | |||
9412ac740a | |||
f2a5c4255e | |||
d903aaca89 | |||
c30db91662 | |||
1fb7790c4e |
114
init.lua
114
init.lua
@ -7,6 +7,7 @@ local searches = {}
|
||||
local recipes_cache = {}
|
||||
local usages_cache = {}
|
||||
local fuel_cache = {}
|
||||
local replacements = {fuel = {}}
|
||||
local toolrepair
|
||||
|
||||
local progressive_mode = core.settings:get_bool "craftguide_progressive_mode"
|
||||
@ -22,6 +23,7 @@ local reg_aliases = core.registered_aliases
|
||||
local log = core.log
|
||||
local after = core.after
|
||||
local clr = core.colorize
|
||||
local sound_play = core.sound_play
|
||||
local parse_json = core.parse_json
|
||||
local write_json = core.write_json
|
||||
local chat_send = core.chat_send_player
|
||||
@ -102,6 +104,7 @@ local FMT = {
|
||||
image = "image[%f,%f;%f,%f;%s]",
|
||||
button = "button[%f,%f;%f,%f;%s;%s]",
|
||||
tooltip = "tooltip[%f,%f;%f,%f;%s]",
|
||||
hypertext = "hypertext[%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]",
|
||||
@ -572,6 +575,7 @@ local function cache_fuel(item)
|
||||
type = "fuel",
|
||||
items = {item},
|
||||
burntime = burntime,
|
||||
replacements = replacements.fuel[item],
|
||||
}
|
||||
end
|
||||
end
|
||||
@ -584,7 +588,6 @@ end
|
||||
|
||||
local function get_usages(recipe)
|
||||
local added = {}
|
||||
|
||||
for _, item in pairs(recipe.items) do
|
||||
item = reg_aliases[item] or item
|
||||
if not added[item] then
|
||||
@ -697,7 +700,35 @@ local function cache_drops(name, drop)
|
||||
end
|
||||
|
||||
local function cache_recipes(item)
|
||||
recipes_cache[item] = get_all_recipes(item)
|
||||
local recipes = get_all_recipes(item)
|
||||
|
||||
if replacements[item] then
|
||||
local _recipes = {}
|
||||
|
||||
for k, v in ipairs(recipes or {}) do
|
||||
_recipes[#recipes + 1 - k] = v
|
||||
end
|
||||
|
||||
local shift = 0
|
||||
local size_rpl = maxn(replacements[item])
|
||||
local size_rcp = #_recipes
|
||||
|
||||
if size_rpl > size_rcp then
|
||||
shift = size_rcp - size_rpl
|
||||
end
|
||||
|
||||
for k, v in pairs(replacements[item]) do
|
||||
k = k + shift
|
||||
|
||||
if _recipes[k] then
|
||||
_recipes[k].replacements = v
|
||||
end
|
||||
end
|
||||
|
||||
recipes = _recipes
|
||||
end
|
||||
|
||||
recipes_cache[item] = recipes
|
||||
end
|
||||
|
||||
local function get_recipes(item, data, player)
|
||||
@ -734,21 +765,17 @@ end
|
||||
local function groups_to_items(groups, get_all)
|
||||
if not get_all and #groups == 1 then
|
||||
local group = groups[1]
|
||||
local def_gr = "default:" .. group
|
||||
local stereotypes = craftguide.group_stereotypes
|
||||
local stereotype = stereotypes and stereotypes[group]
|
||||
stereotype = reg_items[stereotype] and stereotype
|
||||
local stereotype = craftguide.group_stereotypes[group]
|
||||
local def = reg_items[stereotype]
|
||||
|
||||
if stereotype then
|
||||
if def and show_item(def) then
|
||||
return stereotype
|
||||
elseif reg_items[def_gr] then
|
||||
return def_gr
|
||||
end
|
||||
end
|
||||
|
||||
local names = {}
|
||||
for name, def in pairs(reg_items) do
|
||||
if item_has_groups(def.groups, groups) then
|
||||
if show_item(def) and item_has_groups(def.groups, groups) then
|
||||
if get_all then
|
||||
names[#names + 1] = name
|
||||
else
|
||||
@ -779,7 +806,7 @@ local function is_fav(favs, query_item)
|
||||
end
|
||||
|
||||
local function weird_desc(str)
|
||||
return not true_str(str) or find(str, "\n") or not find(str, "%u")
|
||||
return not true_str(str) or find(str, "[\\]*") or not find(str, "%u")
|
||||
end
|
||||
|
||||
local function toupper(str)
|
||||
@ -790,6 +817,10 @@ local function strip_newline(str)
|
||||
return match(str, "[^\n]*")
|
||||
end
|
||||
|
||||
local function strip_prefix(str)
|
||||
return match(str, ".*@.*%)(.*)()") or str
|
||||
end
|
||||
|
||||
local function get_desc(item, lang_code)
|
||||
if sub(item, 1, 1) == "_" then
|
||||
item = sub(item, 2)
|
||||
@ -800,10 +831,16 @@ local function get_desc(item, lang_code)
|
||||
if def then
|
||||
local desc = def.description
|
||||
if true_str(desc) then
|
||||
desc = translate(lang_code, desc)
|
||||
desc = desc:trim()
|
||||
desc = strip_newline(desc)
|
||||
desc = strip_prefix(desc)
|
||||
|
||||
if not find(desc, "%u") then
|
||||
return strip_newline(toupper(desc))
|
||||
desc = toupper(desc)
|
||||
end
|
||||
return strip_newline(translate(lang_code, desc))
|
||||
|
||||
return desc
|
||||
|
||||
elseif true_str(item) then
|
||||
return toupper(match(item, ":(.*)"))
|
||||
@ -847,13 +884,13 @@ local function get_tooltip(item, info, lang_code)
|
||||
end
|
||||
|
||||
if info.replace then
|
||||
for i = 1, #info.replace do
|
||||
local rpl = match(info.replace[i], "%S+")
|
||||
for i = 1, #info.replace.items do
|
||||
local rpl = match(info.replace.items[i], "%S+")
|
||||
local desc = clr("#ff0", get_desc(rpl, lang_code))
|
||||
|
||||
if info.cooktime then
|
||||
if info.replace.type == "cooking" then
|
||||
tooltip = add(S("Replaced by @1 on smelting", desc))
|
||||
elseif info.burntime then
|
||||
elseif info.replace.type == "fuel" then
|
||||
tooltip = add(S("Replaced by @1 on burning", desc))
|
||||
else
|
||||
tooltip = add(S("Replaced by @1 on crafting", desc))
|
||||
@ -1036,11 +1073,11 @@ local function get_grid_fs(lang_code, fs, rcp, spacing)
|
||||
for j = 1, #(rcp.replacements or {}) do
|
||||
local replacement = rcp.replacements[j]
|
||||
if replacement[1] == name then
|
||||
replace = replace or {}
|
||||
replace = replace or {type = rcp.type, items = {}}
|
||||
|
||||
local added
|
||||
|
||||
for _, v in ipairs(replace) do
|
||||
for _, v in ipairs(replace.items) do
|
||||
if replacement[2] == v then
|
||||
added = true
|
||||
break
|
||||
@ -1049,7 +1086,7 @@ local function get_grid_fs(lang_code, fs, rcp, spacing)
|
||||
|
||||
if not added then
|
||||
label = fmt("%s%s\nR", label ~= "" and "\n" or "", label)
|
||||
replace[#replace + 1] = replacement[2]
|
||||
replace.items[#replace.items + 1] = replacement[2]
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1060,7 +1097,13 @@ local function get_grid_fs(lang_code, fs, rcp, spacing)
|
||||
fs[#fs + 1] = fmt(FMT.image, X, Y, btn_size, btn_size, PNG.selected)
|
||||
end
|
||||
|
||||
local btn_name = item ~= "" and item or (groups and groups[1] or "")
|
||||
local btn_name = ""
|
||||
|
||||
if groups then
|
||||
btn_name = fmt("group|%s|%s", groups[1], item)
|
||||
elseif item ~= "" then
|
||||
btn_name = item
|
||||
end
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.item_image_button,
|
||||
X, Y, btn_size, btn_size, item, btn_name, label)
|
||||
@ -1144,8 +1187,8 @@ local function get_title_fs(query_item, lang_code, favs, fs, spacing)
|
||||
local t_desc = query_item
|
||||
t_desc = #t_desc > 40 and fmt("%s...", sub(t_desc, 1, 37)) or t_desc
|
||||
|
||||
fs[#fs + 1] = fmt("hypertext[9.05,%f;5.85,1.2;item_title;%s]",
|
||||
spacing - 0.1,
|
||||
fs[#fs + 1] = fmt(FMT.hypertext,
|
||||
9.05, spacing - 0.1, 5.85, 1.2,
|
||||
fmt("<item name=%s float=right width=64 height=64 rotate=yes>" ..
|
||||
"<big><b>%s</b></big>\n<style color=#7bf font=mono>%s</style>",
|
||||
query_item, desc, t_desc))
|
||||
@ -1313,7 +1356,10 @@ local function make_fs(data)
|
||||
lbl = ES"Collect items to reveal more recipes"
|
||||
end
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.button, -0.25, 3, 8.3, 1, "no_item", lbl)
|
||||
fs[#fs + 1] = fmt(FMT.hypertext,
|
||||
0.05, 3, 8.29, 1,
|
||||
fmt("<center><style size=20><b>%s</b></style></center>]",
|
||||
translate(data.lang_code, lbl)))
|
||||
end
|
||||
|
||||
local first_item = (data.pagenum - 1) * IPP
|
||||
@ -1443,6 +1489,7 @@ end)
|
||||
See engine's issues #4901, #5745 and #8920. ]]
|
||||
|
||||
local old_register_craft = core.register_craft
|
||||
local rcp_num = {}
|
||||
|
||||
core.register_craft = function(def)
|
||||
old_register_craft(def)
|
||||
@ -1463,12 +1510,16 @@ core.register_craft = function(def)
|
||||
end
|
||||
|
||||
for i = 1, #output do
|
||||
local name = output[i]
|
||||
local item = output[i]
|
||||
rcp_num[item] = (rcp_num[item] or 0) + 1
|
||||
|
||||
if def.replacements then
|
||||
if def.type == "fuel" then
|
||||
def.replacements = def.replacements
|
||||
def.items = {def.recipe}
|
||||
fuel_cache[name] = def
|
||||
replacements.fuel[item] = def.replacements
|
||||
else
|
||||
replacements[item] = replacements[item] or {}
|
||||
replacements[item][rcp_num[item]] = def.replacements
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1604,9 +1655,14 @@ on_joinplayer(function(player)
|
||||
end)
|
||||
|
||||
local function fields(player, _f)
|
||||
if _f.quit then return end
|
||||
local name = player:get_player_name()
|
||||
local data = pdata[name]
|
||||
|
||||
if not _f.key_enter_field then
|
||||
sound_play("craftguide_click", {to_player = name, gain = 0.2})
|
||||
end
|
||||
|
||||
if _f.clear then
|
||||
reset_data(data)
|
||||
|
||||
@ -1665,6 +1721,8 @@ local function fields(player, _f)
|
||||
item = sub(item, 1, -5)
|
||||
elseif sub(item, 1, 1) == "_" then
|
||||
item = sub(item, 2)
|
||||
elseif sub(item, 1, 6) == "group|" then
|
||||
item = match(item, "([%w:_]+)$")
|
||||
end
|
||||
|
||||
item = reg_aliases[item] or item
|
||||
|
BIN
sounds/craftguide_click.ogg
Normal file
BIN
sounds/craftguide_click.ogg
Normal file
Binary file not shown.
Reference in New Issue
Block a user