Anonymous

Module:Items/ComparisonTables: Difference between revisions

From Melvor Idle
getTableFromList: Change to use one item per parameter/arg instead of a comma delimited list
(getItemUpgradeTable: Implement parameter 'usedItem', for restricting results to only those using the specified item)
(getTableFromList: Change to use one item per parameter/arg instead of a comma delimited list)
Line 355: Line 355:


function p.getTableForList(frame)
function p.getTableForList(frame)
local stuffString = frame.args ~= nil and frame.args[1] or frame[1]
local frameArgs = frame.args ~= nil and frame.args or frame
local itemNames = Shared.splitString(stuffString, ',')
local includeModifiers = frame.includeModifiers ~= nil and string.upper(frame.includeModifiers) == 'TRUE' or false


local includeModifiers = frame.args ~= nil and frame.args[2] or frame[2]
local itemList, errItems = {}, {}
includeModifiers = includeModifiers ~= nil and string.upper(includeModifiers) == 'TRUE' or false
 
local itemList = {}
local errMsg = 'Some items not found in database: '
local errMsg = 'Some items not found in database: '
local hasErr = false
local hasErr = false
for i, name in Shared.skpairs(itemNames) do
for i, rawItemName in ipairs(frameArgs) do
local nextItem = Items.getItem(Shared.trim(name))
local itemName = Shared.trim(rawItemName)
if nextItem == nil then
local item = Items.getItem(itemName)
errMsg = errMsg.." '"..name.."'"
if item == nil then
hasErr = true
table.insert(errItems, "'" .. itemName .. "'")
else
else
table.insert(itemList, nextItem)
table.insert(itemList, item)
end
end
end
end


if hasErr then
if not Shared.tableIsEmpty(errItems) then
return Shared.printError(errMsg)
return Shared.printError('Some items not found in database: ' .. table.concat(errItems, ', '))
else
else
return p._getEquipmentTable(itemList, includeModifiers)
return p._getEquipmentTable(itemList, includeModifiers)