Module:SkillResources: Difference between revisions

From August Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- Module:SkillResources
-- Module:SkillResources
local p = {}
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(s)
-- Main function to generate the item source table
function p.main(frame)
function p.main(frame)
     local args = frame.args
     local args = frame.args
     local html = ""
 
     local tableCount = tonumber(args['tableCount'] or '1')
    -- Check if any items have materials
     local hasMaterials = false
     local index = 1
    while args['item' .. index] do
        for i = 1, 7 do
            if (args['material' .. i .. '_' .. index] or '') ~= '' then
                hasMaterials = true
                break
            end
        end
        if hasMaterials then break end
        index = index + 1
    end
      
      
     -- Process each table
     -- Start building the table HTML
    for t = 1, tableCount do
    local html = [[
        -- Start building the table HTML
        html = 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">
<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>
   <tr>
     <th class="drop-disp-btn btn-first headerSort" tabindex="0" role="columnheader button" title="Sort ascending" colspan="5">Item</th>
     <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">Level</th>
    <th class="drops-rarity-header headerSort headerSortUp" tabindex="0" role="columnheader button" title="Sort ascending">Materials</th>
  </tr>
]]
]]
         -- Table title if provided
   
        local tableTitle = args['tableTitle' .. t]
    -- Add Requirements header only if materials exist
        if tableTitle and tableTitle ~= '' then
    if hasMaterials then
            html = html .. '  <tr><th colspan="7">' .. tableTitle .. '</th></tr>\n'
         html = html .. [[    <th class="drops-rarity-header headerSort headerSortUp" tabindex="0" role="columnheader button" title="Sort ascending">Requirements</th>
]]
    end
   
    html = html .. [[  </tr>
]]
    -- Table title if provided
    local tableTitle = args['tableTitle']
    if tableTitle and tableTitle ~= '' then
        local colspan = hasMaterials and "7" or "6"
        html = html .. '  <tr><th colspan="' .. colspan .. '">' .. tableTitle .. '</th></tr>\n'
    end
   
    -- 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 skillClass = ''
 
        -- Check for "N/A" level
        if skill:upper() == 'N/A' then
            skillClass = 'table-na'
         end
         end
          
          
         -- Generate rows dynamically for this table
         -- Build the row HTML
         local index = 1
         html = html .. ' <tr>\n'
        while args['item' .. t .. '_' .. index] do
       
            -- Get parameters for this item
        -- Item cell with image and name combined
            local item = args['item' .. t .. '_' .. index] or ''
        if image and image ~= '' then
            local image = args['image' .. t .. '_' .. index] or ''
          html = html .. '<td colspan="1">'
            local level = args['level' .. t .. '_' .. index] or ''
          html = html .. ' [[File:' .. image .. '|center|32px]]'
            local skill = args['skill' .. t .. '_' .. index] or ''
          html = html .. '</td>\n'
            local skillClass = ''
        end
 
        html = html .. '   <td colspan="4">'
            -- Check for "N/A" level
        html = html .. item
            if skill:upper() == 'N/A' then
        html = html .. '</td>\n'
                skillClass = 'table-na'
            end
              
              
            -- Build the row HTML
        -- Level cell with skill information
            html = html .. ' <tr>\n'
        html = html .. '   <td class="plainlist ' .. skillClass ..'" style="text-align:center">\n'
           
        html = html .. '        <ul class="skills-list">\n'
            -- Item cell with image and name combined
        if skill == 'N/A' then
            if image and image ~= '' then
            html = html .. '           <li>N/A</li>\n'
              html = html .. '<td colspan="1">'
        elseif skill ~= '' then
              html = html .. ' [[File:' .. image .. '|center|32px]]'
            html = html .. '           <li>[[File:' .. skill .. '_icon.png|20px]] ' .. level .. '</li>\n'
              html = html .. '</td>\n'
        end
        html = html .. '       </ul>\n'
        html = html .. '    </td>\n'
       
        -- Check if any materials exist for this item
        local hasMaterials = false
        for i = 1, 7 do
            local material = args['material' .. i .. '_' .. index] or ''
            if material ~= '' then
                hasMaterials = true
                break
             end
             end
            html = html .. '    <td colspan="4">'
        end
            html = html .. '[[' .. item .. ']]'
       
            html = html .. '</td>\n'
        -- Materials cell - only add if any materials exist in the table
               
        if hasMaterials then
            -- 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'
           
            -- Materials cell
             html = html .. '    <td data-sort-value="1" class="plainlist">\n'
             html = html .. '    <td data-sort-value="1" class="plainlist">\n'
            html = html .. '        <ul class="products-materials">\n'
              
              
             -- Add materials list (up to 7 materials)
             -- Check if this specific item has materials
            local itemHasMaterials = false
             for i = 1, 7 do
             for i = 1, 7 do
                 local material = args['material' .. i .. '_' .. t .. '_' .. index] or ''
                 if (args['material' .. i .. '_' .. index] or '') ~= '' then
                 local quantity = args['quantity' .. i .. '_' .. t .. '_' .. index] or ''
                    itemHasMaterials = true
                    break
                 end
            end
           
            -- Only add materials list if this item has materials
            if itemHasMaterials then
                html = html .. '       <ul class="products-materials">\n'
                  
                  
                 if material ~= '' and quantity ~= '' then
                 -- Add materials list (up to 7 materials)
                    html = html .. '            <li>' .. quantity .. ' × ' .. material .. '</li>\n'
                for i = 1, 7 do
                    local material = args['material' .. i .. '_' .. index] or ''
                    local quantity = args['quantity' .. i .. '_' .. index] or ''
                   
                    if material ~= '' then
                        local displayText = material
                        if quantity ~= '' then
                            displayText = quantity .. ' × ' .. material
                        end
                        html = html .. '            <li>' .. displayText .. '</li>\n'
                    end
                 end
                 end
               
                html = html .. '        </ul>\n'
             end
             end
              
              
            html = html .. '        </ul>\n'
             html = html .. '    </td>\n'
             html = html .. '    </td>\n'
            html = html .. '  </tr>\n'
           
            -- Move to next index
            index = index + 1
         end
         end
        html = html .. '  </tr>\n'
          
          
         -- Close the table
         -- Move to next index
         html = html .. '</table>\n'
         index = index + 1
        -- Add some spacing between tables if more than one
        if t < tableCount then
            html = html .. '<br/>\n'
        end
     end
     end
      
      
    -- Close the table
    html = html .. '</table>'
     return html
     return html
end
end

Latest revision as of 01:36, 10 March 2025

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

-- Module:SkillResources
local p = {}

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

    -- Check if any items have materials
    local hasMaterials = false
    local index = 1
    while args['item' .. index] do
        for i = 1, 7 do
            if (args['material' .. i .. '_' .. index] or '') ~= '' then
                hasMaterials = true
                break
            end
        end
        if hasMaterials then break end
        index = index + 1
    end
    
    -- 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>
]]
    
    -- Add Requirements header only if materials exist
    if hasMaterials then
        html = html .. [[    <th class="drops-rarity-header headerSort headerSortUp" tabindex="0" role="columnheader button" title="Sort ascending">Requirements</th>
]]
    end
    
    html = html .. [[  </tr>
]]
    -- Table title if provided
    local tableTitle = args['tableTitle']
    if tableTitle and tableTitle ~= '' then
        local colspan = hasMaterials and "7" or "6"
        html = html .. '  <tr><th colspan="' .. colspan .. '">' .. tableTitle .. '</th></tr>\n'
    end
    
    -- 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 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'
        
        -- Check if any materials exist for this item
        local hasMaterials = false
        for i = 1, 7 do
            local material = args['material' .. i .. '_' .. index] or ''
            if material ~= '' then
                hasMaterials = true
                break
            end
        end
        
        -- Materials cell - only add if any materials exist in the table
        if hasMaterials then
            html = html .. '    <td data-sort-value="1" class="plainlist">\n'
            
            -- Check if this specific item has materials
            local itemHasMaterials = false
            for i = 1, 7 do
                if (args['material' .. i .. '_' .. index] or '') ~= '' then
                    itemHasMaterials = true
                    break
                end
            end
            
            -- Only add materials list if this item has materials
            if itemHasMaterials then
                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 ~= '' then
                        local displayText = material
                        if quantity ~= '' then
                            displayText = quantity .. ' × ' .. material
                        end
                        html = html .. '            <li>' .. displayText .. '</li>\n'
                    end
                end
                
                html = html .. '        </ul>\n'
            end
            
            html = html .. '    </td>\n'
        end
        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