Module:DropsLine2

From Roat Pkz
Revision as of 12:32, 5 May 2024 by Hefner (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:DropsLine2/doc

local p = {}

-- Function to format numbers with commas
local function commas(n)
    if tonumber(n) then
        return tostring(math.floor(tonumber(n)))
    else
        return n
    end
end

-- Function to handle quantity
local function qty(quantity)
    if quantity == "unknown" or not quantity then
        return "Unknown"
    elseif quantity == "varies" then
        return "Varies"
    else
        return commas(quantity)
    end
end

-- Function to generate a table row
local function generateRow(name, quantity, rarity, price)
    local image = "[[File:%s.png|link=]]"
    local row = mw.html.create('tr')
        :tag('td'):wikitext(image):done()
        :tag('td'):wikitext(name):done()
        :tag('td'):wikitext(qty(quantity)):done()
        :tag('td'):wikitext(rarity):done()
        :tag('td'):wikitext(commas(price)):done()
    return tostring(row)
end

-- Main function
function p.main(frame)
    local args = frame.args
    local name = args.name or args.Name or "Item"
    local quantity = args.quantity or args.Quantity or "Unknown"
    local rarity = args.rarity or args.Rarity or "Unknown"
    local price = args.price or args.Price or "Unknown"

    local row = generateRow(name, quantity, rarity, price)
    return row
end

return p