Module:IconData

-- local p = {}

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

--[[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 (default: Available)	source      - string    - Store, Missions, Riot, Merch Store and Bundle (default: Store)	RP          - string    - If source="Store": RP Cost (default: 250)	BE          - string    - If source="Store": BE Cost (default: N/A)	details     - string    - Additional acquisition information	set         - string or table    - Collection name 	country      - string    - If set="eSports", the Team's Country         currently handled countrys:              AR  - Argentina             INT     - International                     BR  - Brazil                EU      - Europe                               CN  - China                 NA      - North America             CO  - Colombia              LAS     - Latin America South              CR  - Costa Rica            LAN     - Latin America North            DK  - Denmark               SEA     - South East Asia            FR  - France                OCE     - Oceania            DE  - Germany            HK  - Hong Kong            ID  - Indonesia            JP  - Japan            KR  - Korea            LT  - Lithuania            MY  - Malaysia            MX  - Mexico            PE  - Peru            PH  - Philippines            RU  - Russia            SG  - Singapore            ES  - Spain            SW  - Sweden            TW  - Taiwan            TH  - Thailand            TR  - Turkey            UA  - Ukraine            UK  - United Kingdom            VN  - Vietnam    tournament	- string	- If set="esports", the Event/Tournament the icon is from        currently handled tournaments:            NALCS   - NA LCS                MSI         - Mid-Season Invitational            EULCS   - EU LCS                Worlds      - World Championship            CBLOL   - Brazil LCS            All-Star            CLS     - Latin South LCS       Rift Rivals            CNC     - Chile LCS            GPL     - Garena LCS            LAN     - Latin America LCS            LCK     - Korean LCS            LCL     - Russian LCS            LJL     - Japan LCS            LMS     - SEA LCS            LPL     - China LCS            LLN     - Latin North LSC            OPL     - Oceania LCS            TCL     - Turkey LCS            VCS     - Vietnam LCS            OGN     - OnGameNet Invitational            SLTV    - SLTV Star Series ]]--

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.getIconname(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local avatars = {} for x in pairs(iconData) do       table.insert(avatars, x)    end for _, avatarname in pairs(avatars) do       if iconData[avatarname].id ~= nil then if tonumber(args[id]) == iconData[avatarname].id then return avatarname end end end return "Error" 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 = {} local count = 0 local idtable = {} for x in pairs(iconData) do       table.insert(avatars, x)    end function comp(a, b)       if iconData[a].id == nil then a = -1 else a = iconData[a].id end if iconData[b].id == nil then b = -1 else b = iconData[b].id end if a < b then return true end end table.sort(avatars, comp) for _, avatarname in pairs(avatars) do       local num = "" if iconData[avatarname].id ~= nil then if iconData[avatarname].id < 10 then num = "000" .. iconData[avatarname].id           elseif iconData[avatarname].id < 100 then num = "00" .. iconData[avatarname].id           elseif iconData[avatarname].id < 1000 then num = "0" .. iconData[avatarname].id           else num = iconData[avatarname].id           end end if iconData[avatarname].id == 0 then avatarList :tag('li') :wikitext(' == ') :done :newline count = count + 1 end idtable[num] = avatarname end avatarList :newline :wikitext('count: ' .. count) local avatarListItems = mw.html.create('ol') for i=1, 3600 do       local num = "" if i < 10 then num = "000" .. i       elseif i < 100 then num = "00" .. i       elseif i < 1000 then num = "0" .. i       else num = i       end mw.log(idtable[num]) avatarListItems :tag('li') :wikitext(' == ') :done end avatarList :node(avatarListItems) return avatarList 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.getRP(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return iconData[args[1]].RP or "250" end

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

return iconData[args[1]].BE or "N/A" 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.getCountry(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return iconData[args[1]].country 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 = {} local hash = {} local setList = mw.html.create('ul') setList:newline

for x in pairs(iconData) do       if iconData[x].set ~= nil then if type(iconData[x].set) == "table" then for _, value in pairs(iconData[x].set) do                   if (not hash[value]) then table.insert(sets, value) hash[value] = true end end else if (not hash[iconData[x].set]) then table.insert(sets, iconData[x].set) hash[iconData[x].set] = true end end end end table.sort(sets) 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 = {} local result = false for x in pairs(iconData) do       table.insert(avatars, x)    end table.sort(avatars)

for _, avatarname in pairs(avatars) do       local hit = false local t = iconData[avatarname] -- if current.set == args[1] then --    result = true -- else --    --do nothing -- end if (t.set ~= nil) then if type(t.set) == "table" then for _, subset in pairs(t.set) do                   if subset == args[1] then hit = true result = true end end else if t.set == args[1] then hit = true result = true end end end if hit == true then avatarList :tag('li') :tag('div') :addClass('avatar-icon') :attr('data-param', avatarname) :wikitext(' ' .. avatarname) :done :done :newline end end if result == false then avatarList :tag('li') :wikitext('No match found for ' .. args[1] .. '.') :done 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') :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 or 'Store') :attr('data-release', tostring(current.release) .. "release") :tag('div') :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) avatarlist :wikitext(';' .. v)       :newline esportsbyyear (avatars, avatarList, 2017) avatarlist :wikitext(';' .. v)       :newline esportsbyyear (avatars, avatarList, 2016) avatarlist :wikitext(';' .. v)       :newline esportsbyyear (avatars, avatarList, 2015) avatarlist :wikitext(';' .. v)       :newline esportsbyyear (avatars, avatarList, 2014) avatarlist :wikitext(';' .. v)       :newline esportsbyyear (avatars, avatarList, 2013) avatarlist :wikitext(';' .. v)       :newline esportsbyyear (avatars, avatarList, 2012) avatarlist :wikitext(';' .. v)       :newline 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)   for _, avatarname in pairs(avatars) do        local current = iconData[avatarname] if current.set == "eSports" then if current.release == v then local region = "" if current.country ~= nil then region = current.country .. ", " .. getRegion(current.country) end local event = "" if current.tournament ~= nil then event = current.tournament .. ", " .. getEvent(current.tournament) 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-country', region) :attr('data-tournament', event) :wikitext('') :done :done :newline else --do nothing end else --do nothing end end

return avatarList end

function getRegion(regionname) local regionlist = { {"US",   "NA"}, {"DE",   "EU"}, {"DK",   "EU"}, {"ES",   "EU"}, {"FR",   "EU"}, {"LT",   "EU"}, {"SW",   "EU"}, {"UA",   "EU"}, {"UK",   "EU"}, {"CO",   "LAN"}, {"CR",   "LAN"}, {"MX",   "LAN"}, {"PE",   "LAN"}, {"AR",   "LAS"}, {"CL",   "LAS"}, {"AU",   "OCE"}, {"ID",   "SEA"}, {"HK",   "SEA"}, {"MY",   "SEA"}, {"PH",   "SEA"}, {"SG",   "SEA"}, {"TH",   "SEA"}, {"TW",   "SEA"}, {"VN",   "SEA"} }   for _, value in ipairs(regionlist) do         if regionname == value[1] then return value[2] end end

return "undefined" end

function getEvent(eventname) local eventslist = { {"MSI",        "International"}, {"Worlds",     "International"}, {"All-Star",   "International"}, {"Rift Rivals", "International"}, {"NALCS",      "Countryal"}, {"EULCS",      "Countryal"}, {"CBLOL",      "Countryal"}, {"CLS",        "Countryal"}, {"CNC",        "Countryal"}, {"GPL",        "Countryal"}, {"LAN",        "Countryal"}, {"LCK",        "Countryal"}, {"LCL",        "Countryal"}, {"LJL",        "Countryal"}, {"LMS",        "Countryal"}, {"LPL",        "Countryal"}, {"LLN",        "Countryal"}, {"OPL",        "Countryal"}, {"TCL",        "Countryal"}, {"VCS",        "Countryal"}, {"OGN",        "Special"}, {"SLTV",       "Special"} }   for _, value in ipairs(eventslist) do         if eventname == value[1] then return value[2] end end

return "undefined" 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

return p

-- --