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")

function p.medalProcess(mpName, mpValue, mpTable, mpData, isTypes) -- 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 mpName == "custom" and isTypes == 0 then local mpHTML = mpValue local sortFactor = 10 mpTable[sortFactor] = mpHTML elseif mpName == "eliteCollector" and isTypes == 0 then mpValue = tonumber(mpValue) local mpHTML = " " .. lang:formatNum(mpValue) .. " "		local sortFactor = 100 mpTable[sortFactor] = mpHTML elseif 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 = 4500 barWidth = mpValue / mpData[mpName]["bronze"] mpHTML = mpHTML .. "shadow" if mpValue < 1 and isTypes == 0 then if mpData[mpName]["h"] == 1 then mpHTML = "nodisplay" end end elseif mpValue < mpData[mpName]["silver"] then sortFactor = 3500 barWidth = (mpValue - mpData[mpName]["bronze"]) / (mpData[mpName]["silver"] - mpData[mpName]["bronze"]) mpHTML = mpHTML .. "Bronze" elseif mpValue < mpData[mpName]["gold"] then sortFactor = 2500 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 = 1500 barWidth = (mpValue - mpData[mpName]["gold"]) / (mpData[mpName]["plat"] - mpData[mpName]["gold"]) mpHTML = mpHTML .. "Gold" else medalClass = "pogo-medal-num pogo-plat" sortFactor = 500 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, 0) 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 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, 1) 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 return mOutput end

return p