Module:Sandbox/AnataBakka2

-- 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.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 exclude = args['exclude'] or args[2] 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 setstable = {} for _, setdata in pairs(jsonsets) do       setstable[setdata.id] = setdata.name end local universestable = {} for _, universedata in pairs(jsonuniverses) do       for _, setid in pairs(universedata.skinSets) do            universestable[setid] = universedata.name end end local championtable = {} local resulttable  = {} 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 setid = jsonskins[tostring(skinid)]["skinLines"] if setid ~= nil and setid ~= "null" then setid   = jsonskins[tostring(skinid)]["skinLines"][1]["id"] set     = setstable[setid] universe = universestable[setid] if set == theme or universe == theme then if resulttable[championname] == nil then resulttable[championname] = {} table.insert(championtable, championname) end table.insert(resulttable[championname], skinname) else local luatheme = t[skinname]["theme"] if luatheme ~= nil then if type(luatheme) == "string" then if luatheme == theme then if resulttable[championname] == nil then resulttable[championname] = {} table.insert(championtable, championname) end table.insert(resulttable[championname], skinname) end else for _, subtheme in pairs(luatheme) do                                       if subtheme == theme then if resulttable[championname] == nil then resulttable[championname] = {} table.insert(championtable, championname) end table.insert(resulttable[championname], skinname) end end end end end end end end end end table.sort(championtable) local s = "" for _, championname in pairs(championtable) do       table.sort(resulttable[championname]) for _, skinname in pairs(resulttable[championname]) 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 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 --