Module:ItemRecipe: Difference between revisions

From August Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 80: Line 80:
                     cssClass = ' class="production-selected"'
                     cssClass = ' class="production-selected"'
                 end
                 end
                 html = html .. '            <li' .. cssClass .. '>' .. quantity .. ' × [[' .. material .. ']]</li>\n'
                 html = html .. '            <li' .. cssClass .. '>' .. quantity .. ' × ' .. material .. '</li>\n'
             end
             end
         end
         end

Revision as of 19:50, 2 March 2025

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

-- Module:ItemRecipe
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-left-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" colspan="5">Item</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">Success Chance</th>
    <th class="drops-rarity-header headerSort headerSortUp" tabindex="0" role="columnheader button" title="Sort ascending">Materials</th>
  </tr>
]]
    -- Generate rows dynamically
    local index = 1
    while args['item' .. index] do
        -- Get parameters for this item
        local item = args['item' .. index] or ''
        local image = args['image' .. index] or ''
        local level = args['level' .. index] or ''
        local skill = args['skill' .. index] or ''
        local chance = args['chance' .. index] or ''
        local skillClass = ''

        -- Check for "N/A" level
        if skill:upper() == 'N/A' then
            skillClass = 'table-na'
        end
        
        -- Build the row HTML
        html = html .. '  <tr>\n'
        
        -- Item cell with image and name combined
        if image and image ~= '' then
          html = html .. '<td colspan="1">'
          html = html .. ' [[File:' .. image .. '|center|32px]]'
          html = html .. '</td>\n'
	end
      html = html .. '    <td colspan="4">'
      html = html .. '[[' .. item .. ']]'
      html = html .. '</td>\n'
        
        -- Level cell with skill information
        html = html .. '    <td class="plainlist ' .. skillClass ..'" style="text-align:center">\n'
        html = html .. '        <ul class="skills-list">\n'
        if skill == 'N/A' then
            html = html .. '            <li>N/A</li>\n'
        elseif skill ~= '' then
            html = html .. '            <li>[[File:' .. skill .. '_icon.png|20px]] ' .. level .. '</li>\n'
        end
        html = html .. '        </ul>\n'
        html = html .. '    </td>\n'

        -- Success Chance cell
        html = html .. '    <td data-sort-value="' .. chance .. '">' .. chance .. '</td>\n'
        
        -- Materials cell
        html = html .. '    <td data-sort-value="1" class="plainlist">\n'
        html = html .. '        <ul class="products-materials">\n'
        
        -- Add materials list (up to 7 materials)
        for i = 1, 7 do
            local material = args['material' .. i .. '_' .. index] or ''
            local quantity = args['quantity' .. i .. '_' .. index] or ''
            
            if material ~= '' and quantity ~= '' then
                local cssClass = ''
                if i == 1 then
                    cssClass = ' class="production-selected"'
                end
                html = html .. '            <li' .. cssClass .. '>' .. quantity .. ' × ' .. material .. '</li>\n'
            end
        end
        
        html = html .. '        </ul>\n'
        html = html .. '    </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