Module:Test Version History

-- local p = {}

local logbook = require("Module:Items/LogbookData") local data = require("Module:Test Version History/Data") local all_dates = data.patch

Version Infobox local infobox_template_item = [=[ ]=]

function p.InfoboxVersion(frame) local item_name = frame.args[1] ~= "" and frame.args[1] or mw.title.getCurrentTitle.text local item = all_dates[item_name] return frame:preprocess(infobox_template_item:format( item_name, item_name, item.Desc:gsub("\r\n", " "), item.Date, item.Category and Category(item.Category) or "", item.ID, item.Stats and Stats(item.Stats) or "" )) end

Category function Category(list) local cats = {} for i, v in ipairs(list) do   table.insert(cats, "" .. v .. "") end return table.concat(cats, " ") end

Table local table_head = [=[ {| class="article-table sortable firstcolumn-center-nowrap floatheader" style="width:100%; max-width:1350px; text-align:center;" ! data-sort-type=isoDate style="width:10%" | Date ! class="unsortable" style="width:10%" | Version ! class="unsortable" style="width:10%" | New Survivor ! class="unsortable" | Description ]=]

local table_row = [=[ ]=]
 * data-sort-direction="desc" data-sort-value="%s" | %s
 * %s
 * %s
 * %s
 * %s

function p.Table(frame) local wikitable = table_head for i, item in ipairs(Sort(all_dates)) do     wikitable = wikitable .. table_row:format(       item.Date, DateToString(item.Date),         item.Version,         item.NewSurvivor and ("%s"):format( item.NewSurvivor, item.NewSurvivor, item.NewSurvivor) or "-",        Description(item.Desc)      ) end return frame:preprocess(wikitable .. "|}") end

Description

local link_patterns = {} link_patterns["Damage"] = { "[Dd]amage", "[Aa]ttack [Ss]peed" } link_patterns["Health"] = { "[Hh]ealth" } link_patterns["Shield"] = { "[Ss]hields?" } link_patterns["Barrier"] = { "[Bb]arrier" } link_patterns["Armor"] = { "[Aa]rmor" } link_patterns["Movement Speed"] = { "[Mm]ovement [Ss]peed", "[Ss]print [Ss]peed", "[Mm]ovespeed" } link_patterns["Chests#Rusty Lockbox"] = { "[Hh]idden [Cc]ache" } link_patterns[":Category:OnKillEffect Items"] = { "On%-Kill" } link_patterns["Interactibles#Shrines"] = { "Shrine" } link_patterns["3D Printers"] = { "3D Printers" } link_patterns["57 Leaf Clover"] = { "[Ll]uck" } link_patterns["Monsters#Bosses"] = { "[Bb]osses" } link_patterns["Monsters#Elites"] = { "[Ee]lites?" }

-- this function replaces instances of keywords found in the description using link patterns found above. takes into account upper and lower case 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

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.Date < b.Date end) return items end

DateToString -- MON XX, YEAR function DateToString(isodate) m = {"January","February","March","April","May","June","July","August","September","October","November","December"} return m[tonumber(string.sub(isodate,5,6))].." "..string.sub(isodate,7)..", "..string.sub(isodate,1,4) end

GetItemOrEquipment -- returns item object (table) or string with error function GetItemOrEquipment(item_name) if item_name == nil then return ' Error: Name missing. 1st parameter is required. ' end local item = all_items[item_name] or all_equipment[item_name] if item == nil then return ' Error: Incorrect name. Check capitalization. ' else return item end end

GetRarity function p.GetRarity(frame) local item_name = frame.args[1] local simple_form = frame.args[2] or false local item = GetItemOrEquipment(item_name) if type(item) == 'string' then return item end local rarity = item.Rarity if simple_form and rarity == 'Elite Equipment' then rarity = 'Equipment' elseif simple_form and rarity == 'Lunar Equipment' then rarity = 'Lunar' end return rarity end

Logbook local logbook_template = [=[

function p.Logbook(frame) local size = frame.args.size or frame.args[1] or 64 local spacing = math.max(0, size / 16 - 2) local rows = {} for i, item in ipairs(logbook.order) do   rows[#rows+1] = '| ' .. GetItemBox(frame, item, size) if i % logbook.width == 0 and i ~= count then rows[#rows+1] = '|-' end end return string.format(logbook_template, spacing, table.concat(rows, '\n')) end

return p --