Module:NavboxItems

--[=[

Lua script for Items Navbox Template

Function: main:

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

local p = {}

local collectionData = mw.loadData( 'Module:ItemCollection/data' ) local navbox = require('Module:Navbox').main local util = require('Module:Utility') local allItems = {} local aboveHead = table.concat(	{		"Permanent",		"Premium",		"Limited Time",		"Premium Limited Time"	}, " · ") local otherColl = { [9998] = {"Parade Floats"}, [9999] = {" Others "}, [99991] = {"Tappers", "''"}, [99992] = {"Mini Bosses", "''"}, }

local function getAllItems for name, data in pairs(collectionData.Items) do		local coll = data[1] or 9999 local itemType= data[2]

if itemType then if itemType == "tp" then itemType = "ch" coll = 99991 end if itemType == "mb" then itemType = "ch" coll = 99992 end if itemType == "pf" then coll = 9998 end if itemType == "cos" then local sChar, sCos = mw.ustring.match(name, "^(.+)%/(.+)$") coll = collectionData.Items[sChar][1] end

if not allItems[itemType] then allItems[itemType] = {} end

table.insert(allItems[itemType], {coll, name:lower:gsub("[\"'%-]", ""), name})		end	end

for key, data in pairs(allItems) 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 getCollName(coll) if otherColl[coll] then return otherColl[coll][1] end

if collectionData.Collections[coll] then return ""				.. collectionData.Collections[coll][2]				.. "" end return coll end

local function _itemType(itemName) local item = itemName or mw.title.getCurrentTitle.prefixedText

local iType = "Unknown Item"

if collectionData.Items[item] and collectionData.Items[item][2] then iType = collectionData.Items[item][2] if not itemName and (iType == "tp" or iType == "mb") then iType = "ch" end end return iType end

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

return _itemType(tArgs[1]) end

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

local paramTable = { "child", above = aboveHead, }

local list = {}

for i, tdata in ipairs(items) do		local item = tdata[3]

if collectionData.Items[item] then iData = collectionData.Items[item] item = "" .. item:gsub(" Float$", "") .."" if otherColl[tdata[1]] and otherColl[tdata[1]][2] then item = otherColl[tdata[1]][2] .. item .. otherColl[tdata[1]][2] else if iData[3] and iData[3] == true then item = "'''" .. item .. "'''"				end if iData[4] and iData[4] == true then item = "''" .. item .. "''"				end end end

table.insert(list, item) end

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

return navbox(paramTable) end

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

local paramTable = { "child", above = aboveHead, }

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

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

local item = tdata[3]

if collectionData.Items[item] then iData = collectionData.Items[item] item = "" .. item .. "" if otherColl[tdata[1]] and otherColl[tdata[1]][2] then item = otherColl[tdata[1]][2] .. item .. otherColl[tdata[1]][2] else if iData[3] and iData[3] == true then item = "'''" .. item .. "'''"				end if iData[4] and iData[4] == true then item = "''" .. item .. "''"				end end end

table.insert(list, item) end

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

return navbox(paramTable) end

local function withSubGroup(itemType) local items = allItems[itemType]

local paramTable = { "child", above = aboveHead, }

local group = 1 local currColl = nil

local subParamTable = { "child", groupwidth = "30%", }

local subgroup = 1 local currChar = nil local sublist = {}

for i, tdata in ipairs(items) do   	local sChar, sCos = mw.ustring.match(tdata[3], "^(.+)%/(.+)$") if sChar ~= currChar then if currChar then subParamTable["group" .. subgroup] = "" .. currChar .. "" subParamTable["list" .. subgroup] = table.concat(sublist, " · ") subgroup = subgroup + 1 sublist = {} if tdata[1] ~= currColl then --if currColl then paramTable["group" .. group] = getCollName(currColl) paramTable["list" .. group] = navbox(subParamTable) group = group + 1 --end subParamTable = { "child", groupwidth = "30%", }					subgroup = 1 end end currChar = sChar currColl = tdata[1] end

local item = tdata[3]

if collectionData.Items[item] then iData = collectionData.Items[item] item = "" .. (sCos or item) .. "" if otherColl[tdata[1]] and otherColl[tdata[1]][2] then item = otherColl[tdata[1]][2] .. item .. otherColl[tdata[1]][2] else if iData[3] and iData[3] == true then item = "'''" .. item .. "'''"				end if iData[4] and iData[4] == true then item = "''" .. item .. "''"				end end end

table.insert(sublist, item) end

subParamTable["group" .. subgroup] = "" .. currChar .. "" subParamTable["list" .. subgroup] = table.concat(sublist, " · ") paramTable["group" .. group] = getCollName(currColl) paramTable["list" .. group] = navbox(subParamTable)

return navbox(paramTable) end

-- Main invokable function

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

-- Populate and categorize All Items getAllItems

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

group1 = "Characters", abbr1 = "ch", list1 = withGroup("ch"),

group2 = "Costumes", abbr2 = "cos", list2 = withSubGroup("cos"),

group3 = "Attractions", abbr3 = "ba", list3 = withGroup("ba"),

group4 = "Concessions", abbr4 = "bc", list4 = withGroup("bc"),

group5 = "Decorations", abbr5 = "d", list5 = withGroup("d"),

group6 = "Parade Floats", abbr6 = "pf", list6 = withNoGroup("pf"), }	if tArgs.nocollapsiblegroups then nbParams.withcollapsiblegroups = nil end

return navbox(nbParams) end

return p