Compare commits

..

3 Commits

101
init.lua
View File

@ -7,7 +7,6 @@ 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"
@ -573,7 +572,6 @@ local function cache_fuel(item)
type = "fuel",
items = {item},
burntime = burntime,
replacements = replacements.fuel[item],
}
end
end
@ -586,6 +584,7 @@ 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
@ -698,23 +697,7 @@ local function cache_drops(name, drop)
end
local function cache_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
for k, v in pairs(replacements[item]) do
_recipes[k].replacements = v
end
recipes = _recipes
end
recipes_cache[item] = recipes
recipes_cache[item] = get_all_recipes(item)
end
local function get_recipes(item, data, player)
@ -792,7 +775,7 @@ local function is_fav(favs, query_item)
end
local function weird_desc(str)
return not true_str(str) or find(str, "[\\]*") or not find(str, "%u")
return not true_str(str) or find(str, "\n") or not find(str, "%u")
end
local function toupper(str)
@ -803,10 +786,6 @@ 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)
@ -817,16 +796,10 @@ 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
desc = toupper(desc)
return strip_newline(toupper(desc))
end
return desc
return strip_newline(translate(lang_code, desc))
elseif true_str(item) then
return toupper(match(item, ":(.*)"))
@ -1083,13 +1056,7 @@ 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 = ""
if groups then
btn_name = fmt("group|%s|%s", groups[1], item)
elseif item ~= "" then
btn_name = item
end
local btn_name = item ~= "" and item or (groups and groups[1] or "")
fs[#fs + 1] = fmt(FMT.item_image_button,
X, Y, btn_size, btn_size, item, btn_name, label)
@ -1173,7 +1140,7 @@ 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;;%s]",
fs[#fs + 1] = fmt("hypertext[9.05,%f;5.85,1.2;item_title;%s]",
spacing - 0.1,
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>",
@ -1342,10 +1309,7 @@ local function make_fs(data)
lbl = ES"Collect items to reveal more recipes"
end
fs[#fs + 1] = fmt("hypertext[%f,%f;%f,%f;;%s]",
0.05, 3, 8.29, 1,
fmt("<center><style size=20><b>%s</b></style></center>]",
translate(data.lang_code, lbl)))
fs[#fs + 1] = fmt(FMT.button, -0.25, 3, 8.3, 1, "no_item", lbl)
end
local first_item = (data.pagenum - 1) * IPP
@ -1475,7 +1439,6 @@ 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)
@ -1497,15 +1460,41 @@ core.register_craft = function(def)
for i = 1, #output do
local name = output[i]
rcp_num[name] = (rcp_num[name] or 0) + 1
if def.replacements then
if def.type == "fuel" then
replacements.fuel[name] = def.replacements
else
replacements[name] = replacements[name] or {}
replacements[name][rcp_num[name]] = def.replacements
if def.type == "fuel" then
def.items = {def.recipe}
fuel_cache[name] = def
elseif def.type == "cooking" then
def.items = {def.recipe}
elseif def.type == "shapeless" then
def.items, def.width = {}, 0
for j = 1, #def.recipe do
def.items[#def.items + 1] = def.recipe[j]
end
else
def.items, def.width = {}, #def.recipe[1]
local c = 0
for j = 1, #def.recipe do
if def.recipe[j] then
for h = 1, def.width do
c = c + 1
local it = def.recipe[j][h]
if it and it ~= "" then
def.items[c] = it
end
end
end
end
end
if def.type ~= "fuel" then
def.recipe = nil
recipes_cache[name] = recipes_cache[name] or {}
insert(recipes_cache[name], 1, def)
end
end
end
@ -1567,14 +1556,16 @@ local function get_init_items()
if name ~= "" and show_item(def) then
cache_drops(name, def.drop)
if not fuel_cache[name] then
if not fuel_cache[name] then --[*]
cache_fuel(name)
end
if not recipes_cache[name] then
if not recipes_cache[name] then --[*]
cache_recipes(name)
end
--[*] `core.register_craft` override may have cached them already
_preselect[name] = true
end
end
@ -1702,8 +1693,6 @@ 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