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.synchronize(frame) local jsonicons    = jsontolua("User:AnataBakka/icons") local s            = ""

for jsonindex, idata in pairs(jsonicons) do       local iconid = idata["id"] local jsonname = idata["title"] local luaname = luaiconData[jsonname] local lucaid = luaname["id"] if luaname ~= nil then if luaid ~= iconid then s = s .. "\n* jsonindex = " .. jsonindex .. " id = " .. luaid .. " " .. jsonname .. " > " .. jsonid end else s = s .. "\n * " .. jsonindex .. " " .. jsonname .. " > not found" 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            = ""

for jsonindex, idata in pairs(jsonicons) do       local jsonname = idata["title"] local luaname = luaiconData[jsonname] if luaname ~= nil then for _, descriptiondata in pairs(idata["descriptions"]) do               if descriptiondata["description"] ~= luaname["details"] then s = s .. "\n* jsonindex = " .. jsonindex .. " " .. jsonname end 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 iconskins    = jsontolua("User:AnataBakka/icons") local iconsets     = jsontolua("User:AnataBakka/iconsets") local setids       = {} local setdata      = {} local s            = "" for _, setdata in pairs(iconsets) 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"] local luaname = luaiconData[jsonname] local jsonid = idata["id"] 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 if type(luaset) == string then if jsonset == luaset then count2 = 1 end else if type(luaset) == table then for _, subtheme in pairs(luaset) do                                   if subtheme == jsonset then count2 = 1 end end end end if count2 == 0 then s = s .. "\n* jsonindex = " .. jsonindex .. " " .. 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 .. " " .. 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 iconskins    = jsontolua("User:AnataBakka/icons") local iconsets     = jsontolua("User:AnataBakka/iconsets") local setids       = {} local setdata      = {} local s            = "" for _, setdata in pairs(iconsets) 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"] local luaname = luaiconData[jsonname] local jsonid = idata["id"] if luaname ~= nil then local luaset = luaname["set"] if luaset ~= nil then if setids[jsonid] ~= nil then if type(luaset) == string then local count2 = 0 for _,jsonset in pairs(setids[jsonid]) do                           if luaset == jsonset then count2 = 1 end end if count2 == 0 then s = s .. "\n* jsonindex = " .. jsonindex .. " " .. jsonname .. " > " .. luaset .. " Unofficial Set Added" end else if type(luaset) == table 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 .. " " .. jsonname .. " > " .. subtheme .. " Unofficial Set Added" end end end end else if type(luaset) == string then s = s .. "\n* jsonindex = " .. jsonindex .. " " .. jsonname .. " > " .. luaset .. " Unofficial Set Added" else if type(luaset) == table then for _, subtheme in pairs(luaset) do                               s = s .. "\n* jsonindex = " .. jsonindex .. " " .. jsonname .. " > " .. subtheme .. " Unofficial Set Added" end end 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 --