FANDOM


--Sub pages : 
--/Buildings
--/Techs
--/Pedia
--/Wonders
 
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><P style="text-align:center;font-style:bold;">%s</P></default></title>
    <image><default>%s</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 {{Production2}}</default></data>
    <data><label>Maintenance</label>
        <default>%s {{Gold2}}</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,
	"[[File:Model_"..PAGENAME..".png]]",
	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
 
local wonderpage = [=[<infobox>
    <title><default><P style="text-align:center;font-style:bold;">%s</P></default></title>
    <image><default>%s</default></image>
    <data><label>Technology required</label>
        <default>%s</default></data>
    <data><label>Cost</label>
        <default>%s {{Production2}}</default></data>
    <data><label>Obsoleted by</label>
        <default>%s</default></data>
    <data><label>Effect</label>
        <default>%s</default></data>
    <data><label>Notes</label>
        <default>%s</default></data>
</infobox>
{{BackArrow|List of wonders in Civ2|Back to the list of wonders}}{{#if:{{NAMESPACE}} | |[[Category:Wonders (Civ2)]]}}]=]
 
function p.GetWonderPage(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local name = string.gsub(PAGENAME, " %(.*","")
	local data = mw.loadData("Module:Data/Civ2/Wonders")[name]
	--Temporary fix to script error pages  We probably can get rid of if statement later
    if data then 
	    return frame:preprocess(string.format(wonderpage,
	    name,
	    "[[File:Model_"..PAGENAME..".png]]",
	    data.reqtech and Link(data.reqtech) or "None",
	    data.cost and data.cost or "None",
	    data.obsolete and Link(data.obsolete) or "None",
	    data.effect or "None",
	    data.notes or "None"))
	else
	-- Temp code
	    return frame:preprocess(string.format(wonderpage,
	    name,
	    "[[File:Model_"..PAGENAME..".png]]",
	    "To be added soon",
	    "To be added soon",
	    "To be added soon",
	    "To be added soon",
	    "To be added soon"))
	end
end
return p
Community content is available under CC-BY-SA unless otherwise noted.