Module:UserMedals

local p = {} local dataMain = mw.loadData('Module:UserMedals/main') local dataTypes = mw.loadData('Module:UserMedals/types') local getArgs = require('Dev:Arguments').getArgs local lang = mw.language.new("en")

local hiddenMedals = {"fisher", "youngster", "pikachuFan", "unown", "champion", "battleLegend", "berryMaster", "gymLeader", "researcher", "idol", "gentleman", "pilot", "greatLeague", "ultraLeague", "masterLeague", "cameraman", "purifier", "hero", "ultraHero", "wayfarer", "successor", "megaEvolutionGuru", "triathlete", "picnicker", "sightseer", "risingStar"}

function p.medalProcess(mpName, mpValue, mpTable, mpData) -- old name compatibility if mpName == "fisherman" then mpName = "fisher" elseif mpName == "depotAgent" then mpName = "railStaff" elseif mpName == "ranger" then mpName = "researcher" -- short name compatibility elseif mpName == "guru" then mpName = "megaEvolutionGuru" end

if mpData[mpName] ~= nil then mpValue = string.gsub(mpValue, ",", "") mpValue = tonumber(mpValue) local mpHTML = "[[File:" .. mpName .. " "		local barWidth		local sortFactor = 0		local medalClass = "pogo-medal-num"

if mpValue < mpData[mpName]["bronze"] then sortFactor = 4000 barWidth = mpValue / mpData[mpName]["bronze"] mpHTML = mpHTML .. "shadow" if mpValue < 1 then for index = 1, #hiddenMedals do					if hiddenMedals[index] == mpName then mpHTML = "nodisplay" end end end elseif mpValue < mpData[mpName]["silver"] then sortFactor = 3000 barWidth = (mpValue - mpData[mpName]["bronze"]) / (mpData[mpName]["silver"] - mpData[mpName]["bronze"]) mpHTML = mpHTML .. "Bronze" elseif mpValue < mpData[mpName]["gold"] then sortFactor = 2000 barWidth = (mpValue - mpData[mpName]["silver"]) / (mpData[mpName]["gold"] - mpData[mpName]["silver"]) mpHTML = mpHTML .. "Silver" elseif mpValue < mpData[mpName]["plat"] then medalClass = "pogo-medal-num pogo-gold" sortFactor = 1000 barWidth = (mpValue - mpData[mpName]["gold"]) / (mpData[mpName]["plat"] - mpData[mpName]["gold"]) mpHTML = mpHTML .. "Gold" else medalClass = "pogo-medal-num pogo-plat" barWidth = -1 mpHTML = mpHTML .. "Platinum" end

if mpHTML == "nodisplay" then mpHTML = " " else mpHTML = mpHTML .. ".png|72px|link=]] " .. lang:formatNum(mpValue) .. " "		end

if barWidth > -1 then barWidth = string.format("%.3f", 100 * barWidth) mpHTML = mpHTML .. "  "		end

mpHTML = mpHTML .. " "		sortFactor = sortFactor + mpData[mpName]["sort"] mpTable[sortFactor] = mpHTML end

return mpTable end

function p.main(frame) local args = getArgs(frame) local mTable = {} local mOutput = " "

for mName,mValue in pairs(args) do		mTable = p.medalProcess(mName, mValue, mTable, dataMain) end

local mTableKeys = {} for k in pairs(mTable) do table.insert(mTableKeys, k) end table.sort(mTableKeys) for _, k in ipairs(mTableKeys) do mOutput = mOutput .. mTable[k] end mOutput = mOutput .. " "	return mOutput end

function p.types(frame) local args = getArgs(frame) local mTable = {} local mOutput = " "

for mName,mValue in pairs(args) do		mTable = p.medalProcess(mName, mValue, mTable, dataTypes) end

local mTableKeys = {} for k in pairs(mTable) do table.insert(mTableKeys, k) end table.sort(mTableKeys) for _, k in ipairs(mTableKeys) do mOutput = mOutput .. mTable[k] end mOutput = mOutput .. " "	return mOutput end

return p