Module:DropSource: Difference between revisions

From August Wiki
Jump to navigation Jump to search
Created page with "-- 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 }, } -- 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-dr..."
 
No edit summary
Line 17: Line 17:
     local 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">
<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>
    <tr>
    <th class="drop-disp-btn btn-first headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Source</th>
        <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">Level</th>
    <th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Quantity</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>
        <th class="drops-rarity-header headerSort headerSortUp" tabindex="0" role="columnheader button" title="Sort ascending">Rarity</th>
  </tr>
    </tr>
]]
]]


Line 36: Line 36:


         local rarityClass = ''
         local rarityClass = ''
        local raritySort = '' -- Initialize raritySort
         if rarityStyles[rarity] then
         if rarityStyles[rarity] then
             rarityClass = rarityStyles[rarity][1]
             rarityClass = rarityStyles[rarity][1]
             raritySort = rarityStyles[rarity][2]
             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
         end


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


         -- Level cell with optional combat icon
         -- Level cell with optional combat icon
         html = html .. '   <td class="" data-sort-value="'.. level ..'">' .. level
         html = html .. '       <td class="" data-sort-value="'.. level ..'">' .. level
         if level and level ~= '' then
         if level and level ~= '' then
             html = html .. ' [[File:Multicombat.png]]'
             html = html .. ' [[File:Multicombat.png]]'
Line 53: Line 59:


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


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


         -- Move to next index
         -- Move to next index

Revision as of 06:36, 28 February 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 },
}

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

        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

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

        -- Level cell with optional combat icon
        html = html .. '        <td class="" data-sort-value="'.. level ..'">' .. level
        if level and level ~= '' then
            html = html .. ' [[File:Multicombat.png]]'
        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