FANDOM


--Sub pages : 
--/Buildings
--/Techs
--/Pedia
 
local p = {}
 
--Utility functions
local function Link(s)
	return "[["..s.." (Civ2)|"..s.."]]"
end
 
local function LinkAll(t)
	local s = ""
	local first = true
	for k,v in pairs(t) do
		s = s..(first and "" or "<br/>")..Link(v)
		first = false
	end
	return s
end
 
function p.GetTechImage(frame, articlename)
    local PAGENAME = articlename or frame.args[1]
	local name = string.gsub(PAGENAME, " %(.*","")
	local data = mw.loadData("Module:Data/Civ2/Techs")[name]
	return data.epoch.."_"..data.category.."_advance_(Civ2).png"
end
 
 
function p.GetTechData(frame, articlename, key)
    local PAGENAME = articlename or frame.args[1]
    local key = key or frame.args[2]
	local name = string.gsub(PAGENAME, " %(.*","")
	local data = mw.loadData("Module:Data/Civ2/Techs")[name]
 
    for k,value in pairs(data) do 
        if k == key then
            if type(value) == "table" then
                return LinkAll(value)
            else
                return value
            end
        end
    end
    return ""
end
 
local pediapage = [=[{|
| %s
| %s
|}]=]
 
function p.GetPediaPage(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local name = string.gsub(PAGENAME, " %(.*","")
	local data = mw.loadData("Module:Data/Civ2/Pedia")[name]
 
	return frame:preprocess(string.format(pediapage,
        name, 
        data.notes))
end
 
local buildingpage = [=[<infobox>
<title><default>%s</default></title>
    <image><default>%s.png</default></image>
    <data><label>Advance required</label>
        <default>%s</default></data>
    <data><label>Buildings required</label>
        <default>%s</default></data>
    <data><label>Cost</label>
        <default>%s</default></data>
    <data><label>Maintenance</label>
        <default>%s</default></data>
    <data><label>Effect</label>
        <default>%s</default></data>
</infobox>
{{BackArrow|List of buildings in Civ2|The list of buildings}}{{#if:{{NAMESPACE}} | |[[Category:Buildings (Civ2)]]}}]=]
 
function p.GetBuildingPage(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local name = string.gsub(PAGENAME, " %(.*","")
	local data = mw.loadData("Module:Data/Civ2/Buildings")[name]
 
	return frame:preprocess(string.format(buildingpage,
	name,
	"[[Image:"..PAGENAME..".png|108px]]",
	data.reqtech and Link(data.reqtech) or "None",
	data.reqbuild and Link(data.reqbuild) or "None",
	data.cost and data.cost or "None",
	data.maint and data.maint or "None",
        data.notes and data.notes or "None"))
end
 
return p