8,756
edits
(add favilink support?) |
(change data namespace to Population) |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
--# Interface | --# Interface | ||
function EncounterTable.splitEncounterTableArgs(row) | function EncounterTable.splitEncounterTableArgs(row, hideQuantity) | ||
local TABLE_ARGS = {'table', 'item', 'quantity', 'weight'} | local TABLE_ARGS = {} | ||
if hideQuantity then | |||
TABLE_ARGS = {'table', 'item', 'weight'} | |||
else | |||
TABLE_ARGS = {'table', 'item', 'quantity', 'weight'} | |||
end | |||
return TextUtility.splitArgs(row, TABLE_ARGS) | return TextUtility.splitArgs(row, TABLE_ARGS) | ||
end | end | ||
Line 21: | Line 26: | ||
local pick = args.roll or 'once' | local pick = args.roll or 'once' | ||
local bFavilinkId = false | local bFavilinkId = false | ||
local bHideQuantity = (args.hidequantity ~= nil) | |||
if args.favilinkid == 'yes' then bFavilinkId = true end | if args.favilinkid == 'yes' then bFavilinkId = true end | ||
local bSamePageLink = false | local bSamePageLink = false | ||
Line 63: | Line 69: | ||
end | end | ||
finalTable[i].item = 'Item from [[ | 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 69: | Line 75: | ||
-- dice tooltip quantity | -- dice tooltip quantity | ||
if not bHideQuantity then | |||
finalTable[i].quantity = frame:expandTemplate{ | |||
title = 'Dice tooltip', | |||
args = {row.quantity}, | |||
} | |||
end | |||
--finalTable[i].quantity = row.quantity | --finalTable[i].quantity = row.quantity | ||
finalTable[i].weight = row.weight | finalTable[i].weight = row.weight | ||
Line 89: | 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 = '' | |||
for _, entry in ipairs(final) do | for _, entry in ipairs(final) do | ||
if bHideQuantity then | |||
tableRows = tableRows .. ('<tr><td>%s</td><td>%s</td><td>%s</td></tr>'):format(entry.item, entry.weight, entry.chance) | |||
else | |||
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 | ||