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

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", " "), 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

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 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" }

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"] = "#CCCCCC" colors["Hyperbolic"] = "#33CC33" colors["Exponential"] = "#CC6666" colors["Special"] = "#8888FF" colors["None"] = "#888888"

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

Nav Items local nav_head_items = [=[{| class="navbox" style="width:100%;margin-top:1em;border:1px solid;font-size:90%;text-align:center" ! style="background-color:#282828;font-size:175%;white-space:nowrap" | Items ]=]

local nav_row_items = [=[|- ]=]
 * style="background-color:#3A3A3A;font-size:125%%;font-weight:bold;white-space:nowrap" | %s
 * style="padding:0.2em 0.5em" | %s
 * style="padding:0.2em 0.5em" | %s

function p.NavItems(frame) local nav = nav_head_items local items = { Common = {}, Uncommon = {}, Legendary = {}, Boss = {}, Lunar = {} } for name, item in pairs(all_items) do   table.insert(items[item.Rarity], "" .. name .. "") end for rarity in pairs(items) do   table.sort(items[rarity]) end for i, rarity in ipairs({ "Common", "Uncommon", "Legendary", "Boss", "Lunar" }) do   nav = nav .. nav_row_items:format(     rarity,      rarity,      table.concat(items[rarity], " | ")    ) end return frame:preprocess(nav .. "|}") end

Nav Equipment local nav_head_equipment = [=[{| class="navbox" style="width:100%;margin-top:1em;border:1px solid;font-size:90%;text-align:center" ! style="background-color:#282828;font-size:175%;white-space:nowrap" | Equipment ]=]

local nav_row_equipment = [=[|- ]=]
 * style="background-color:#3A3A3A;font-size:125%%;font-weight:bold;white-space:nowrap" | %s
 * style="padding:0.2em 0.5em" | %s
 * style="padding:0.2em 0.5em" | %s

function p.NavEquipment(frame) local nav = nav_head_equipment local equipment = { Equipment = {}, ["Lunar Equipment"] = {}, ["Elite Equipment"] = {} } for name, e in pairs(all_equipment) do   table.insert(equipment[e.Rarity], "" .. name .. "") end for rarity in pairs(equipment) do   table.sort(equipment[rarity]) end for i, rarity in ipairs({ "Equipment", "Lunar Equipment", "Elite Equipment" }) do   nav = nav .. nav_row_equipment:format(     rarity,      rarity:gsub(" Equipment", ""):gsub("Equipment", "Normal"),      table.concat(equipment[rarity], " | ")    ) end return frame:preprocess(nav .. "|}") 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 --