Module:ChampionData

-- local p   = {} local lib      = require('Module:Feature') local userError = require('Dev:User error')

function p.get(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local get      = require ('Module:Sandbox2/getter') local champname = args['champname'] local stat     = args['stat'] return get[stat](champname) end

function p.main(frame) --local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local patchid     = "9.14.1" local o           = mw.loadData('Module:StatTable/data/' .. patchid) local s           = "" local championdata = {} for championname in pairs(o) do       table.insert(championdata, championname) end table.sort(championdata) -- ============================   -- = Generate lua data output = -- ============================   s = s .. '-- \n' s = s .. '-- Champion data for patch version: ' .. patchid .. '\n' s = s .. '\n' s = s .. 'return {\n'

for i, champname in pairs(championdata) do       local t = o[champname] -- StatTable data s = s .. ' ["' .. champname .. '"] = {\n' s = s .. '   ["id"]         = '  .. t['id']                           .. ',\n' s = s .. '   ["apiname"]    = "' .. t['apiname']                       .. '",\n' s = s .. '   ["title"]      = "' .. t['title']                         .. '",\n' s = s .. '   ["attack"]     = '  .. t['attack']                       .. ',\n' s = s .. '   ["defense"]    = '  .. t['defense']                      .. ',\n' s = s .. '   ["magic"]      = '  .. t['magic']                        .. ',\n' s = s .. '   ["difficulty"] = '  .. t['difficulty']                   .. ',\n' s = s .. '   ["herotype"]   = "'  .. t['herotype']                     .. '",\n' if t['alttype'] ~= nil then s = s .. '   ["alttype"]    = "'  .. t['alttype']                  .. '",\n' end s = s .. '   ["resource"]   = "'  .. t['resource']                     .. '",\n' s = s .. '   ["stats"] = {\n' s = s .. '     ["hp_base"]  = '  .. pst2(champname, "hp_base")        .. ',\n' s = s .. '     ["hp_lvl"]   = '  .. pst2(champname, "hp_lvl")        .. ',\n' s = s .. '     ["mp_base"]  = '  .. pst2(champname, "mp_base")        .. ',\n' s = s .. '     ["mp_lvl"]   = '  .. pst2(champname, "mp_lvl")        .. ',\n' s = s .. '     ["arm_base"] = '  .. pst2(champname, "arm_base")        .. ',\n' s = s .. '     ["arm_lvl"]  = '  .. pst2(champname, "arm_lvl")        .. ',\n' s = s .. '     ["mr_base"]  = '  .. pst2(champname, "mr_base")        .. ',\n' s = s .. '     ["mr_lvl"]   = '  .. pst2(champname, "mr_lvl")        .. ',\n' s = s .. '     ["hp5_base"] = '  .. pst2(champname, "hp5_base")        .. ',\n' s = s .. '     ["hp5_lvl"]  = '  .. pst2(champname, "hp5_lvl")        .. ',\n' s = s .. '     ["mp5_base"] = '  .. pst2(champname, "mp5_base")        .. ',\n' s = s .. '     ["mp5_lvl"]  = '  .. pst2(champname, "mp5_lvl")        .. ',\n' s = s .. '     ["dam_base"] = '  .. pst2(champname, "dam_base")        .. ',\n' s = s .. '     ["dam_lvl"]  = '  .. pst2(champname, "dam_lvl")        .. ',\n' s = s .. '     ["as_base"]  = '  .. pst2(champname, "as_base")        .. ',\n' as_lvl1 = pst2(champname, "as_lvl1") if as_lvl1 ~= "" then s = s .. '     ["as_lvl1"]  = '  .. pst2(champname, "as_lvl1")        .. ',\n' end as_lvl1 = pst2(champname, "as_lvl1_bonus") if as_lvl1 ~= "" then s = s .. '     ["as_lvl1_bonus"]  = '  .. pst2(champname, "as_lvl1_bonus")        .. ',\n' end s = s .. '     ["as_lvl"]   = '  .. t['stats']['as_lvl']              .. ',\n' s = s .. '     ["range"]    = '  .. t['stats']['range']               .. ',\n' s = s .. '     ["ms"]       = '  .. t['stats']['ms']                  .. '\n' s = s .. '   },\n' -- Additional data from champion data templates fullname = pst2(champname, "fullname") if fullname ~= "" then s = s .. '   ["fullname"]   = "' .. fullname                       .. '",\n' end nickname = pst2(champname, "nickname") if nickname ~= "" then s = s .. '   ["nickname"]   = "' .. nickname                       .. '",\n' end s = s .. '   ["rangetype"]   = "' .. pst2(champname, "rangetype")           .. '",\n' s = s .. '   ["date"]        = "' .. pst2(champname, "date")                .. '",\n' s = s .. '   ["patch"]       = "' .. pst2(champname, "patch")               .. '",\n' s = s .. '   ["changes"]     = "' .. pst2(champname, "changes")             .. '",\n' s = s .. '   ["role"]        = "' .. pst2(champname, "role")                .. '",\n' s = s .. '   ["damage"]      = '  .. pst2(champname, "damage")             .. ',\n' s = s .. '   ["toughness"]   = '  .. pst2(champname, "toughness")          .. ',\n' s = s .. '   ["control"]     = '  .. pst2(champname, "control")            .. ',\n' s = s .. '   ["mobility"]    = '  .. pst2(champname, "mobility")           .. ',\n' s = s .. '   ["utility"]     = '  .. pst2(champname, "utility")            .. ',\n' s = s .. '   ["style"]       = '  .. pst2(champname, "style")              .. ',\n' s = s .. '   ["adaptivetype"]= "' .. pst2(champname, "adaptivetype")        .. '",\n' s = s .. '   ["be"]          = '  .. pst2(champname, "be")                 .. ',\n' s = s .. '   ["rp"]          = '  .. pst2(champname, "rp")                 .. ',\n' s = s .. '   ["skill_i"]     = {' .. strtoluadata(pst2(champname, "skill_i"), ";") .. '},\n' s = s .. '   ["skill_q"]     = {' .. strtoluadata(pst2(champname, "skill_q"), ";") .. '},\n' s = s .. '   ["skill_w"]     = {' .. strtoluadata(pst2(champname, "skill_w"), ";") .. '},\n' s = s .. '   ["skill_e"]     = {' .. strtoluadata(pst2(champname, "skill_e"), ";") .. '},\n' s = s .. '   ["skill_r"]     = {' .. strtoluadata(pst2(champname, "skill_r"), ";") .. '}\n' s = s .. ' }' .. lib.ternary(i ~= #championdata, ',\n','\n') end

s = s .. '}\n' s = s .. '-- \n' -- pre needs to be splitted with .. cause of Lua weirdness -- s = s .. '-- '

return ' ' .. mw.text.nowiki(s) .. ' ' end

function p.main2(frame) --local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local patchid     = "9.14.1" local o           = mw.loadData('Module:StatTable/data/' .. patchid) local s           = "" local championdata = {} for championname in pairs(o) do       table.insert(championdata, championname) end table.sort(championdata) -- ============================   -- = Generate lua data output = -- ============================   s = s .. '-- \n' s = s .. '-- Champion data for patch version: ' .. patchid .. '\n' s = s .. '\n' s = s .. 'return {\n'

for i, champname in pairs(championdata) do       local t = o[champname] -- StatTable data s = s .. ' ["' .. champname .. '"] = {\n' s = s .. '   ["id"]         = '  .. t['id']                           .. ',\n' s = s .. '   ["apiname"]    = "' .. t['apiname']                       .. '",\n' s = s .. '   ["title"]      = "' .. t['title']                         .. '",\n' s = s .. '   ["attack"]     = '  .. t['attack']                       .. ',\n' s = s .. '   ["defense"]    = '  .. t['defense']                      .. ',\n' s = s .. '   ["magic"]      = '  .. t['magic']                        .. ',\n' s = s .. '   ["difficulty"] = '  .. t['difficulty']                   .. ',\n' s = s .. '   ["herotype"]   = "'  .. t['herotype']                     .. '",\n' if t['alttype'] ~= nil then s = s .. '   ["alttype"]    = "'  .. t['alttype']                  .. '",\n' end s = s .. '   ["resource"]   = "'  .. t['resource']                     .. '",\n' s = s .. '   ["stats"] = {\n' s = s .. '     ["hp_base"]  = '  .. t['stats']['hp_base']             .. ',\n' s = s .. '     ["hp_lvl"]   = '  .. t['stats']['hp_lvl']              .. ',\n' s = s .. '     ["mp_base"]  = '  .. t['stats']['mp_base']             .. ',\n' s = s .. '     ["mp_lvl"]   = '  .. t['stats']['mp_lvl']              .. ',\n' s = s .. '     ["arm_base"] = '  .. t['stats']['arm_base']            .. ',\n' s = s .. '     ["arm_lvl"]  = '  .. t['stats']['arm_lvl']             .. ',\n' s = s .. '     ["mr_base"]  = '  .. t['stats']['mr_base']             .. ',\n' s = s .. '     ["mr_lvl"]   = '  .. t['stats']['mr_lvl']              .. ',\n' s = s .. '     ["hp5_base"] = '  .. t['stats']['hp5_base']            .. ',\n' s = s .. '     ["hp5_lvl"]  = '  .. t['stats']['hp5_lvl']             .. ',\n' s = s .. '     ["mp5_base"] = '  .. t['stats']['mp5_base']            .. ',\n' s = s .. '     ["mp5_lvl"]  = '  .. t['stats']['mp5_lvl']             .. ',\n' s = s .. '     ["dam_base"] = '  .. t['stats']['dam_base']            .. ',\n' s = s .. '     ["dam_lvl"]  = '  .. t['stats']['dam_lvl']             .. ',\n' s = s .. '     ["as_base"]  = '  .. pst2(champname, "as_base")        .. ',\n' if t['stats']['as_lvl1'] ~= nil then s = s .. '     ["as_lvl1"]  = '     .. t['stats']['as_lvl1']      .. ',\n' end if t['stats']['attack_delay'] ~= nil then s = s .. '     ["attack_delay"] = ' .. t['stats']['attack_delay'] .. ',\n' end s = s .. '     ["as_lvl"]   = '  .. t['stats']['as_lvl']              .. ',\n' s = s .. '     ["range"]    = '  .. pst2(champname, "range")          .. ',\n' s = s .. '     ["ms"]       = '  .. pst2(champname, "ms")             .. '\n' s = s .. '   },\n' -- Additional data from champion data templates fullname = pst2(champname, "fullname") if fullname ~= "" then s = s .. '   ["fullname"]   = "' .. fullname                       .. '",\n' end nickname = pst2(champname, "nickname") if nickname ~= "" then s = s .. '   ["nickname"]   = "' .. nickname                       .. '",\n' end s = s .. '   ["rangetype"]   = "' .. pst2(champname, "rangetype")           .. '",\n' s = s .. '   ["date"]        = "' .. pst2(champname, "date")                .. '",\n' s = s .. '   ["patch"]       = "' .. pst2(champname, "patch")               .. '",\n' s = s .. '   ["changes"]     = "' .. pst2(champname, "changes")             .. '",\n' s = s .. '   ["role"]        = "' .. pst2(champname, "role")                .. '",\n' s = s .. '   ["damage"]      = '  .. pst2(champname, "damage")             .. ',\n' s = s .. '   ["toughness"]   = '  .. pst2(champname, "toughness")          .. ',\n' s = s .. '   ["control"]     = '  .. pst2(champname, "control")            .. ',\n' s = s .. '   ["mobility"]    = '  .. pst2(champname, "mobility")           .. ',\n' s = s .. '   ["utility"]     = '  .. pst2(champname, "utility")            .. ',\n' s = s .. '   ["style"]       = '  .. pst2(champname, "style")              .. ',\n' s = s .. '   ["adaptivetype"]= "' .. pst2(champname, "adaptivetype")        .. '",\n' s = s .. '   ["be"]          = '  .. pst2(champname, "be")                 .. ',\n' s = s .. '   ["rp"]          = '  .. pst2(champname, "rp")                 .. ',\n' s = s .. '   ["skill_i"]     = {' .. strtoluadata(pst2(champname, "skill_i"), ";") .. '},\n' s = s .. '   ["skill_q"]     = {' .. strtoluadata(pst2(champname, "skill_q"), ";") .. '},\n' s = s .. '   ["skill_w"]     = {' .. strtoluadata(pst2(champname, "skill_w"), ";") .. '},\n' s = s .. '   ["skill_e"]     = {' .. strtoluadata(pst2(champname, "skill_e"), ";") .. '},\n' s = s .. '   ["skill_r"]     = {' .. strtoluadata(pst2(champname, "skill_r"), ";") .. '}\n' s = s .. ' }' .. lib.ternary(i ~= #championdata, ',\n','\n') end

s = s .. '}\n' s = s .. '-- \n' -- pre needs to be splitted with .. cause of Lua weirdness -- s = s .. '-- '

return ' ' .. mw.text.nowiki(s) .. ' ' end

-- -- local funtions --

function strtoluadata(str, sep) x = mw.text.split(str, sep) i=1 s = '[' .. i .. '] = "' .. mw.text.trim(x[i]) .. '"' i = i +1 while i <= #x do       s = s .. ', [' .. i .. '] = "' .. mw.text.trim(x[i]) .. '"' i = i + 1 end return s end

function pst2(champion, stat) local frame = mw.getCurrentFrame return frame:expandTemplate{ title = 'Data ' .. champion, args = {'pst2', stat} } end

function loadData(patchid) if exists('Module:StatTable/data/' .. patchid) then return mw.loadData('Module:StatTable/data/' .. patchid) end return nil end function exists(page) local sPage = page if sPage then local _, val = pcall(package.loaders[2], sPage) if type(val) == "function" or type(val) == "string" then return true end end return false end

return p -- --