Add an option to disable the auto-cache

This commit is contained in:
Jean-Patrick Guerrero 2020-04-16 03:08:36 +02:00
parent 1910b4b345
commit 6d994fc8d5
2 changed files with 46 additions and 26 deletions

@ -10,10 +10,12 @@ local fuel_cache = {}
local toolrepair 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 autocache = core.settings:get_bool "craftguide_autocache"
local http = core.request_http_api() local http = core.request_http_api()
local storage = core.get_mod_storage()
local reg_items = core.registered_items local reg_items = core.registered_items
local reg_tools = core.registered_tools local reg_tools = core.registered_tools
@ -130,7 +132,7 @@ craftguide.group_stereotypes = {
mesecon_conductor_craftable = "mesecons:wire_00000000_off", mesecon_conductor_craftable = "mesecons:wire_00000000_off",
} }
local GROUP_NAMES = { local group_names = {
coal = S"Any coal", coal = S"Any coal",
wool = S"Any wool", wool = S"Any wool",
wood = S"Any wood planks", wood = S"Any wood planks",
@ -708,7 +710,7 @@ local function get_tooltip(name, info)
if info.groups then if info.groups then
sort(info.groups) sort(info.groups)
tooltip = GROUP_NAMES[concat(info.groups, ",")] tooltip = group_names[concat(info.groups, ",")]
if not tooltip then if not tooltip then
local groupstr, c = {}, 0 local groupstr, c = {}, 0
@ -1470,31 +1472,43 @@ local function show_item(def)
end end
local function get_init_items() local function get_init_items()
print "[craftguide] Caching data (this may take a while)" if not autocache then
local hash = {} init_items = dslz(storage:get "init_items")
fuel_cache = dslz(storage:get "fuel_cache")
usages_cache = dslz(storage:get "usages_cache")
recipes_cache = dslz(storage:get "recipes_cache")
else
print "[craftguide] Caching data (this may take a while)"
local hash = {}
for name, def in pairs(reg_items) do for name, def in pairs(reg_items) do
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)
end end
if not recipes_cache[name] then if not recipes_cache[name] then
cache_recipes(name) cache_recipes(name)
end end
cache_usages(name) cache_usages(name)
register_drops(name, def.drop) register_drops(name, def.drop)
if name ~= "" and 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 end
end end
end
handle_aliases(hash) handle_aliases(hash)
sort(init_items) sort(init_items)
storage:set_string("init_items", slz(init_items))
storage:set_string("fuel_cache", slz(fuel_cache))
storage:set_string("usages_cache", slz(usages_cache))
storage:set_string("recipes_cache", slz(recipes_cache))
end
if http and true_str(craftguide.export_url) then if http and true_str(craftguide.export_url) then
local post_data = { local post_data = {
@ -1957,8 +1971,8 @@ if progressive_mode then
local data = pdata[name] local data = pdata[name]
local meta = player:get_meta() local meta = player:get_meta()
data.inv_items = dslz(meta:get_string("inv_items")) or {} data.inv_items = dslz(meta:get_string "inv_items") or {}
data.known_recipes = dslz(meta:get_string("known_recipes")) or 0 data.known_recipes = dslz(meta:get_string "known_recipes") or 0
data.hud = { data.hud = {
bg = player:hud_add{ bg = player:hud_add{

@ -1,5 +1,11 @@
# The progressive mode shows recipes you can craft from items you ever had in your inventory. # The progressive mode shows recipes you can craft from items you ever had in your inventory.
craftguide_progressive_mode (Progressive Mode) bool false craftguide_progressive_mode (Learn crafting recipes progressively) 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 (Crafting Guide in inventory only) bool false
# Enable pre-caching of item recipes.
# Disabling it will result in faster game loading but lesser in-game efficiency.
# If you enable or disable mods, or edit the current mod recipes in your game, you should re-enable the cache,
# otherwise some recipes will be skipped or removed. Usage at your own risk.
craftguide_autocache (Auto-caching of recipes) bool true