Module:Animation

From Terraria Wiki
Revision as of 05:20, 17 April 2024 by Westgrass (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

No documentation subpage exists yet for this module. Create one now.


local VariablesLua = mw.ext.VariablesLua
local cache = mw.ext.LuaCache

local load = function()
	local status, result = pcall(function ()
		return mw.text.jsonDecode(cache.get('animation__database'))
	end)
	if status then
		return result
	else
		--fallback
		local info = require('Module:Animation/db') -- return table of mw.loadData() has a metatable, can not be used for cache.set and mw.loadData.
		cache.set( 'animation__database', mw.text.jsonEncode(info))
		return info
	end
end;

return {
	-- load database for template:animation
	-- from template: {{#invoke:animation|loadData}}
	loadData = function(frame)
		for k,v in pairs(load()) do
			VariablesLua.vardefine( 'animation:info:'..k, v )
		end
	end,

	purge = function()
		cache.delete( 'animation__database')
	end

}