Module:ItemCollection

--[=[

-- Lua script to get Collection Icon for Character or Collection Name --

-- Function: -- getCollection -- -- Parameters: -- 1: Character Name (or Collection short Name) --     Separate multiple characters with a dollar sign "$" -- 2: Icon Size in pixels --     "T" = include Text name/link, size = 25 --     "A" = link to section/anchor on current page --     "N" = Collection Name (Text only) --     "S" = IP/Collection Short Name (Text only) -- 3: Filtered list --     if present, then filtered list of collections is displayed --     filtering out collections with item [2] not nil --

-- Function: -- getGallery -- -- Parameters: -- None. --]=]

local p = {}

local collectionData = mw.loadData( 'Module:ItemCollection/data' ) local util = require('Module:Utility')

function oneCollection(collection, size, outType, pageName) local fileLink = ""

if collection then local collName = collection[1] if outType == 3 then return collName elseif outType == 4 then return collection[3] or collName end local file = mw.ustring.gsub(collName, "[\,\.']", "") file = mw.ustring.gsub(file, " ", "_") file = mw.ustring.lower(file)

if outType == 1 then fileLink = ""               .. collName                .. " ("        end

fileLink = fileLink .. "[[File:cc-"           .. file            .. "-l.png|x"            .. size            .. "px|"            .. collName            .. "|link="

if outType == 2 then fileLink = fileLink .. pageName .. "#"                       .. mw.uri.anchorEncode(collection[4] or collName) .. "]]"       else fileLink = fileLink .. "Category:" .. collName .. "]]"       end

if outType == 1 then fileLink = fileLink .. ")"       end    end    return fileLink end

function oneImage(collection) local fileLink = ""

if collection then local collName = collection[1] local file = mw.ustring.gsub(collName, "[\,\.']", "") file = mw.ustring.gsub(file, " ", "_") file = mw.ustring.lower(file)

fileLink = fileLink .. "cc-" .. file .. "-l.png|"           .. collName            .. "|link=Category:" .. collName end return fileLink end

function p.getCollection(frame) local tArgs = util.getArgs(frame) local character = tArgs[1] or "" local size = tArgs[2] local filter = tArgs[3] or ""

local outType = 0

if not size or size == "" then size = "50" elseif not tonumber(size) then if size == "N" then outType = 3 size = "0" elseif size == "S" then outType = 4 size = "0" elseif size == "A" then outType = 2 size = "40" else outType = 1 size = "25" end end

local collectionFile = "" local space = "" local pageName = mw.title.getCurrentTitle.prefixedText

local collections = {}

character = mw.ustring.gsub(character, "^%s*(.-)%s*$", "%1") or '' if character == "" then character = mw.title.getCurrentTitle.text end

if character == "ALL" then for k, v in pairs(collectionData["Collections"]) do           if filter == "" or v[5] == nil then table.insert(collections, v)           end end

table.sort(collections, function(a,b) return a[2] < b[2] end)

for _, coll in ipairs(collections) do           collectionFile = collectionFile .. space .. oneCollection(coll, size, outType, pageName)

if outType == 1 or outType == 3 or outType == 4 then space = ", " else space = " " end end else for cName in mw.text.gsplit(character, "%s*%$%s*") do           cName = mw.text.decode(cName) if collectionData["Items"][cName] and collectionData["Items"][cName][1] then local collNo = collectionData["Items"][cName][1] -- If the line below is added, then in case of multiple items, if any one -- item has collNo = nil then the empty string will be returned, -- instead of just skipping that one item --               if collNo == nil then return "" end

if not collections[collNo] then local collData = collectionData["Collections"][collNo] collectionFile = collectionFile .. space .. oneCollection(collData, size, outType, pageName) if outType == 1 or outType == 3 or outType == 4 then space = ", " else space = " " end

collections[collNo] = 1 end end end end

return collectionFile end

-- to be called only from other LUA modules function p.actDataFile(character)

local dataFile = ""

if collectionData["Items"][character] then local collNo = collectionData["Items"][character][1]

if collectionData["Collections"][collNo] then data = collectionData["Collections"][collNo] dataFile = data[6] or data[3] or data[1] end end return dataFile end

function p.itemType local item = mw.title.getCurrentTitle.prefixedText if collectionData["Items"][item] then if collectionData["Items"][item][2] == "npc" then return "ch" end return collectionData["Items"][item][2] end return "Unknown Item" end

function p.getGallery(frame) local collectionFile = '' collectionFile = frame:preprocess(collectionFile)

return collectionFile end

-- used for the Content Update Navbox local function OneItem(collNumb, collNo, iItem) local tIndex = {} local tItems = "" local space = "" for item, v in pairs(collectionData["Items"]) do   	if v[1] == collNo then table.insert(tIndex, {item:lower:gsub("[\"']", ""):gsub(" ", "_"), item})   	end    end    table.sort(tIndex, function (a,b) return a[1] < b[1] end)

for nb, name in pairs(tIndex) do   	if collectionData["Items"][name[2]][2] and  collectionData["Items"][name[2]][2] == iItem then local iName = "" .. name[2] .. "" if collectionData["Items"][name[2]][3] and collectionData["Items"][name[2]][3] == true then iName = "'''" .. iName .. "'''"			end if collectionData["Items"][name[2]][4] and collectionData["Items"][name[2]][4] == true then iName = "''" .. iName .. "''"			end tItems = tItems .. space .. iName space = " · " end end if tItems == "" then return "" end

return '\n\n   ' .. "" .. collNumb[1] .. " " .. ' ' .. tItems .. "  " end

local function OneFloat local tIndex = {} local tItems = ' ' local space = "" for item, v in pairs(collectionData["Items"]) do   	if v[2] == "pf" then table.insert(tIndex, {v[1], item}) end end table.sort(tIndex, function (a,b) return a[1] < b[1] end)

for nb, name in pairs(tIndex) do local iName = "" .. mw.ustring.gsub(name[2], " Float", "") .. "" if collectionData["Items"][name[2]][3] and collectionData["Items"][name[2]][3] == true then iName = "'''" .. iName .. "'''"  		end if collectionData["Items"][name[2]][4] and collectionData["Items"][name[2]][4] == true then iName = "''" .. iName .. "''"		end tItems = tItems .. space .. iName space = " · " end return tItems .. " " end

local function OneCostume(collNumb, collNo) local tIndex = {} local tName = {} local tItem = "" local tChar = "" local space = "" local done = "" for item, v in pairs(collectionData["Items"]) do   	if v[1] == collNo then table.insert(tIndex, {item:lower:gsub(" ", "_"), item}) end end table.sort(tIndex, function (a,b) return a[1] < b[1] end)

for nb, name in pairs(tIndex) do   	if collectionData["Items"][name[2]][2] and collectionData["Items"][name[2]][2] == "cos" then local iChar, iCos = mw.ustring.match(name[2], "^([^%(]+)%s%(([^%d]+%d*)%)$")	       if iChar and done ~= iChar then    	    	done = iChar        		tItem = ""        		space = ""		    	for nb, name in pairs(tIndex) do		    		local _, iCos = mw.ustring.match(name[2], "^([^%(]+)%s%(([^%d]+%d*)%)$") if name[2]:match(iChar) and collectionData["Items"][name[2]][2] and collectionData["Items"][name[2]][2] == "cos" then local iName = "" .. iCos .. "" if collectionData["Items"][name[2]][3] and collectionData["Items"][name[2]][3] == true then iName = "'''" .. iName .. "'''"						end if collectionData["Items"][name[2]][4] and collectionData["Items"][name[2]][4] == true then iName = "''" .. iName .. "''"  						end tItem = tItem .. space .. iName space = " · " end end tChar = tChar .. ' "			end		end	end    if tItem == "" then return "" end    return '\n\n    ' .. "" .. collNumb[1] .. " "    		.. ' ' .. tChar .. "   " end

function p.getNavbox(frame) local tArgs = util.getArgs(frame) local collections = {} local items = ' ' end

return p