Modul:Data

Aus Firestone Idle RPG Wiki
Zur Navigation springen Zur Suche springen

Die Dokumentation für dieses Modul kann unter Modul:Data/Doku erstellt werden

--<pre>
--------------------------------------------------------------------------------
-- Helper module to get values from data module
-- Reads data value key1.key2, e.g.{["key1"]={["key2"]="baba"}} from Module:ModuleName/data.
-- Syntax: {{#invoke:Data|main|Module:ModuleName/data|key1|key2}} -> baba
-- Syntax: {{#invoke:Data|Module:ModuleName/data|key1|key2}} -> baba
--
-- @module data
-- @alias p
--------------------------------------------------------------------------------

local p = {}

--------------------------------------------------------------------------------
-- @function p.load
-- @param[opt] {string} modName
-- @param {sequence} args
-- @param {string} args[1] If `modName` is absent, then this is `modName`
-- @return {any}
--------------------------------------------------------------------------------
function p.load(modName, args)
	if (args == nil) then
		args = modName
		modName = nil
	end
	if (modName or args[1]) then 
		local data = mw.loadData(modName or args[1])
		
		for i,v in ipairs(args) do
			if (modName or i > 1) and data[v] then
				data = data[v]
			end
		end
		
		return data
	end
end

--------------------------------------------------------------------------------
-- @function p.main
-- @param {Frame} frame
--------------------------------------------------------------------------------
function p.main(frame)
	local args = frame.args
	return p.load(args)
end

return p