Module:ItemData/nav: Difference between revisions

Jump to navigation Jump to search
Sur (talk | contribs)
m concat card to ret earlier
Sur (talk | contribs)
m process to a list then sort it alphabetically before returning the string
Line 15: Line 15:
if min_souls == nil or max_souls == nil then return 'Min/Max souls must be numerical' end
if min_souls == nil or max_souls == nil then return 'Min/Max souls must be numerical' end
local ret = ''
--Retrieve all items that fit the bounds
local items = {}
for item_key, item_data in pairs(items_data) do
for item_key, item_data in pairs(items_data) do
local card
local card
Line 26: Line 27:
if item_data["Name"] ~= nil and item_data["Disabled"] == false and cost ~= nil and slot ~= nil then
if item_data["Name"] ~= nil and item_data["Disabled"] == false and cost ~= nil and slot ~= nil then
if slot == slot_ and cost>=min_souls and cost<max_souls then
if slot == slot_ and cost>=min_souls and cost<max_souls then
card = '{{ItemIcon|' .. lang_module.get_string(item_key) .. '}}'
table.insert(items, lang_module.get_string(item_key))
ret = ret .. card .. ' &bull; '
end
end
end
end
end
--Order list alphabetically
table.sort(items) --O(nlogn)
--Add each item to output
local ret = ''
for index, item_name in ipairs(items) do
ret = ret .. '{{ItemIcon|' .. item_name .. '}} &bull; '
end
end