Module:SkinThemes

-- local p   = {}

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

function p.test(frame) local s = "" for championname,cdata in pairs(luaskinData) do       if s ~= "" then s = s .. " "       end s = s .. "[https://leagueoflegends.fandom.com/wiki/" .. string.gsub(championname," ","_") .. "/Trivia?action=edit " .. championname .. "] [https://leagueoflegends.fandom.com/wiki/" .. string.gsub(championname," ","_") .. "/Trivia?action=history history]" end return s end function p.officialtable(frame) local jsonskins    = jsontolua("Template:Set/skins.json") local jsonsets     = jsontolua("Template:Set/sets.json") local jsonuniverses = jsontolua("Template:Set/universes.json") local setnames     = {} local resulttable  = {} local skintable    = {} local setids       = {} local universenames = {} local universeids  = {} local s            = "" s = s .. ' ' end

function p.synchronize(frame) local jsonskins    = jsontolua("Template:Set/skins.json") local s            = ""

for championname, cdata in pairs(luaskinData) do       for skinname, sdata in pairs(cdata["skins"]) do            if sdata["id"] ~= nil 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 = jsonname.name 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 end end end end if s == "" then return "All champion skin ids and skin names are synchronized." else return "The following champion skins are not synchronized:" .. s   end end

function p.lore(frame) local jsonskins    = jsontolua("Template:Set/skins.json") local s            = ""

for championname, cdata in pairs(luaskinData) do       for skinname, sdata in pairs(cdata["skins"]) do            if sdata["id"] ~= nil then if skinname ~= "Original" then local luaname = sdata["formatname"] or (skinname .. " " .. championname) local skinid  = cdata["id"] * 1000 + sdata["id"] local jsonname = jsonskins[tostring(skinid)] if jsonname ~= nil then jsonname = jsonname.name or "nil" end if championname == "Nunu" and skinname == "Original" then luaname = "Nunu & Willump" end if luaname == jsonname then if sdata["lore"] ~= jsonskins[tostring(skinid)]["description"] then s = s .. "\n* " .. skinid .. " " .. luaname end end end end end end if s == "" then return "All lores are synchronized." else return "The following lores are not synchronized:" .. s   end end

function p.missing(frame) local luauniverseData = mw.loadData('Module:SkinData/universes') local jsonskins    = jsontolua("Template:Set/skins.json") local jsonsets     = jsontolua("Template:Set/sets.json") local jsonuniverses = jsontolua("Template:Set/universes.json") local setids       = {} local setdata      = {} local s            = "" for _, setdata in pairs(jsonsets) do       setids[setdata.id] = setdata.name or "nil" 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 championname, cdata in pairs(luaskinData) do       for skinname, sdata in pairs(cdata["skins"]) do            if sdata["id"] ~= nil 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 setid = jsonname.skinLines jsonname = jsonname.name or "nil" end if championname == "Nunu" and skinname == "Original" then luaname = "Nunu & Willump" end if luaname == jsonname then local luaset = sdata["set"] if luaset ~= nil then if setid ~= nil and setid ~= "null" then for _,champsetid in pairs(setid) do                               local jsonset      = setids[champsetid.id] or "nil" 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 .. " " .. csl(championname,skinname) .. " > " .. jsonset .. " Set Missing" end end end else if setid ~= nil and setid ~= "null" then for _,champsetid in pairs(setid) do                               local jsonset      = setids[champsetid.id] or "nil" s = s .. "\n* " .. skinid .. " " .. csl(championname,skinname) .. " > " .. jsonset .. " Set Missing" end end 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 luauniverseData = mw.loadData('Module:SkinData/universes') local jsonskins    = jsontolua("Template:Set/skins.json") local jsonsets     = jsontolua("Template:Set/sets.json") local jsonuniverses = jsontolua("Template:Set/universes.json") local setids       = {} local setdata      = {} local s            = "" for _, setdata in pairs(jsonsets) do       setids[setdata.id] = setdata.name or "nil" 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 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* " .. luasetname .. " Unofficial Set Added In " .. luauniversename .. " 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 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 setid = jsonname.skinLines jsonname = jsonname.name or "nil" end if championname == "Nunu" and skinname == "Original" then luaname = "Nunu & Willump" end if luaname == jsonname then local luaset = sdata["set"] if luaset ~= nil then if setid ~= nil and setid ~= "null" then for _, subtheme in pairs(luaset) do                               local count2 = 0 for _,champsetid in pairs(setid) do                                   local jsonset      = setids[champsetid.id] or "nil" if subtheme == jsonset then count2 = 1 end end if count2 == 0 then s = s .. "\n* " .. skinid .. " " .. csl(championname,skinname) .. " > " .. subtheme .. " Unoffical Set Added" end end else for _, subtheme in pairs(luaset) do                               s = s .. "\n* " .. skinid .. " " .. csl(championname,skinname) .. " > " .. subtheme .. " Unoffical 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 function p.get(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local luauniverseData = mw.loadData('Module:SkinData/universes') local theme  = {} theme[1]= args['theme']  or args[1] local lualinkData   = mw.loadData('Module:SkinData/setlinks') local link local exclude = args["exclude"] or "nil" local inputskinname local themeexists 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 end end if theme[1] ~= nil then if luaskinData[exclude] ~= nil then local t = luaskinData[exclude]["skins"] for skinname,sdata in pairs(t) do               if sdata["id"] ~= nil then if theme[1] == skinname then local luatheme = sdata["set"] if luatheme ~= nil then inputskinname = theme[1] theme[1] = nil for _,skintheme in pairs(luatheme) do                               themeexists = 1 for _,tabletheme in pairs (theme) do                                   if set_to_universe[skintheme] == tabletheme or skintheme == tabletheme then themeexists = 0 end end if themeexists == 1 then table.insert(theme,skintheme) end end else theme = nil end break end end end end end if theme == nil then return "" end local s = "" for tableindex,tabletheme in pairs (theme) do       for championname,cdata in pairs(luaskinData) do            local t = cdata["skins"] for skinname,sdata in pairs(t) do               if sdata["id"] ~= nil and (inputskinname == nil or (inputskinname ~= nil and (skinname .. " " .. championname) ~= (inputskinname .. " " .. exclude))) then local luatheme = sdata["set"] if luatheme ~= nil then for _, subtheme in pairs(luatheme) do                           if subtheme == tabletheme or subtheme == set_to_universe[tabletheme] or set_to_universe[subtheme] == tabletheme or (set_to_universe[tabletheme] ~= nil and set_to_universe[subtheme] == set_to_universe[tabletheme]) 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 table.sort(skintable,orderup) local s2 = "" for _, skinname in pairs(skintable) do           table.sort(resulttable[skinname],orderup) for _, championname in pairs(resulttable[skinname]) do               s2 = s2 .. "\n**" .. csl(championname, skinname) end end if s2 ~= "" then link = nil if lualinkData[tabletheme] ~= nil or (set_to_universe[tabletheme] ~= nil and lualinkData[set_to_universe[tabletheme]] ~= nil) then for _,lualink in pairs (lualinkData[tabletheme] or lualinkData[set_to_universe[tabletheme]]) do                   link = lualink end end if tableindex == 1 then s = s .. "\n* This skin " else s = s .. "\n* It also " end s = s .. "shares the " if link ~= "false" then s = s .. "" .. string.gsub(link or set_to_universe[tabletheme] or tabletheme, ": ", "/") .. " " else s = s .. "'" .. tabletheme .. "' "           end s = s .. "theme with: " .. s2       end skintable      = {} resulttable    = {} end return s 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 --