Module:UserMedals

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

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

for mName,mValue in pairs(args) do		-- old name compatibility if mName == "fisherman" then mName = "fisher" elseif mName == "depotAgent" then mName = "railStaff" end

if data[mName] ~= nil then mValue = string.gsub(mValue, ",", "") mValue = tonumber(mValue) local mHTML = "[[File:" .. mName .. " "			local barWidth			local sortFactor = 0			local medalClass = "pogo-medal-num"

if mValue < data[mName]["bronze"] then sortFactor = 3000 barWidth = mValue / data[mName]["bronze"] if mName == "ultraHero" then mHTML = "" .. lang:formatNum(mValue) .. " "				else mHTML = mHTML .. "shadow" end elseif mValue < data[mName]["silver"] then sortFactor = 2000 barWidth = (mValue - data[mName]["bronze"]) / (data[mName]["silver"] - data[mName]["bronze"]) mHTML = mHTML .. "Bronze" elseif mValue < data[mName]["gold"] then sortFactor = 1000 barWidth = (mValue - data[mName]["silver"]) / (data[mName]["gold"] - data[mName]["silver"]) mHTML = mHTML .. "Silver" else medalClass = "pogo-medal-num pogo-gold" barWidth = -1 mHTML = mHTML .. "Gold" end

if mName == "ultraHero" and mValue < data[mName]["bronze"] then else mHTML = mHTML .. ".png|72px|link=]] " .. lang:formatNum(mValue) .. " "			end

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

mHTML = mHTML .. " "			sortFactor = sortFactor + data[mName]["sort"] mTable[sortFactor] = mHTML end 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