Module:NavboxTokens

--[=[

Lua script for Token Navbox Template

Function: main:

Parameters: state: plain / off selected: the selected group will be expanded nocollapsiblegroups: disable collapsible groups --]=]

local p = {}

local tokenData = mw.loadData('Module:CharacterToken/data') local availableData = mw.loadData('Module:Available/data').Tokens

local navbox = require('Module:Navbox').main local util = require('Module:Utility')

local allTokens = {} local tokGroups = { [0] = {"Collection Tokens"}, [1] = {"Common Tokens"}, [2] = {"Uncommon Tokens"}, [3] = {"Rare Tokens"}, [4] = {"Epic Tokens"}, [5] = {"Legendary Tokens"}, [6] = {"Costume Tokens"}, [8] = {"Attraction Enchantment Tokens"}, [7] = {nil, 8, "Blueprints"}, [81] = {nil, 8, "Common Relics"}, [82] = {nil, 8, "Uncommon Relics"}, [83] = {nil, 8, "Rare Relics"}, [9] = {"Event Only Tokens"}, [10] = {"NPC Tokens"}, [11] = {"Elixir Ingot Tokens"}, }

local function getAllTokens for name, data in pairs(tokenData) do		for _, tok in pairs(data) do			if type(tok) == "table" and not data["X"] then local tokenType = tok[2] or 999 if math.floor(tokenType/100) == 1 then tokenType = tokenType-100 end tokenKey = tokenType if tokGroups[tokenType] then tokenKey = tokGroups[tokenType][2] or tokenType end if not allTokens[tokenKey] then allTokens[tokenKey] = {} end

if availableData[tok[1]] then local date = require("Dev:Date") local today = os.date("%Y/%m/%d %H:%M:%S") local UnlockDate = availableData[tok[1]][1] .. util.dayStart if today > UnlockDate then table.insert(allTokens[tokenKey], {tokenType, tok[1], tok[2]}) end else table.insert(allTokens[tokenKey], {tokenType, tok[1], tok[2]}) end end end end

for key, data in pairs(allTokens) do	   table.sort(data, function(a,b)					if a[1] == b[1] then return a[2] < b[2] end					return a[1] < b[1]				end			) end end

local function withNoGroup(itemType) items = allTokens[itemType]

local paramTable = { "child", above = "Permanent Collection Token · Limited Time Collection Token", }

local list = {}

for i, tdata in pairs(items) do item = "" .. tdata[2] ..""

if tdata[3] == 9 or tdata[3] == 10 or (math.floor(tdata[3]/100) == 1) then item = "''" .. item .. "''"		end

table.insert(list, item) end

paramTable["list1"] = table.concat(list, " · ")

return navbox(paramTable) end

local function withGroup(itemType) local items = allTokens[itemType]

local paramTable = { "child", above = "Permanent Collection Token · Limited Time Collection Token", }

local group = 1 local currColl = nil local list = {}

for i, tdata in pairs(items) do		if tdata[1] ~= currColl then if currColl then paramTable["group" .. group] = tokGroups[currColl][3] paramTable["list" .. group] = table.concat(list, " · ") group = group + 1 list = {} end currColl = tdata[1] end

item = "" .. tdata[2] ..""

if tdata[3] == 6 or tdata[3] == 10 or (math.floor(tdata[3]/100) == 1) then item = "''" .. item .. "''"		end

table.insert(list, item) end

paramTable["group" .. group] = tokGroups[currColl][3] paramTable["list" .. group] = table.concat(list, " · ")

return navbox(paramTable) end

local function _tokenType(tokenName) local token = tokenName or mw.title.getCurrentTitle.prefixedText token = token:gsub(" Token$", "")

if availableData[token] then local date = require("Dev:Date") local today = os.date("%Y/%m/%d %H:%M:%S") local UnlockDate = availableData[token][1] .. util.dayStart if today < UnlockDate then return "unknown" end end local nRarity = nil

for name, data in pairs(tokenData) do		for _, tok in pairs(data) do			if type(tok) == "table" and not data["X"] then if tok[1] == token then nRarity = tok[2] if nRarity and math.floor(nRarity/100) == 1 then nRarity = math.mod(nRarity, 100) end if tokGroups[nRarity] then nRarity = tokGroups[nRarity][2] or nRarity end return tostring(nRarity) end end end end return "unknown" end

-- Main invokable function

function p.main(frame) local tArgs = util.getArgs(frame)

-- Populate and categorize All Items getAllTokens

local nbParams = { name = "Items", title = "Content Updates", listclass = "hlist", state = tArgs.state, selected = tArgs.selected or _tokenType(tArgs.name), withcollapsiblegroups = "yes", }

for gNumb, gData in pairs(tokGroups) do		if gNumb == 8 then nbParams["group9"] = tokGroups[gNumb][1] nbParams["abbr9"] = tostring(gNumb) nbParams["list9"] = withGroup(gNumb) elseif gData[1] then nbParams["group" .. gNumb+1] = gData[1] nbParams["abbr" .. gNumb+1] = tostring(gNumb) nbParams["list" .. gNumb+1] = withNoGroup(gNumb) end end if tArgs.nocollapsiblegroups then nbParams.withcollapsiblegroups = nil end

return navbox(nbParams) end

return p