Toggle menu
515
2.5K
886
23K
Deadlock Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:ItemData/nav: Difference between revisions

From Deadlock Wiki
Sur (talk | contribs)
m process to a list then sort it alphabetically before returning the string
Sur (talk | contribs)
m sort by souls first, then item name; seems it wasnt necessary since nothing seems to be different, call it future proof then
Line 17: Line 17:
--Retrieve all items that fit the bounds
--Retrieve all items that fit the bounds
local items = {}
local items = {}
--1st layer: souls
--2nd layer: list of items with that soul count
for item_key, item_data in pairs(items_data) do
for item_key, item_data in pairs(items_data) do
local card
if item_data['Disabled'] == nil and item_data['IsDisabled'] ~= nil then  
if item_data['Disabled'] == nil and item_data['IsDisabled'] ~= nil then  
return "REMINDER: 'Disabled' was renamed to 'IsDisabled'"
return "REMINDER: 'Disabled' was renamed to 'IsDisabled'"
end
end
local cost = tonumber(item_data["Cost"])
local cost = tonumber(item_data["Cost"])
local slot_ = item_data["Slot"]
local slot_ = item_data["Slot"]
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
table.insert(items, lang_module.get_string(item_key))
if items[cost] == nil then
items[cost] = {} --list, ensure it exists before inserting to it
end
table.insert(items[cost], lang_module.get_string(item_key))
end
end
end
end
end
end
--Order list alphabetically
--Order each list of items for that cost by item name alphabetically
table.sort(items) --O(nlogn)
for cost, items_within_souls in pairs(items) do
table.sort(items[cost])
end
--Order the lists by souls
table.sort(items)
--2 level hash is now ordered first by cost, second by name alphabetically
--Add each item to output
--Add each item to output
local ret = ''
local ret = ''
for index, item_name in ipairs(items) do
for cost, items_within_souls in pairs(items) do
ret = ret .. '{{ItemIcon|' .. item_name .. '}} &bull; '
for index, item_name in ipairs(items_within_souls) do
ret = ret .. '{{ItemIcon|' .. item_name .. '}} &bull; '
end
end
end