Module:Magic: Difference between revisions

1,406 bytes added ,  11 November 2022
Re-arrange spell table generation functions & implement getSpellTableFromList()
(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 = {'\r\n|-\r\n|data-sort-value="' .. spell.name .. '"| '}
     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}))
table.insert(rowPart, '||data-sort-value="' .. spell.level .. '"| ' .. p._getSpellRequirements(spell))
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"|'..p._getSpellStat(spell, 'spellDamage'))
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.spellBook == 'altMagic' then
if includeExperience then
table.insert(rowPart, '|| ' .. spell.baseExperience)
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._getSpellBookTable(spellBookID)
function p._getSpellTable(spellList, includeTypeColumn)
    local spells = p.getSpellsBySpellBook(spellBookID)
if type(spellList) == 'table' and not Shared.tableIsEmpty(spellList) then
   
local includeSpellbook, includeItems, includeDamage, includeExperience = false, false, false, false
    if spells ~= nil and not Shared.tableIsEmpty(spells) then
if type(includeTypeColumn) == 'boolean' then
    -- Check to see if we need the items column
includeSpellbook = includeTypeColumn
local hasItems = false
end
for i, spell in ipairs(spells) do
-- Check to see what columns are required
if p._getSpellItems(spell) ~= '' then
for i, spell in ipairs(spellList) do
hasItems = true
if not includeItems and p._getSpellItems(spell) ~= '' then
break
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
-- Check to see if we want to show damage
local showDamage = spellBookID == 'archaic' or spellBookID == 'standard'
   
        local resultPart = {}
        table.insert(resultPart, '{|class="wikitable sortable"\r\n!colspan="2"| Spell')
        table.insert(resultPart, '\r\n! Requirements')
        if showDamage then
        table.insert(resultPart, '\r\n!Spell Dmg')
        end
        table.insert(resultPart, '\r\n!style="width:275px"| Description')
        if spellBookID == 'altMagic' then
            table.insert(resultPart, '\r\n! Experience')
        end
        table.insert(resultPart, '\r\n! Runes')
        if hasItems then
        table.insert(resultPart, '\r\n! Item Cost')
        end


        for i, spell in ipairs(spells) do
local resultPart = {p._getSpellHeader(includeSpellbook, includeItems, includeDamage, includeExperience)}
            table.insert(resultPart, p._getSpellRow(spell, false, hasItems, showDamage))
for i, spell in ipairs(spellList) do
        end
table.insert(resultPart, p._getSpellRow(spell, includeSpellbook, includeItems, includeDamage, includeExperience))
end


        table.insert(resultPart, '\r\n|}')
table.insert(resultPart, '\n|}')
         return table.concat(resultPart)
         return table.concat(resultPart)
    end
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._getSpellBookTable(spellBook)
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._getSpellBookTable('standard')
     return p._getSpellTable(p.getSpellsBySpellBook('standard'), false)
end
end


function p.getAncientTable(frame)
function p.getAncientTable(frame)
     return p._getSpellBookTable('ancient')
     return p._getSpellTable(p.getSpellsBySpellBook('ancient'), false)
end
end


function p.getCurseTable(frame)
function p.getCurseTable(frame)
     return p._getSpellBookTable('curse')
     return p._getSpellTable(p.getSpellsBySpellBook('curse'), false)
end
end


function p.getAuroraTable(frame)
function p.getAuroraTable(frame)
     return p._getSpellBookTable('aurora')
     return p._getSpellTable(p.getSpellsBySpellBook('aurora'), false)
end
end


function p.getAltSpellsTable(frame)
function p.getAltSpellsTable(frame)
     return p._getSpellBookTable('altMagic')
     return p._getSpellTable(p.getSpellsBySpellBook('altMagic'), false)
end
end


return p
return p