Anonymous

Module:Items/UseTables: Difference between revisions

From Melvor Idle
_getItemUseTable: Avoid repeated string concatenation
(_getItemUses: Only iterate over slayer areas for equipment)
(_getItemUseTable: Avoid repeated string concatenation)
Line 483: Line 483:


   local spellUseTable = p._getSpellUseTable(item)
   local spellUseTable = p._getSpellUseTable(item)
   local result = ''
   local resultPart = {}
   if Shared.tableCount(useArray) == 0 and Shared.tableCount(obstacles) == 0 then
   if Shared.tableCount(useArray) == 0 and Shared.tableCount(obstacles) == 0 then
     if string.len(spellUseTable) > 0 then
     if string.len(spellUseTable) > 0 then
Line 491: Line 491:
     end
     end
   end
   end
   result = result..'{| class="wikitable sortable"'
   table.insert(resultPart, '{| class="wikitable sortable"')
   result = result..'\r\n!colspan=2|Item Created!!Type!!Requirements!!XP!!Ingredients'
   table.insert(resultPart, '\r\n!colspan=2|Item Created!!Type!!Requirements!!XP!!Ingredients')
   for i, row in pairs(useArray) do
   for i, row in pairs(useArray) do
     local qty = row.qty ~= nil and row.qty or 1
     local qty = row.qty ~= nil and row.qty or 1
     local iconType = row.type ~= nil and row.type or 'item'
     local iconType = row.type ~= nil and row.type or 'item'
     result = result..'\r\n|-\r\n|data-sort-value="'..row.item.name..'"|'
     table.insert(resultPart, '\r\n|-\r\n|data-sort-value="'..row.item.name..'"|')
     result = result..Icons.Icon({row.item.name, type=iconType, notext=true, size=50})..'||'
     table.insert(resultPart, Icons.Icon({row.item.name, type=iconType, notext=true, size=50})..'||')
     if qty > 1 then result = result.."'''"..qty.."x''' " end
     if qty > 1 then table.insert(resultPart, "'''"..qty.."x''' ") end
     result = result..'[['..row.item.name..']]'
     table.insert(resultPart, '[['..row.item.name..']]')
     if row.skill == 'Upgrade' then
     if row.skill == 'Upgrade' then
       result = result..'||data-sort-value="Upgrade"|[[Upgrading Items|Upgrade]]'
       table.insert(resultPart, '||data-sort-value="Upgrade"|[[Upgrading Items|Upgrade]]')
     elseif row.skill == 'Shop' then
     elseif row.skill == 'Shop' then
       result = result..'||data-sort-value="Shop"|'..Icons.Icon({'Shop'})
       table.insert(resultPart, '||data-sort-value="Shop"|'..Icons.Icon({'Shop'}))
     else
     else
       result = result..'||data-sort-value="'..row.skill..'"|'..Icons.Icon({row.skill, type='skill'})
       table.insert(resultPart, '||data-sort-value="'..row.skill..'"|'..Icons.Icon({row.skill, type='skill'}))
     end
     end
     if type(row.req) == 'number' then
     if type(row.req) == 'number' then
       result = result..'|| data-sort-value="'..row.req..'"|'..Icons._SkillReq(row.skill, row.req)
       table.insert(resultPart, '|| data-sort-value="'..row.req..'"|'..Icons._SkillReq(row.skill, row.req))
     elseif row.reqVal ~= nil then
     elseif row.reqVal ~= nil then
       result = result..'|| data-sort-value="'..row.reqVal..'"|'..row.req
       table.insert(resultPart, '|| data-sort-value="'..row.reqVal..'"|'..row.req)
     else
     else
       result = result..'||'..row.req
       table.insert(resultPart, '||'..row.req)
     end
     end
     if type(row.xp) == 'string' then
     if type(row.xp) == 'string' then
       result = result..'||data-sort-value="0"|'..row.xp
       table.insert(resultPart, '||data-sort-value="0"|'..row.xp)
     else
     else
       result = result..'||data-sort-value="'..row.xp..'"|'..row.xp..' '..Icons.Icon({row.skill, type='skill', notext=true})..' XP'
       table.insert(resultPart, '||data-sort-value="'..row.xp..'"|'..row.xp..' '..Icons.Icon({row.skill, type='skill', notext=true})..' XP')
     end
     end
     result = result..'||'
     table.insert(resultPart, '||')
     for i, mat in Shared.skpairs(row.mats) do
     for i, mat in Shared.skpairs(row.mats) do
       local matID = mat.id ~= nil and mat.id or mat[1]
       local matID = mat.id ~= nil and mat.id or mat[1]
Line 525: Line 525:
       local matText = ''
       local matText = ''


       if i > 1 then result = result..'<br/>' end
       if i > 1 then table.insert(resultPart, '<br/>') end
       if matID >= 0 then
       if matID >= 0 then
         -- Item
         -- Item
Line 543: Line 543:
         matText = 'ERROR: Unknown item ID: ' .. matID .. ' [[Category:Pages with Script Errors]]'
         matText = 'ERROR: Unknown item ID: ' .. matID .. ' [[Category:Pages with Script Errors]]'
       end
       end
       result = result .. matText
       table.insert(resultPart, matText)
     end
     end
     if row.gp ~= nil then result = result..'<br/>'..Icons.GP(row.gp) end
     if row.gp ~= nil then table.insert(resultPart, '<br/>'..Icons.GP(row.gp)) end
   end
   end


   --Agility obstacles are weird and get their own section
   --Agility obstacles are weird and get their own section
   for i, obst in Shared.skpairs(obstacles) do
   for i, obst in Shared.skpairs(obstacles) do
     result = result..'\r\n|-\r\n|'
     table.insert(resultPart, '\r\n|-\r\n|')
     result = result..Icons.Icon({"Agility", type="skill", size="50", notext=true})
     table.insert(resultPart, Icons.Icon({"Agility", type="skill", size="50", notext=true}))
     result = result..'||[[Agility#Obstacles|'..obst.name..']]'
     table.insert(resultPart, '||[[Agility#Obstacles|'..obst.name..']]')
     result = result..'||'..Icons.Icon({"Agility", type="skill"})
     table.insert(resultPart, '||'..Icons.Icon({"Agility", type="skill"}))


     --Adding the requirements for the Agility Obstacle
     --Adding the requirements for the Agility Obstacle
Line 568: Line 568:
       end
       end
     end
     end
     result = result..'||'..table.concat(reqArray, '<br/>')
     table.insert(resultPart, '||'..table.concat(reqArray, '<br/>'))


     --Just including 'N/A' for XP since it doesn't really apply for Agility Obstacles
     --Just including 'N/A' for XP since it doesn't really apply for Agility Obstacles
     result = result..'||N/A'
     table.insert(resultPart, '||N/A')


     --Finally the cost
     --Finally the cost
Line 587: Line 587:
     end
     end


     result = result..'||'..table.concat(costArray, '<br/>')
     table.insert(resultPart, '||'..table.concat(costArray, '<br/>'))


   end
   end


   result = result..'\r\n|}'
   table.insert(resultPart, '\r\n|}')
   if string.len(spellUseTable) > 0 then
   if string.len(spellUseTable) > 0 then
     result = result..'\r\n==='..Icons.Icon({'Magic', type='skill', size='30'})..'===\r\n'..spellUseTable
     table.insert(resultPart, '\r\n==='..Icons.Icon({'Magic', type='skill', size='30'})..'===\r\n'..spellUseTable)
   end
   end
   return '==Uses==\r\n'..result
   return '==Uses==\r\n'..table.concat(resultPart)
end
end