Module:Shop: Difference between revisions

getShopSkillcapeTable: Rework to generate from shop data
(getAutoEatTable: Initial implementation; getPurchases: Pass category to check function)
(getShopSkillcapeTable: Rework to generate from shop data)
Line 260: Line 260:


function p.getShopSkillcapeTable()
function p.getShopSkillcapeTable()
   local result = ''
   local resultPart = {}
   local capeList = Items.getItems(function(item) return Shared.contains(item.name, 'Skillcape') or item.name == 'Cape of Completion' end)
   local capeList = p.getPurchases(function(cat, purch) return cat == 'Skillcapes' end)


   result = result..'\r\n{|class="wikitable sortable stickyHeader"'
   table.insert(resultPart, '{|class="wikitable sortable stickyHeader"')
   result = result..'\r\n|- class="headerRow-0"'
   table.insert(resultPart, '|- class="headerRow-0"')
   result = result..'\r\n!colspan="2" style="width:200px"|Cape'
   table.insert(resultPart, '!colspan="2" style="width:200px"|Cape!!Description!!style="width:120px"|Price')
  result = result..'!!Description!!style="width:120px"|Price'


   --Sort the table by cost and then name
   --Sort the table by cost and then name
   table.sort(capeList, function(a, b)  
   table.sort(capeList, function(a, b)  
                         if a.buysFor == b.buysFor then
                         if a.cost.gp == b.cost.gp then
                           return a.name < b.name
                           return a.name < b.name
                         else
                         else
                           return a.sellsFor < b.buysFor
                           return a.cost.gp < b.cost.gp
                         end
                         end
                       end)
                       end)
   for i, thisItem in pairs(capeList) do
   for i, thisItem in ipairs(capeList) do
     result = result..'\r\n|-\r\n|style="min-width:25px"|'..Icons.Icon({thisItem.name, type='item', size='50', notext=true})
     local sortValue = p._getPurchaseSortValue(thisItem)
     result = result..'||[['..thisItem.name..']]'
    table.insert(resultPart, '|-\r\n|style="min-width:25px; text-align:center;"| ' .. Icons.Icon({thisItem.name, type='item', size=50, notext=true}))
     result = result..'\r\n||'..thisItem.description
     table.insert(resultPart, '| [[' .. thisItem.name .. ']]')
     result = result..'||style="text-align:left" data-sort-value="'..thisItem.buysFor..'"'
     table.insert(resultPart, '| ' .. thisItem.description)
    result = result..'|'..Icons.GP(thisItem.buysFor)
     table.insert(resultPart, '|style="text-align:right;" data-sort-value="' .. sortValue .. '"| ' .. p.getCostString(thisItem.cost))
   end
   end
   result = result..'\r\n|}'
   table.insert(resultPart, '|}')


   return result
   return table.concat(resultPart, '\r\n')
end
end