17,101
edits
Falterfire (talk | contribs) (Added an inline option for spell description (so that I can put some data on the monster page about curses more easily)) |
(Re-arrange spell table generation functions & implement getSpellTableFromList()) |
||
Line 562: | Line 562: | ||
end | end | ||
function p._getSpellRow(spell, includeTypeColumn, includeItems, includeDamage) | function p._getSpellHeader(includeTypeColumn, includeItems, includeDamage, includeExperience) | ||
local resultPart = {} | |||
table.insert(resultPart, '{|class="wikitable sortable"\n!colspan="2"| Spell') | |||
if includeTypeColumn then | |||
table.insert(resultPart, 'Spellbook') | |||
end | |||
table.insert(resultPart, 'Requirements') | |||
if includeDamage then | |||
table.insert(resultPart, 'Spell Dmg') | |||
end | |||
table.insert(resultPart, 'style="width:275px"| Description') | |||
if includeExperience then | |||
table.insert(resultPart, 'XP') | |||
end | |||
table.insert(resultPart, 'style="min-width:90px"| Runes') | |||
if includeItems then | |||
table.insert(resultPart, 'Item Cost') | |||
end | |||
return table.concat(resultPart, '\n! ') | |||
end | |||
function p._getSpellRow(spell, includeTypeColumn, includeItems, includeDamage, includeExperience) | |||
local spellBookIdx = p.spellBookIndex[spell.spellBook] | local spellBookIdx = p.spellBookIndex[spell.spellBook] | ||
local spellBook = p.spellBooks[spellBookIdx] | local spellBook = p.spellBooks[spellBookIdx] | ||
local rowPart = {' | local rowPart = {'\n|-\n|data-sort-value="' .. spell.name .. '"| '} | ||
table.insert(rowPart, Icons.Icon({spell.name, type=spellBook.imgType, notext=true, size=50})) | table.insert(rowPart, Icons.Icon({spell.name, type=spellBook.imgType, notext=true, size=50})) | ||
table.insert(rowPart, '|| ' .. Icons.getExpansionIcon(spell.id) .. Icons.Icon({spell.name, type=spellBook.imgType, noicon=true})) | table.insert(rowPart, '|| ' .. Icons.getExpansionIcon(spell.id) .. Icons.Icon({spell.name, type=spellBook.imgType, noicon=true})) | ||
if includeTypeColumn then | if includeTypeColumn then | ||
table.insert(rowPart, '||data-sort-value="' .. spellBookIdx .. '"| ' .. p.getSpellTypeLink(spell.spellBook)) | table.insert(rowPart, '||data-sort-value="' .. spellBookIdx .. '"| ' .. p.getSpellTypeLink(spell.spellBook)) | ||
end | end | ||
table.insert(rowPart, '||data-sort-value="' .. spell.level .. '"| ' .. p._getSpellRequirements(spell)) | |||
--11/01/22: Added base damage if requested | --11/01/22: Added base damage if requested | ||
if includeDamage then | if includeDamage then | ||
table.insert(rowPart, '||style="text-align:right"|'.. | local dmg = p._getSpellStat(spell, 'spellDamage') | ||
table.insert(rowPart, (dmg > 0 and '||style="text-align:right"| ' .. dmg or '||class="table-na"| N/A')) | |||
end | end | ||
Line 594: | Line 616: | ||
end | end | ||
end | end | ||
if spell. | if includeExperience then | ||
table.insert(rowPart, '|| ' .. | local xp = spell.baseExperience | ||
table.insert(rowPart, ((xp == nil or xp == 0) and '||class="table-na"| N/A' or '||style="text-align:right"| ' .. xp)) | |||
end | end | ||
table.insert(rowPart, '||style="text-align:center"| ' .. p._getSpellRunes(spell)) | table.insert(rowPart, '||style="text-align:center"| ' .. p._getSpellRunes(spell)) | ||
Line 604: | Line 627: | ||
end | end | ||
function p. | function p._getSpellTable(spellList, includeTypeColumn) | ||
if type(spellList) == 'table' and not Shared.tableIsEmpty(spellList) then | |||
local includeSpellbook, includeItems, includeDamage, includeExperience = false, false, false, false | |||
if type(includeTypeColumn) == 'boolean' then | |||
includeSpellbook = includeTypeColumn | |||
end | |||
for i, spell in ipairs( | -- Check to see what columns are required | ||
if p._getSpellItems(spell) ~= '' then | for i, spell in ipairs(spellList) do | ||
if not includeItems and p._getSpellItems(spell) ~= '' then | |||
includeItems = true | |||
end | |||
if not includeExperience and spell.spellBook == 'altMagic' then | |||
includeExperience = true | |||
end | |||
if not includeDamage and (spell.spellBook == 'archaic' or spell.spellBook == 'standard') then | |||
includeDamage = true | |||
end | end | ||
end | end | ||
local resultPart = {p._getSpellHeader(includeSpellbook, includeItems, includeDamage, includeExperience)} | |||
for i, spell in ipairs(spellList) do | |||
table.insert(resultPart, p._getSpellRow(spell, includeSpellbook, includeItems, includeDamage, includeExperience)) | |||
end | |||
table.insert(resultPart, '\n|}') | |||
return table.concat(resultPart) | return table.concat(resultPart) | ||
end | |||
end | |||
function p.getSpellTableFromList(frame) | |||
local args = frame.args ~= nil and frame.args or frame | |||
local spellListText = args[1] | |||
local includeSpellbook = args.includeSpellbook ~= nil and string.lower(args.includeSpellbook) == 'true' | |||
local spellNames = Shared.splitString(spellListText, ',') | |||
local spellList = {} | |||
for i, spellName in ipairs(spellNames) do | |||
local spell = p.getSpell(spellName) | |||
if spell == nil then | |||
return 'ERROR: Unknown spell "' .. spellName .. '"[[Category:Pages with script errors]]' | |||
else | |||
table.insert(spellList, spell) | |||
end | |||
end | |||
return p._getSpellTable(spellList, includeSpellbook) | |||
end | end | ||
Line 647: | Line 676: | ||
local spellBook = frame.args ~= nil and frame.args[1] or frame[1] | local spellBook = frame.args ~= nil and frame.args[1] or frame[1] | ||
spellBook = p.getSpellBookID(spellBook) | spellBook = p.getSpellBookID(spellBook) | ||
return p. | return p._getSpellTable(p.getSpellsBySpellBook(spellBook), false) | ||
end | end | ||
-- Included below for backwards compatibility | -- Included below for backwards compatibility | ||
function p.getStandardSpellsTable(frame) | function p.getStandardSpellsTable(frame) | ||
return p. | return p._getSpellTable(p.getSpellsBySpellBook('standard'), false) | ||
end | end | ||
function p.getAncientTable(frame) | function p.getAncientTable(frame) | ||
return p. | return p._getSpellTable(p.getSpellsBySpellBook('ancient'), false) | ||
end | end | ||
function p.getCurseTable(frame) | function p.getCurseTable(frame) | ||
return p. | return p._getSpellTable(p.getSpellsBySpellBook('curse'), false) | ||
end | end | ||
function p.getAuroraTable(frame) | function p.getAuroraTable(frame) | ||
return p. | return p._getSpellTable(p.getSpellsBySpellBook('aurora'), false) | ||
end | end | ||
function p.getAltSpellsTable(frame) | function p.getAltSpellsTable(frame) | ||
return p. | return p._getSpellTable(p.getSpellsBySpellBook('altMagic'), false) | ||
end | end | ||
return p | return p |