Civilization Wiki
Advertisement

Documentation for this module may be created at Module:Data/doc

-- Game specific functions:
-- Use the game's suffix to reach the appropriate subpage.
-- Example: Data/CivRev2
local p = {}

--To get a simple text value
function p.GetValue(frame)
	local game = frame.args[1]
	local datatype = frame.args[2]
	local entry = frame.args[3]
	local field = frame.args[4]
	local data = mw.loadData("Module:Data/"..game.."/"..datatype)
	
	local value = data[entry][field]
	if value[1] then
		local s = ""
		local first = true
		for k,v in pairs(value) do
			s = s..(first and "" or ", ")..v
			first = false
		end
		return s
	else
		return value
	end
end

--To get all of the keys of a game's datatype
function p.GetKeys(frame)
	local game = frame.args[1]
	local datatype = frame.args[2]
	local separator = frame.args[3] or ""
	local data = mw.loadData("Module:Data/"..game.."/"..datatype)
	
	local t = {}
	for k,v in pairs(data) do
		table.insert(t,k)
	end
	table.sort(t)
	
	local s = ""
	local first = true
	for i = 1, #t do
		s = s..(first and "" or separator)..t[i]
		first = false
	end
	return s
	
end

return p
Advertisement