Module:CombatPet

From August Wiki
Jump to navigation Jump to search

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

-- Module:CombatPet
local p = {}

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

    -- Start building the table HTML
    local html = [[
<table class="wikitable sortable align-left-2 align-center-3 align-center-4 align-center-5 jquery-tablesorter" style="text-align:left;">
  <tr>
    <th colspan="2" class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Pet</th>
    <th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Tier</th>
    <th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Attack Speed</th>
    <th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Max Hit</th>
    <th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Source</th>
    <th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Special Effect</th>
  </tr>
]]

    -- Generate rows dynamically
    local index = 1
    while args['pet' .. index] do
        -- Get parameters for this pet
        local pet = args['pet' .. index] or ''
        local image = args['image' .. index] or ''
        local tier = args['tier' .. index] or ''
        local attackspeed = args['attackspeed' .. index] or ''
        local maxhit = args['maxhit' .. index] or ''
        local source = args['source' .. index] or ''
        local specialeffect = args['specialeffect' .. index] or ''
        
        -- Skip empty entries
        if pet ~= '' then
            -- Build the row HTML
            html = html .. '  <tr>\n'
            
            -- Image cell
            html = html .. '    <td class="plinkt-image">'
            if image ~= '' then
                html = html .. '[[File:' .. image .. '|center|32px]]'
            end
            html = html .. '</td>\n'
            
            -- Pet name cell
            html = html .. '    <td>' .. pet .. '</td>\n'
            
            -- Tier cell
            html = html .. '    <td>' .. tier .. '</td>\n'
            
            -- Attack Speed cell
            html = html .. '    <td>' .. attackspeed .. '</td>\n'
            
            -- Max Hit cell
            html = html .. '    <td>' .. maxhit .. '</td>\n'
            
            -- Source cell
            html = html .. '    <td class="plinkt-link>[[' .. source .. ']]</td>\n'
            
            -- Special Effect cell
            html = html .. '    <td>' .. specialeffect .. '</td>\n'
            
            html = html .. '  </tr>\n'
        end
        
        -- 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