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(infobox_template_item:format( item_name, item_name, item.Quote, item.Rarity, item.Desc:gsub("\r\n", " "), Stacking(item.Stacking), Category(item.Category), (item.Unlock == "" or item.Unlock == nil) and "" or "" .. item.Unlock .. "", item.ID, ""   --Stats(item.Stats) )) 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(infobox_template_equipment:format( equipment_name, equipment_name, equipment.Quote, equipment.Rarity, equipment.Desc:gsub("\r\n", " "), equipment.Cooldown and equipment.Cooldown .. "s" or "", (equipment.Unlock == "" or equipment.Unlock == nil) and "" or "" .. equipment.Unlock .. "", equipment.ID )) end

Stacking function Stacking(list) return list:gsub("([^,]+)", function(m)   m = m:gsub("^%l", string.upper)    return "" .. m .. " Stacking"  end):gsub(",", " ") end

Category function Category(list) return list:gsub("([^,]+)", function(m)   m = m:gsub("^%l", string.upper)    return "" .. m .. ""  end):gsub(",", " ") end

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

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

function p.Table(frame) local rarity = frame.args[1] local table = table_head_item for i, item in ipairs(Sort(all_items)) do   if item.Rarity == rarity then table = table .. frame:preprocess(table_row_item:format(item.Name, item.Name, item.Name, item.Name, Description(item.Desc))) end end 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(table_row_boss:format(item.Name, item.Name, item.Name, item.Name, Description(item.Desc), item.Boss, item.Boss, item.Boss, item.Boss)) end end 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" | %s ]=]

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:format(rarity == "Elite Equipment" and "Elite" or "Cooldown") for i, equipment in ipairs(Sort(all_equipment)) do   if equipment.Rarity == rarity then table = table .. frame:preprocess(table_row_equipment:format(equipment.Name, equipment.Name, equipment.Name, equipment.Name, Description(equipment.Desc), rarity == "Elite Equipment" and equipment.Elite or (equipment.Cooldown and equipment.Cooldown .. "s" or "-"))) end end return table .. "|}" end

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

Stats local stats_row = [=[| stat%s = %s ]=]
 * value%s = %s
 * stack%s = %s
 * add%s = %s

function Stats(stats) local rows = "" for i, v in ipairs(stats) do   rows = rows .. stats_row:format(     i, v.Stat,      i, v.Value,      i, Stack(v.Stack),      i, v.Add    ) end return rows end

Stack local colors = {} colors["Linear"] = "#FFFFFF" colors["Hyperbolic"] = "#00FF66" colors["Exponential"] = "#FF0033" colors["Special"] = "#0066FF" colors["None"] = "#909090"

function Stack(stack) for k, v in pairs(colors) do   if stack:find(k) then stack = stack:gsub(k, "" .. k .. " ") break end end return stack end

Sort 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 --