Module:IconData

-- local p = {}

local iconData = mw.loadData('Module:IconData/data') local lib      = require('Module:Feature')

-- Key:   id              - int       - icon id    nicknames       - string    - alternatative names the icon may be referred by    release         - int       - release year    availability    - string    - Available, Legacy, Unavailable and Unreleased    source          - string    - Store, Missions, Riot and Bundle (default: Store)    details         - string    - Additional acquisition information    set             - string    - Collection name     region          - string    - eSports Team Region    tournament      - string    - eSports Event/Tournament --

function p.getIconData(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return iconData[args[1]] end

function p.getId(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return iconData[args[1]].id end

function p.idCompare(frame) local avatarList = mw.html.create('ul')

local avatars = {} for x in pairs(iconData) do       table.insert(avatars, x)    end table.sort(avatars) for _, avatarname in pairs(avatars) do       avatarList :tag('li') :wikitext(' == == ') :done :  newline end return avatarList end

function p.idComp (a, b)   if a.id > b.id then return true else return false end end

function p.getNicknames(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return iconData[args[1]].nicknames end

function p.getRelease(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return iconData[args[1]].release end

function p.getAvailability(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return iconData[args[1]].availability end

function p.getSource(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return iconData[args[1]].source end

function p.getDetails(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return iconData[args[1]].details end

function p.getSet(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return iconData[args[1]].set end

function p.getRegion(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return iconData[args[1]].region end

function p.getTournament(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return iconData[args[1]].tournament end

function p.getSetlist(frame) local sets = {} for x in pairs(iconData) do       table.insert(sets, iconData[x].set) end

sets = removeDuplicates(sets) table.sort(sets)

local setList = mw.html.create('ul') for _, setname in pairs(sets) do       setList :tag('li') :wikitext( .. setname .. ) :done :done :newline end return setList end

function p.getSeticons(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local avatarList = mw.html.create('ul') local avatars = {} for x in pairs(iconData) do       table.insert(avatars, x)    end table.sort(avatars)

for _, avatarname in pairs(avatars) do       local current = iconData[avatarname] if current.set == args[1] then avatarList :tag('li') :tag('div') :addClass('avatar-icon') :attr('data-param', avatarname) :wikitext(' ' .. avatarname) :done :done :newline else --do nothing end end return avatarList end

function p.getIconlist(frame) local avatarList = mw.html.create('ol') avatarList :addClass('champion_roster') :newline local avatars = {} for x in pairs(iconData) do       table.insert(avatars, x)    end table.sort(avatars) for _, avatarname in pairs(avatars) do       local current = iconData[avatarname] if current.set == "eSports" then --do nothing else avatarList :tag('li') :tag('div') :addClass('avatar-icon') :attr('data-param', avatarname) :attr('data-search', avatarname .. lib.ternary(current.nicknames ~= nil, ", " .. tostring(current.nicknames), "") .. lib.ternary(current.set ~= nil, ", " .. tostring(current.set), "")) :attr('data-availability', current.availability) :attr('data-source', current.source) :attr('data-release', tostring(current.release) .. "release") :wikitext('') :done :done :newline end end return avatarList end

function p.getEsportslist(frame) avatarList = mw.html.create('ol') avatarList :addClass('champion_roster') :newline local avatars = {} for x in pairs(iconData) do       table.insert(avatars, x)    end table.sort(avatars) esportsbyyear (avatars, avatarList, 2018) esportsbyyear (avatars, avatarList, 2017) esportsbyyear (avatars, avatarList, 2016) esportsbyyear (avatars, avatarList, 2015) esportsbyyear (avatars, avatarList, 2014) esportsbyyear (avatars, avatarList, 2013) esportsbyyear (avatars, avatarList, 2012) return avatarList end

function p.getEsportsyear(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end avatarList = mw.html.create('ol') avatarList :addClass('champion_roster') :newline local avatars = {} for x in pairs(iconData) do       table.insert(avatars, x)    end table.sort(avatars) esportsbyyear (avatars, avatarList, tonumber(args[1])) return avatarList end

function esportsbyyear ( avatars, avatarlist, v ) avatarlist :wikitext(';' .. v)       :newline for _, avatarname in pairs(avatars) do       local current = iconData[avatarname] if current.set == "eSports" then if current.release == v then local server = "" if current.region ~= nil then server = current.region .. ", " .. getServer(current.region) end avatarList :tag('li') :tag('div') :addClass('esports-icon') :attr('data-param', avatarname) :attr('data-search', avatarname .. lib.ternary(current.nicknames ~= nil, ", " .. tostring(current.nicknames), "")) :attr('data-region', server) :attr('data-tournament', current.tournament) :wikitext('') :done :done :newline else --do nothing end else --do nothing end end

return avatarList end

function getServer ( v ) local var = "" if v == "US" then var = "NA" end if v == "DK" or v == "DE" or v == "FR" or v == "LT" or v == "ES" or v == "SW" or v == "UA" or v == "UK" then var = "EU" end if v == "CO" or v == "CR" or v == "MX" or v == "PE" then var = "LAN" end if v == "AR" or v == "CL" then var = "LAS" end if v == "AU" then var = "OCE" end if v == "ID" or v == "HK" or v == "MY" or v == "PH" or v == "SG" or v == "TH" or v == "TW" or v == "VN" then var = "SEA" end return var end

-- helper functions function table.val_to_str ( v ) if "string" == type( v ) then v = string.gsub( v, "\n", "\\n" ) if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then return "'" .. v .. "'"   end return '"' .. string.gsub(v,'"', '\\"' ) .. '"' else return "table" == type( v ) and table.tostring( v ) or     tostring( v ) end end function table.key_to_str ( k ) if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then return k else return "[" .. table.val_to_str( k ) .. "]" end end function table.tostring( tbl ) local result, done = {}, {} for k, v in ipairs( tbl ) do   table.insert( result, table.val_to_str( v ) ) done[ k ] = true end for k, v in pairs( tbl ) do   if not done[ k ] then table.insert( result,       table.key_to_str( k ) .. "=" .. table.val_to_str( v ) ) end end return "{" .. table.concat( result, "," ) .. "}" end

function duplicateCount(tbl, item) local count = 0 for _, v in pairs(tbl) do		if item == v then count = count + 1 end end return count end

function removeDuplicates(tbl) local newtable = {} for _, v in ipairs(tbl) do		if(duplicateCount(newtable, v) == 0) then newtable[#newtable+1] = v		end end return newtable end

return p

-- --