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.skinsnumber(frame) local s="" local resulttable={} local prices={} local limited=0 local rare=0 local total=0 for championname in pairs(luaskinData) do       local t = luaskinData[championname]["skins"] for skinname in pairs(t) do           if skinname~="Original" and t[skinname]["id"] ~= nil and t[skinname]["release"] ~= "N/A" then if t[skinname]["availability"]=="Limited" then limited=limited+1 total=total+1 else local price=t[skinname]["cost"] if price==10 or price==100 then price=2450 end if t[skinname]["availability"]=="Rare" and price~=2450 then rare=rare+1 total=total+1 else if resulttable[price]==nil then resulttable[price]=0 table.insert(prices,price) end resulttable[price]=resulttable[price]+1 total=total+1 end end end end end table.sort(prices) for _,price in pairs(prices) do       s=s.."\n* "..price.."= "..resulttable[price].." skins" end s=s.."\n* Rare= "..rare.." skins" s=s.."\n* Limited= "..limited.." skins" s=s.."\n* Total= "..total.." skins" return "Number of skins for each price type: "..s end

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 s            = ""

for championname, cdata in pairs(luaskinData) do       for skinname, sdata in pairs(cdata["skins"]) do            if sdata["id"] ~= nil then local skinid  = cdata["id"] * 1000 + sdata["id"] local jsonname = jsonskins[tostring(skinid)] if jsonname~=nil then jsonname = jsonskins[tostring(skinid)]["name"] end 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)] if champsetid~=nil then champsetid = jsonskins[tostring(skinid)]["skinLines"] end 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,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

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