Module:IconThemes

-- local p   = {}

local luaiconData = mw.loadData('Module:IconData/data') local lib         = require('Module:Feature') local json        = require('Module:JSON') local userError   = require('Dev:User error')

function p.duplicates(frame) local jsonicons    = jsontolua("User:AnataBakka/icons") local s     = "" local duplicatenames={} local namesindex={} local duplicateids={} local idsindex={} for jsonindex, idata in pairs(jsonicons) do       local name = idata["title"] local id = idata["id"] if duplicatenames[name] == nil then duplicatenames[name] = 1 namesindex[name] = jsonindex else if duplicatenames[name] == 1 then duplicatenames[name] = 2 s = s .. "\n* " .. namesindex[name] .. " " .. name s = s .. "\n* " .. jsonindex .. " " .. name else s = s .. "\n* " .. jsonindex .. " " .. name end end if duplicateids[id] == nil then duplicateids[id] = 1 idsindex[id] = jsonindex else if duplicateids[id] == 1 then duplicateids[id] = 2 s = s .. "\n* " .. idsindex[id] .. " " .. id               s = s .. "\n* " .. jsonindex .. " " .. id           else s = s .. "\n* " .. jsonindex .. " " .. id           end end end local duplicatenames={} local duplicateids={} for name, idata in pairs(luaiconData) do       local id = idata["id"] if duplicatenames[name] == nil then duplicatenames[name] = 1 else s = s .. "\n* " .. name end if id ~= nil then if duplicateids[id] == nil then duplicateids[id] = 1 else s = s .. "\n* " .. id           end end end return s end

function p.synchronize(frame) local jsonicons    = jsontolua("User:AnataBakka/icons") local s            = "" local luatable = {} for name, idata in pairs(luaiconData) do       if idata.id ~= nil then luatable[tostring(idata.id)] = name end end for jsonindex, idata in pairs(jsonicons) do       local jsonid = tostring(idata["id"]) or "nil" local jsonname = idata["title"] or "nil" local luaname if luatable[jsonid] ~= nil then luaname = luatable[jsonid] if jsonname ~= luaname then if string.sub(jsonname,-5) == " Icon" then jsonname = string.sub(jsonname,1,#jsonname-5) if jsonname ~= luaname then s = s .. "\n* jsonindex = " .. jsonindex-1 .. " " .. luaname .. " > " .. jsonname end else s = s .. "\n* jsonindex = " .. jsonindex-1 .. " " .. luaname .. " > " .. jsonname end end else s = s .. "\n* jsonindex = " .. jsonindex-1 .. " id " .. jsonid .. " not found for " .. jsonname end end if s == "" then return "All icon ids and skin names are synchronized." else return "The following icons are not synchronized:" .. s   end end

function p.descriptions(frame) local jsonicons    = jsontolua("User:AnataBakka/icons") local s            = "" local s2           = "" local i = 0

for jsonindex, idata in pairs(jsonicons) do       local jsonname = idata["title"] or "nil" local luaname if string.sub(jsonname,-5) == " Icon" then jsonname = string.sub(jsonname,1,#jsonname-5) luaname = luaiconData[jsonname] if luaname == nil then luaname = luaiconData[idata["title"]] end else luaname = luaiconData[jsonname] end if luaname ~= nil then i = 0 for _, descriptiondata in pairs(idata["descriptions"]) do               if descriptiondata["description"] ~= luaname["details"] then if descriptiondata["region"] == "riot" then s = s .. "\n* jsonindex = " .. jsonindex-1 .. " " .. jsonname i = 1 break end s2 = "\n* jsonindex = " .. jsonindex-1 .. " " .. jsonname else if descriptiondata["region"] == "riot" then i = 1 break end end end if i ~= 1 then s = s .. s2            end end end if s == "" then return "All descriptions are synchronized." else return "The following descriptions are not synchronized:" .. s   end end

function p.missing(frame) local jsonicons    = jsontolua("User:AnataBakka/icons") local jsonsets     = jsontolua("User:AnataBakka/iconsets") local setids       = {} local setdata      = {} local s            = "" for _, setdata in pairs(jsonsets) do       for _, id in pairs(setdata["icons"]) do            if setids[id] == nil then setids[id] = {} end table.insert (setids[id],setdata.displayName) end end for jsonindex, idata in pairs(jsonicons) do       local jsonname = idata["title"] or "nil" local jsonid = idata["id"] or "nil" local luaname if string.sub(jsonname,-5) == " Icon" then jsonname = string.sub(jsonname,1,#jsonname-5) luaname = luaiconData[jsonname] if luaname == nil then luaname = luaiconData[idata["title"]] end else luaname = luaiconData[jsonname] end if luaname ~= nil then local luaset = luaname["set"] if luaset ~= nil then if setids[jsonid] ~= nil then for _,jsonset in pairs(setids[jsonid]) do                       local count2 = 0 for _, subtheme in pairs(luaset) do                           if subtheme == jsonset then count2 = 1 end end if count2 == 0 then s = s .. "\n* jsonindex = " .. jsonindex-1 .. " " .. jsonname .. " > " .. jsonset .. " Set Missing" end end end else if setids[jsonid] ~= nil then for _,jsonset in pairs(setids[jsonid]) do                       s = s .. "\n* jsonindex = " .. jsonindex-1 .. " " .. jsonname .. " > " .. jsonset .. " Set Missing" end end end end end if s == "" then return "Nothing is missing." else return "The following stuff is missing:" .. s   end end

function p.added(frame) local jsonicons    = jsontolua("User:AnataBakka/icons") local jsonsets     = jsontolua("User:AnataBakka/iconsets") local setids       = {} local setdata      = {} local s            = "" for _, setdata in pairs(jsonsets) do       for _, id in pairs(setdata["icons"]) do            if setids[id] == nil then setids[id] = {} end table.insert (setids[id],setdata.displayName) end end for jsonindex, idata in pairs(jsonicons) do       local jsonname = idata["title"] or "nil" local jsonid = idata["id"] or "nil" local luaname if string.sub(jsonname,-5) == " Icon" then jsonname = string.sub(jsonname,1,#jsonname-5) luaname = luaiconData[jsonname] if luaname == nil then luaname = luaiconData[idata["title"]] end else luaname = luaiconData[jsonname] end if luaname ~= nil then local luaset = luaname["set"] if luaset ~= nil then if setids[jsonid] ~= nil then for _, subtheme in pairs(luaset) do                       local count2 = 0 for _,jsonset in pairs(setids[jsonid]) do                           if subtheme == jsonset then count2 = 1 end end if count2 == 0 then s = s .. "\n* jsonindex = " .. jsonindex-1 .. " " .. jsonname .. " > " .. subtheme .. " Unofficial Set Added" end end else for _, subtheme in pairs(luaset) do                       s = s .. "\n* jsonindex = " .. jsonindex-1 .. " " .. jsonname .. " > " .. subtheme .. " Unofficial Set Added" end end end end end if s == "" then return "Nothing unofficial has been added." else return "The following unofficial stuff has been added:" .. s   end end

-- HELPER FUNCTIONS:

function jsontolua(pagename) local titleobject = mw.title.new(pagename) local o           = json.decode(titleobject:getContent) return o end

return p --