Module:SkinThemes

-- local p   = {}

local luaskinData = mw.loadData('Module:SkinData/data') local luauniverseData = mw.loadData('Module:SkinData/universes') local lib         = require('Module:Feature') local json        = require('Module:JSON') local userError   = require('Dev:User error') local IL          = require('Module:ImageLink')

function p.officialtable(frame) local jsonskins    = jsontolua("User:AnataBakka/skins") local jsonsets     = jsontolua("User:AnataBakka/sets") local jsonuniverses = jsontolua("User:AnataBakka/universes") local setnames     = {} local resulttable  = {} local skintable    = {} local setids       = {} local universenames = {} local universeids  = {} local s            = "" s = s .. ' ' end

function p.synchronize(frame) local jsonskins    = jsontolua("User:AnataBakka/skins") local jsonsets     = jsontolua("User:AnataBakka/sets") local jsonuniverses = jsontolua("User:AnataBakka/universes") local setids       = {} local setdata      = {} local s            = ""

for _, setdata in pairs(jsonsets) do       setids[setdata.id] = setdata.name end for _, universedata in pairs(jsonuniverses) do       for _, setid in pairs(universedata.skinSets) do            if setdata[universedata.name] == nil then setdata[universedata.name] = {} end table.insert (setdata[universedata.name],setids[setid]) end end for jsonuniversename,jsonuniverse in pairs (setdata) do       if luauniverseData[jsonuniversename] ~= nil then for _,jsonsetname in pairs (jsonuniverse) do               local count = 0 for _,luasetname in pairs (luauniverseData[jsonuniversename]) do                   if jsonsetname == luasetname then count = 1 break end end if count == 0 then s = s .. "\n* Missing " .. jsonsetname .. "Set In " .. jsonuniversename .. " Universe" end end else s = s .. "\n* " .. jsonuniversename .. " Universe Missing" end end for luauniversename,luauniverse in pairs (luauniverseData) do       if setdata[luauniversename] ~= nil then for _,luasetname in pairs (luauniverse) do               local count = 0 for _,jsonsetname in pairs (setdata[luauniversename]) do                   if jsonsetname == luasetname then count = 1 break end end if count == 0 then s = s .. "\n* " .. jsonsetname .. "Unofficial Set Added In " .. jsonuniversename .. " Universe" end end else s = s .. "\n* " .. luauniversename .. " Unofficial Universe Added" end end for championname, cdata in pairs(luaskinData) do       for skinname, sdata in pairs(cdata["skins"]) do            if sdata["id"] ~= nil and sdata["id"] ~= "N/A" then local luaname = sdata["formatname"] or lib.ternary(skinname == "Original", championname, skinname .. " " .. championname) local skinid  = cdata["id"] * 1000 + sdata["id"] local jsonname = jsonskins[tostring(skinid)] if jsonname ~= nil then jsonname = jsonskins[tostring(skinid)]["name"] champsetid = jsonskins[tostring(skinid)]["skinLines"] end if championname == "Nunu" and skinname == "Original" then luaname = "Nunu & Willump" end if luaname ~= jsonname then s = s .. "\n* " .. skinid .. " " .. luaname .. " > "                    if jsonname == nil then s = s .. "skinid not found" else s = s .. jsonname end else local luaset = sdata["set"] if luaset ~= nil then if champsetid ~= nil and champsetid ~= "null" then for _,champsetid in pairs(jsonskins[tostring(skinid)]["skinLines"]) do                               local jsonset      = setids[champsetid.id] local count2 = 0 for _, subtheme in pairs(luaset) do                                   if subtheme == jsonset then count2 = 1 end end if count2 == 0 then s = s .. "\n* " .. skinid .. " " .. luaname .. " > " .. jsonset .. " Set Missing" end end for _, subtheme in pairs(luaset) do                               local count2 = 0 for _,champsetid in pairs(jsonskins[tostring(skinid)]["skinLines"]) do                                   local jsonset      = setids[champsetid.id] if subtheme == jsonset then count2 = 1 end end if count2 == 0 then s = s .. "\n* " .. skinid .. " " .. luaname .. " > " .. subtheme .. " Unoffical Set Added" end end else for _, subtheme in pairs(luaset) do                               s = s .. "\n* " .. skinid .. " " .. luaname .. " > " .. subtheme .. " Unoffical Set Added" end end else if champsetid ~= nil and champsetid ~= "null" then for _,champsetid in pairs(jsonskins[tostring(skinid)]["skinLines"]) do                               local jsonset      = setids[champsetid.id] s = s .. "\n* " .. skinid .. " " .. luaname .. " > " .. jsonset .. " Set Missing" end end end end end end end if s == "" then return "All champion skins are synchronized." else return "The following champion skins are not synchronized:" .. s   end end

function p.get(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local theme  = args['theme']   or args[1] local link   = args['link']    or args[2] local exclude = mw.title.getCurrentTitle.rootText if theme == nil then return userError("You must input a theme in the first parameter", "LuaError") end local skintable    = {} local resulttable  = {} local set_to_universe     = {} for universename, universedata in pairs(luauniverseData) do       for _, universeset in pairs(universedata) do            set_to_universe[universeset] = universename if universeset == theme and link == nil then link = universename end end end

for championname in pairs(luaskinData) do       if championname ~= exclude then local t = luaskinData[championname]["skins"] for skinname in pairs(t) do               if t[skinname]["id"] ~= nil and t[skinname]["release"] ~= "N/A" then local luatheme = t[skinname]["set"] if luatheme ~= nil then for _, subtheme in pairs(luatheme) do                           if subtheme == theme or set_to_universe[subtheme] == theme then if resulttable[skinname] == nil then resulttable[skinname] = {} table.insert(skintable, skinname) end table.insert(resulttable[skinname], championname) break end end end end end end end table.sort(skintable,orderup) local s = "" for _, skinname in pairs(skintable) do       table.sort(resulttable[skinname],orderup) for _, championname in pairs(resulttable[skinname]) do           s = s .. "\n**" .. csl(championname, skinname) end end if s == "" then return userError("No champion skins found for the theme: " .. theme, "LuaError") else return "* This skin theme is shared with: " .. s   end end

-- HELPER FUNCTIONS:

function csl(champion, skin) return tostring(IL.skin{           ["champion"] = champion,            ["skin"]     = skin,            ["link"]     = champion .. "/Skins",            ["circle"]   = "true"        }) end

function orderup(a,b) a = string.lower(a) b = string.lower(b) if a == 'n/a' then return false end if b == 'n/a' then return true end return b > a end

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

return p --