Module:DropSource: Difference between revisions

From August Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 7: Line 7:
     Uncommon = { 'table-bg-yellow', 64 },
     Uncommon = { 'table-bg-yellow', 64 },
     Rare = { 'table-bg-orange', 256 },
     Rare = { 'table-bg-orange', 256 },
    ['Very rare'] = { 'table-bg-red', 1024 },
     ['Extremely rare'] = { 'table-bg-red', 1024 },
     ['Extremely rare'] = { 'table-bg-red', 1024 },
}
}

Latest revision as of 12:49, 3 March 2025

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

-- Module:DropSource
local p = {}

local rarityStyles = {
    Always = { 'table-bg-blue', 1 },
    Common = { 'table-bg-green', 16 },
    Uncommon = { 'table-bg-yellow', 64 },
    Rare = { 'table-bg-orange', 256 },
    ['Very rare'] = { 'table-bg-red', 1024 },
    ['Extremely rare'] = { 'table-bg-red', 1024 },
}

-- Main function to generate the item source table
function p.main(frame)
    local args = frame.args

    -- Start building the table HTML
    local html = [[
<table class="wikitable sortable filterable item-drops align-center-2 align-center-3 align-center-4 autosort=3,a jquery-tablesorter rsw-dropsline-hidealch">
    <tr>
        <th class="drop-disp-btn btn-first headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Source</th>
        <th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Level</th>
        <th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Quantity</th>
        <th class="drops-rarity-header headerSort headerSortUp" tabindex="0" role="columnheader button" title="Sort ascending">Rarity</th>
    </tr>
]]

    -- Generate rows dynamically
    local index = 1
    while args['source' .. index] do
        local source = args['source' .. index]
        local level = args['source' .. index .. 'Lvl'] or ''
        local rarity = args['rarity' .. index] or ''

        -- Check for source-specific quantity first, then fall back to global quantity
        local quantity = args['source' .. index .. 'Quant'] or args['itemQuant'] or ''

        local rarityClass = ''
        local raritySort = '' -- Initialize raritySort
        local levelClass = '' -- Initialize levelClass

        if rarityStyles[rarity] then
            rarityClass = rarityStyles[rarity][1]
            raritySort = rarityStyles[rarity][2]
        else
            -- Handle cases where rarity is not found
            rarityClass = 'table-bg-gray' -- Optional: Assign a default class
            raritySort = 0 -- Optional: Assign a default sort value
        end

        -- Check for "N/A" level
        if level:upper() == 'N/A' then
            levelClass = 'table-na'
        end

        -- Build the row HTML
        html = html .. '    <tr>\n'
        html = html .. '        <td>[[' .. source .. ']]</td>\n'

        -- Level cell with optional combat icon
        html = html .. '        <td class="' .. levelClass .. '" data-sort-value="'.. level ..'">' .. level
        if level and level ~= '' and level:upper() ~= 'N/A' then
            html = html .. ' [[File:Multicombat.png]]'
        elseif level:upper() == 'N/A' then
            html = html .. ' [[File:Casket_(easy).png|20px]]'
        end
        html = html .. '</td>\n'

        -- Quantity cell
        html = html .. '        <td data-sort-value="' .. quantity .. '">' .. quantity .. '</td>\n'

        -- Rarity cell
        html = html .. '        <td data-sort-value="' .. raritySort ..  '" class="' .. rarityClass.. '">' .. rarity ..  '</td>\n'
        html = html .. '    </tr>\n'

        -- Move to next index
        index = index + 1
    end

    -- Close the table
    html = html .. '</table>'

    return html
end

-- Function to render HTML from template-style parameters
function p.render(frame)
    -- Get all arguments from parent template
    local parentArgs = frame:getParent().args
    return p.main({args = parentArgs})
end

return p