Module:Shop: Difference between revisions

423 bytes added ,  14 September 2021
getPurchaseStat: Special handling for 'cost' stat
(getPurchaseContents: Initial implementation)
(getPurchaseStat: Special handling for 'cost' stat)
Line 61: Line 61:
   local statName = args[2]
   local statName = args[2]
   local displayInline = (args['inline'] ~= nil and string.lower(args['inline']) == 'true' or false)
   local displayInline = (args['inline'] ~= nil and string.lower(args['inline']) == 'true' or false)
   local purchase = p.getPurchase(purchaseName)
  -- Hack for some purchases existing twice with varying costs (e.g. 'Extra Equipment Set')
   local purchaseList = {}
  if statName == 'cost' then
    purchaseList = p.getPurchases(function(cat, purch) return purch.name == purchaseName end)
  else
    purchaseList = {p.getPurchase(purchaseName)}
  end


   if purchase == nil then
   if Shared.tableCount(purchaseList) == 0 then
     return "ERROR: Couldn't find purchase with name '" .. purchaseName .. "'[[Category:Pages with script errors]]"
     return "ERROR: Couldn't find purchase with name '" .. purchaseName .. "'[[Category:Pages with script errors]]"
   else
   else
     return p._getPurchaseStat(purchase, statName, displayInline)
     local resultPart = {}
    for i, purchase in ipairs(purchaseList) do
      table.insert(resultPart, p._getPurchaseStat(purchase, statName, displayInline))
    end
    return table.concat(resultPart, ' or ')
   end
   end
end
end