Module:Focus


-- -- Module:Focus -- -- This module implements Template:Focus.


local p = {};

local tagSet = { generic = {dlc = "generic"}, warlord = {dlc = "generic"}, hoa = {dlc = "generic"}, ast = {dlc = "tfv"}, can = {dlc = "tfv"}, saf = {dlc = "tfv"}, raj = {dlc = "tfv"}, nzl = {dlc = "tfv"}, cze = {dlc = "dod"}, hun = {dlc = "dod"}, yug = {dlc = "dod"}, rom = {dlc = "dod"}, ger = {dlc = "wtt"}, jap = {dlc = "wtt"}, chi = {dlc = "wtt"}, prc = {dlc = "wtt"}, man = {dlc = "wtt"}, usa = {dlc = "mtg"}, eng = {dlc = "mtg"}, hol = {dlc = "mtg"}, mex = {dlc = "mtg"}, fra = {dlc = "lar"}, spr = {dlc = "lar"}, spa = {dlc = "lar"}, por = {dlc = "lar"}, vic = {dlc = "lar"}, fre = {dlc = "lar"}, tur = {dlc = "bftb"}, gre = {dlc = "bftb"}, bul = {dlc = "bftb"}, sov = {dlc = "nsb"}, pol = {dlc = "nsb"}, est = {dlc = "nsb"}, lat = {dlc = "nsb"}, lit = {dlc = "nsb"}, baltic = {dlc = "nsb"}, ita = {dlc = "bba"}, swi = {dlc = "bba"}, eth = {dlc = "bba"}, den = {dlc = "aat"}, swe = {dlc = "aat"}, nor = {dlc = "aat"}, fin = {dlc = "aat"}, ice = {dlc = "aat"}, nordic = {dlc = "aat"}, };

local chinese_warlords = { gxc = {}, shx = {}, sik = {}, xsm = {}, yun = {}, };

local hoa_nations = { afa = {}, beg = {}, gba = {}, har = {}, oro = {}, gem = {}, sid = {}, tig = {}, };

function p.main(frame) local args = frame.args local aTag = args['tag']

--Check tag if chinese_warlords[aTag] then --Set chinese warlords tag to "warlord" aTag = "warlord" elseif hoa_nations[aTag] then --Set horn of africa countries tag to "hoa" aTag = "hoa" elseif not tagSet[aTag] then return "(unrecognized TAG \"" .. aTag .. "\" for Template:Focus)" end

--Load only 1 module at a time (One page per dlc) local dlcPage = "Module:Focus/" .. tagSet[aTag].dlc local tag = mw.loadData(dlcPage)[aTag]

--Check id if not tag[args['id']] then return "(unrecognized id \"" .. args['id'] .. "\" in TAG \"" .. aTag .. "\" for Template:Focus)" end

local id = tag[args['id']]

local page = "" if id.continuous then page = "Continuous focus" elseif id.shared then page = tag.shared_page elseif id.joint then page = tag.joint_page else page = tag.page end

--icon local icon = "" if args.icon ~= nil and args.icon ~= "" then icon = args.icon elseif type(id.icon) == "table" then args.iconid = tonumber(args.iconid) if id.icon[args.iconid] then icon = id.icon[args.iconid] else --Fallback value (default) if out of range icon = id.icon[1] end else icon = id.icon end


local ic = string.format("link=", icon, id.name, args['size']) if args['link'] == "yes" then ic = ic .. page if id.subtree ~= nil then ic = ic .. id.subtree end end if id.replaceName == nil then ic = ic .. "#" .. id.name else ic = ic .. "#" .. id.replaceName end if id.dup_name ~= nil then ic = ic .. " " .. id.dup_name end ic = ic .. ""

--text local name = "" if args.text ~= nil and args.text ~= "" then name = args.text else name = id.name end

local tx = name if args['link'] == "yes" then tx = "[[" .. page if id.subtree ~= nil then tx = tx .. id.subtree end if id.replaceName == nil then tx = tx .. "#" .. id.name else tx = tx .. "#" .. id.replaceName end if id.dup_name ~= nil then tx = tx .. " " .. id.dup_name end tx = tx .. "|" .. name .. "]]" end

return ic .. tx end

return p