Module:Items

-- local p = {}

local data = require("Module:Items/Data") local data_e = require("Module:Equipment/Data") local all_items = data.items local all_equipment = data_e.equipment

Link Patterns local link_patterns = {} link_patterns["Damage"] = { "[Dd]amage" } link_patterns["Health"] = { "[Hh]ealth" } link_patterns["Shield"] = { "[Ss]hield" } link_patterns["Armor"] = { "[Aa]rmor" } link_patterns["Movement Speed"] = { "[Mm]ovement [Ss]peed", "[Ss]print [Ss]peed" } link_patterns["Rusty Lockbox"] = { "[Hh]idden [Cc]ache" } link_patterns["Luck"] = { "[Ll]uck" } link_patterns["Elite"] = { "[Ee]lites?" } link_patterns["Aurelionite"] = { "[Aa]urelionite" }

Count function p.ItemCount local count = 0 for i in pairs(all_items) do   count = count + 1 end for i in pairs(all_equipment) do   count = count + 1 end return count end

Item Infobox local infobox_template_item = [=[ ]=]

function p.InfoboxItem(frame) local item_name = frame.args[1] local item = all_items[item_name] return frame:preprocess(string.format(infobox_template_item, item_name, item_name, item.Rarity, item.Desc, Stacking(item.Stacking), Category(item.Category), (item.Unlock == "" or item.Unlock == nil) and "" or "" .. item.Unlock .. "", item.ID, item.Quote )) end

Equipment Infobox local infobox_template_equipment = [=[ ]=]

function p.InfoboxEquipment(frame) local equipment_name = frame.args[1] local equipment = all_equipment[equipment_name] return frame:preprocess(string.format(infobox_template_equipment, equipment_name, equipment_name, equipment.Rarity, equipment.Desc, equipment.Cooldown and equipment.Cooldown .. "s" or "", (equipment.Unlock == "" or equipment.Unlock == nil) and "" or "" .. equipment.Unlock .. "", equipment.ID, equipment.Quote )) end

Stacking function Stacking(list) local stacking = "" for m in string.gmatch(list, "[^,]+") do   m = m:gsub("^%l", string.upper) stacking = stacking .. "" .. m  .. " Stacking " end return stacking end

Category function Category(list) local validCategories = { "Damage", "Healing", "Utility" } local category = "" for m in string.gmatch(list, "[^,]+") do   m = m:gsub("^%l", string.upper) for i, v in ipairs(validCategories) do     if m == v then category = category .. "" .. m  .. " " end end end return category end

Description function Description(desc) for link, patterns in pairs(link_patterns) do   for i, v in ipairs(patterns) do      local a, b = string.find(desc, v)      if a then desc = desc:sub(1, a - 1) .. "" .. desc:sub(a, b) .. "" .. desc:sub(b + 1, string.len(desc)) break end end end return desc end

Item Table local table_head = [=[{| class="article-table sortable floatheader header-center firstcolumn-center-nowrap" style="width:100%" ! style="width:25%" | Item ! class="unsortable" | Description ]=]

local table_row = [=[|- ]=]
 * data-sort-value="%s" | %s.png%s
 * %s

function p.Table(frame) local rarity = frame.args[1] local table = table_head for i, item in ipairs(Sort(all_items)) do   if item.Rarity == rarity then table = table .. frame:preprocess(string.format(table_row, item.Name, item.Name, item.Name, item.Name, Description(item.Desc))) end end table = table .. "|}" return table end

Boss Table local table_head_boss = [=[{| class="article-table sortable floatheader header-center firstcolumn-center-nowrap" style="width:100%" ! style="width:25%" | Item ! class="unsortable" | Description ! style="width:20%" | Boss ]=]

local table_row_boss = [=[|- ]=]
 * data-sort-value="%s" | %s.png%s
 * %s
 * style="text-align:center;white-space:nowrap" data-sort-value="%s" | %s.png%s

function p.BossTable(frame) local table = table_head_boss for i, item in ipairs(Sort(all_items)) do   if item.Rarity == "Boss" then table = table .. frame:preprocess(string.format(table_row_boss, item.Name, item.Name, item.Name, item.Name, Description(item.Desc), item.Boss, item.Boss, item.Boss, item.Boss)) end end table = table .. "|}" return table end

Equipment Table local table_head_equipment = [=[{| class="article-table sortable floatheader header-center firstcolumn-center-nowrap" style="width:100%" ! style="width:25%" | Item ! class="unsortable" | Description ! style="white-space:nowrap;width:15%" data-sort-type="number" | Cooldown ]=]

local table_row_equipment = [=[|- ]=]
 * data-sort-value="%s" | %s.png%s
 * %s
 * style="text-align:center" | %s

function p.EquipmentTable(frame) local rarity = frame.args[1] local table = table_head_equipment for i, equipment in ipairs(Sort(all_equipment)) do   if equipment.Rarity == rarity then table = table .. frame:preprocess(string.format(table_row_equipment, equipment.Name, equipment.Name, equipment.Name, equipment.Name, Description(equipment.Desc), equipment.Cooldown and equipment.Cooldown .. "s" or "-")) end end table = table .. "|}" return table end

Sort Items function Sort(list) local items = {} for name, item in pairs(list) do   item.Name = name table.insert(items, item) end table.sort(items, function(a, b) return a.Name < b.Name end) return items end

return p --