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.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) 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 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', current.region) :attr('data-tournament', current.tournament) :wikitext('') :done :done :newline else --do nothing end end return avatarList 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

-- --