Anonymous

Module:Magic: Difference between revisions

From Melvor Idle
Added spell item cost to the spellbook table
(Added a getSpellItems function)
(Added spell item cost to the spellbook table)
Line 535: Line 535:
end
end


function p._getSpellRow(spell, includeTypeColumn)
function p._getSpellRow(spell, includeTypeColumn, includeItems)
     local spellBookIdx = p.spellBookIndex[spell.spellBook]
     local spellBookIdx = p.spellBookIndex[spell.spellBook]
     local spellBook = p.spellBooks[spellBookIdx]
     local spellBook = p.spellBooks[spellBookIdx]
Line 566: Line 566:
end
end
table.insert(rowPart, '||style="text-align:center"| ' .. p._getSpellRunes(spell))
table.insert(rowPart, '||style="text-align:center"| ' .. p._getSpellRunes(spell))
if includeItems then
table.insert(rowPart, '||style="text-align:center"| ' .. p._getSpellItems(spell))
end
return table.concat(rowPart)
return table.concat(rowPart)
end
end
Line 571: Line 574:
function p._getSpellBookTable(spellBookID)
function p._getSpellBookTable(spellBookID)
     local spells = p.getSpellsBySpellBook(spellBookID)
     local spells = p.getSpellsBySpellBook(spellBookID)
   
     if spells ~= nil and not Shared.tableIsEmpty(spells) then
     if spells ~= nil and not Shared.tableIsEmpty(spells) then
    -- Check to see if we need the items column
local hasItems = false
for i, spell in ipairs(spells) do
if p._getSpellItems(spell) ~= '' then
hasItems = true
break
end
end
   
         local resultPart = {}
         local resultPart = {}
         table.insert(resultPart, '{|class="wikitable sortable"\r\n!colspan="2"| Spell')
         table.insert(resultPart, '{|class="wikitable sortable"\r\n!colspan="2"| Spell')
Line 580: Line 593:
         end
         end
         table.insert(resultPart, '\r\n! Runes')
         table.insert(resultPart, '\r\n! Runes')
        if hasItems then
        table.insert(resultPart, '\r\n! Item Cost')
        end


         for i, spell in ipairs(spells) do
         for i, spell in ipairs(spells) do
             table.insert(resultPart, p._getSpellRow(spell, false))
             table.insert(resultPart, p._getSpellRow(spell, false, hasItems))
         end
         end