Module:EncounterTable: Difference between revisions

change data namespace to Population
mNo edit summary
(change data namespace to Population)
 
(6 intermediate revisions by 2 users not shown)
Line 69: Line 69:
             end
             end


             finalTable[i].item = 'Item from [[Data:' .. linkstr  .. '|' .. row.table .. ']]'
             finalTable[i].item = 'Item from [[Population:' .. linkstr  .. '|' .. row.table .. ']]'
         else
         else
             error'A table and item cannot be specified at the same time!'
             error'A table and item cannot be specified at the same time!'
Line 95: Line 95:
     end
     end


     return EncounterTable.formatTable(finalTable)
     return EncounterTable.formatTable(finalTable, bHideQuantity)
end
end


function EncounterTable.formatTable(final)
function EncounterTable.formatTable(final, bHideQuantity)
     local TABLE_HEADER = '<tr><th>Item</th><th>Quantity</th><th>Weight</th><th>Chance</th></tr>'
     local TABLE_HEADER = bHideQuantity and
'<tr><th>Item</th><th>Weight</th><th>Chance</th></tr>' or
'<tr><th>Item</th><th>Quantity</th><th>Weight</th><th>Chance</th></tr>'
     local tableRows = ''
     local tableRows = ''
     local headerhtml = ''
     local headerhtml = ''
    if bHideQuantity then
 
        headerhtml = '<tr><td>%s</td><td>%s</td><td>%s</td></tr>'
    else
        headerhtml = '<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>'
    end
     for _, entry in ipairs(final) do
     for _, entry in ipairs(final) do
           if bHideQuantity then
           if bHideQuantity then
               tableRows = tableRows .. headerhtml:format(entry.item, entry.weight, entry.chance)
               tableRows = tableRows .. ('<tr><td>%s</td><td>%s</td><td>%s</td></tr>'):format(entry.item, entry.weight, entry.chance)
           else
           else
               tableRows = tableRows .. headerhtml:format(entry.item, entry.quantity, entry.weight, entry.chance)
               tableRows = tableRows .. ('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>'):format(entry.item, entry.quantity, entry.weight, entry.chance)
           end
           end
     end
     end