mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Move values the mainmenu caches to dedicated files (#14433)
This commit is contained in:
parent
bb6782ca58
commit
6c6e48f006
16 changed files with 142 additions and 132 deletions
|
@ -18,6 +18,26 @@
|
|||
-- Global menu data
|
||||
menudata = {}
|
||||
|
||||
-- located in user cache path, for remembering this like e.g. last update check
|
||||
cache_settings = Settings(core.get_cache_path() .. DIR_DELIM .. "common.conf")
|
||||
|
||||
--- Checks if the given key contains a timestamp less than a certain age.
|
||||
--- Pair this with a call to `cache_settings:set(key, tostring(os.time()))`
|
||||
--- after successfully refreshing the cache.
|
||||
--- @param key Name of entry in cache_settings
|
||||
--- @param max_age Age to check against, in seconds
|
||||
--- @return true if the max age is not reached
|
||||
function check_cache_age(key, max_age)
|
||||
local time_now = os.time()
|
||||
local time_checked = tonumber(cache_settings:get(key)) or 0
|
||||
return time_now - time_checked < max_age
|
||||
end
|
||||
|
||||
function core.on_before_close()
|
||||
-- called before the menu is closed, either exit or to join a game
|
||||
cache_settings:write()
|
||||
end
|
||||
|
||||
-- Local cached values
|
||||
local min_supp_proto, max_supp_proto
|
||||
|
||||
|
@ -27,6 +47,16 @@ function common_update_cached_supp_proto()
|
|||
end
|
||||
common_update_cached_supp_proto()
|
||||
|
||||
-- Other global functions
|
||||
|
||||
function core.sound_stop(handle, ...)
|
||||
return handle:stop(...)
|
||||
end
|
||||
|
||||
function os.tmpname()
|
||||
error('do not use') -- instead: core.get_temp_path()
|
||||
end
|
||||
|
||||
-- Menu helper functions
|
||||
|
||||
local function render_client_count(n)
|
||||
|
@ -140,11 +170,6 @@ function render_serverlist_row(spec)
|
|||
|
||||
return table.concat(details, ",")
|
||||
end
|
||||
---------------------------------------------------------------------------------
|
||||
os.tmpname = function()
|
||||
error('do not use') -- instead use core.get_temp_path()
|
||||
end
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
function menu_render_worldlist()
|
||||
local retval = {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue