Module:Items: Difference between revisions

Added the 'asList' argument to getItemSources
(Added ability to force number formatting on getItemStat)
(Added the 'asList' argument to getItemSources)
Line 103: Line 103:
   local StatName = args[2]
   local StatName = args[2]
   local ZeroIfNil = args.ForceZero ~= nil and args.ForceZero ~= '' and args.ForceZero ~= 'false'
   local ZeroIfNil = args.ForceZero ~= nil and args.ForceZero ~= '' and args.ForceZero ~= 'false'
   local FormatNum = args.FormatNum ~= nil and args.FormatNum ~= '' and args.FormatNum ~= 'false'
   local formatNum = args.formatNum ~= nil and args.formatNum ~= '' and args.formatNum ~= 'false'
   local item = p.getItem(ItemName)
   local item = p.getItem(ItemName)
   if item == nil then
   if item == nil then
Line 109: Line 109:
   end
   end
   local result = p._getItemStat(item, StatName, ZeroIfNil)
   local result = p._getItemStat(item, StatName, ZeroIfNil)
   if FormatNum then result = Shared.formatnum(result) end
   if formatNum then result = Shared.formatnum(result) end
   return result
   return result
end
end
Line 334: Line 334:
end
end


function p._getItemSources(item)
function p._getItemSources(item, asList)
   local result = nil
   local result = nil
   local lineArray = {}
   local lineArray = {}
Line 547: Line 547:
   end
   end


   local result = table.concat(lineArray, "<br/>")
   local result = ''
  result = '<div style="max-width:180px;text-align:right">'..result..'</div>'
  if asList then
    result = '* '..table.concat(lineArray, "\r\n* ")
  else
    result = table.concat(lineArray, "<br/>")
    result = '<div style="max-width:180px;text-align:right">'..result..'</div>'
  end
   return result
   return result
end
end
Line 556: Line 561:
   local itemName = frame.args ~= nil and frame.args[1] or frame
   local itemName = frame.args ~= nil and frame.args[1] or frame
   local item = p.getItem(itemName)
   local item = p.getItem(itemName)
  local asList = false
  if frame.args ~= nil then
    asList = frame.args.asList ~= nil and frame.args.asList ~= '' and frame.args.asList ~= 'false'
  end
   if item == nil then
   if item == nil then
     return "ERROR: No item named "..itemName.." exists in the data module"
     return "ERROR: No item named "..itemName.." exists in the data module"
   end
   end


   return p._getItemSources(item)
   return p._getItemSources(item, asList)
end
end