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')

function p.officialtable(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local jsonskins    = jsontolua("User:AnataBakka/skins") local jsonsets     = jsontolua("User:AnataBakka/sets") local jsonuniverses = jsontolua("User:AnataBakka/universes") local s            = '{| class="wikitable"\n! width=20% | Universe Name\n! width=20% | Set Name\n! Skins' local setnames={} local resulttable={} local championtable={} local setids={} for _,setdata in pairs(jsonsets) do       setids[setdata.id]=setdata.name end local universenames={} local universeids={} for _,universedata in pairs(jsonuniverses) do       for _,setid in pairs(universedata.skinSets) do            universeids[setid]=universedata.name end end for championname in pairs(luaskinData) do       local t = luaskinData[championname]["skins"] for skinname in pairs(t) do           if t[skinname]["id"] ~= nil and t[skinname]["release"] ~= "N/A" then local skinid = luaskinData[championname]["id"] * 1000 + t[skinname]["id"] local champsetid = jsonskins[tostring(skinid)]["skinLines"] if champsetid ~= nil and champsetid ~= "null" then for _,champsetid in pairs(jsonskins[tostring(skinid)]["skinLines"]) do                        set=setids[champsetid] or "N/A" universe=universeids[champsetid] or "N/A" if resulttable[universe] == nil then resulttable[universe] = {} setnames[universe]={} table.insert(universenames,universe) end if resulttable[universe][set] == nil then resulttable[universe][set] = {} championtable[set]={} table.insert(championtable[set],championname) table.insert(setnames[universe],set) end resulttable[universe][set][championname]={} table.insert(resulttable[universe][set][championname], skinname) end end end end end table.sort(universenames) for _,universe in pairs(universenames) do       s=s..'\n|-\n! rowspan="'..#setnames[universe]..'" | '..universe table.sort(setnames[universe]) for index,set in pairs(setnames[universe]) do           if index~=1 then s=s.."\n|-" end s=s.."\n! "..set.."\n|" table.sort(championtable[set]) for _,champion in pairs(championtable[set]) do               for _,skin in pairs(resulttable[universe][set][champion]) do                    s=s.."\n* "..csl(champion, skin, frame) end end end end return s..'\n|}' end

function p.synchronize(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local jsonskins    = jsontolua("User:AnataBakka/skins") local jsonsets     = jsontolua("User:AnataBakka/sets") local jsonuniverses = jsontolua("User:AnataBakka/universes") local s            = ""

for championname, cdata in pairs(luaskinData) do       for skinname, sdata in pairs(cdata["skins"]) do            if sdata["id"] ~= nil and sdata["release"] ~= "N/A" then local skinid  = cdata["id"] * 1000 + sdata["id"] local jsonname = jsonskins[tostring(skinid)]["name"] local luaname = sdata["formatname"] or lib.ternary(skinname == "Original", championname, skinname .. " " .. championname) if championname == "Nunu" and skinname == "Original" then luaname = "Nunu & Willump" end if luaname ~= jsonname then s = s .. "\n* " .. skinid .. " " .. skinname .. " " .. championname 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] or nil local link   = args['link']    or args[2] or nil local exclude = args['exclude'] or args[3] or nil if theme == nil then return userError("You must input a theme in the first parameter", "LuaError") end local jsonskins    = jsontolua("User:AnataBakka/skins") local jsonsets     = jsontolua("User:AnataBakka/sets") local jsonuniverses = jsontolua("User:AnataBakka/universes") local setids={} local skintable = {} local resulttable  = {} for _, setdata in pairs(jsonsets) do       if setdata.name == theme then table.insert(setids, setdata.id) break end end for _, universedata in pairs(jsonuniverses) do       if universedata.name == theme or link==nil then for _, setid in pairs(universedata.skinSets) do               if link==nil then if setids[1]==setid then link=universedata.name end end if universedata.name == theme then table.insert(setids, setid) end end if universedata.name == theme then break 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 skinid = luaskinData[championname]["id"] * 1000 + t[skinname]["id"] local champsetid = jsonskins[tostring(skinid)]["skinLines"] local quit=false if champsetid ~= nil and champsetid ~= "null" then for _,setid in pairs(setids) do                           for _,champsetid in pairs(jsonskins[tostring(skinid)]["skinLines"]) do                                 if setid == champsetid.id then if resulttable[skinname] == nil then resulttable[skinname] = {} table.insert(skintable, skinname) end table.insert(resulttable[skinname], championname) quit = true break end end if quit == true then break end end end local luatheme = t[skinname]["set"] if luatheme ~= nil and quit ~= true then if type(luatheme) == "string" then if luatheme == theme then if resulttable[skinname] == nil then resulttable[skinname] = {} table.insert(skintable, skinname) end table.insert(resulttable[skinname], championname) end else for _, subtheme in pairs(luatheme) do                               if subtheme == theme then if resulttable[skinname] == nil then resulttable[skinname] = {} table.insert(skintable, skinname) end table.insert(resulttable[skinname], championname) end end end end end end end end table.sort(skintable) local s = "" for _, skinname in pairs(skintable) do       table.sort(resulttable[skinname]) for _, championname in pairs(resulttable[skinname]) do           s = s .. "\n**" .. csl(championname, skinname, frame) 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

function csl(champion, skin, frame) return frame:expandTemplate{ title = "csl", args = {champion, skin} } end

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

return p --