Module:DropsLine2: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
Line 23: Line 23:
-- Function to generate a table row
-- Function to generate a table row
local function generateRow(name, quantity, rarity, price)
local function generateRow(name, quantity, rarity, price)
     local image = "[[File:%s.png|link=]]"
     local image = '[[File:%s|link=%s|alt=%s: %s drops %s with rarity %s%s in quantity %s]]'
     local row = mw.html.create('tr')
     local row = mw.html.create('tr')
         :tag('td'):wikitext(image):done()
         :tag('td'):wikitext(image):done()

Revision as of 12:32, 5 May 2024

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|link=%s|alt=%s: %s drops %s with rarity %s%s in quantity %s]]'
    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