Module:ChampionData

-- local p   = {} local lib      = require('Module:Feature') local json     = require('Module:JSON') local cmd      = require('Module:Maintenance data') local userError = require('Dev:User error') local IL       = require('Module:ImageLink')

local statsdata = { [1] = {"hp_base",      "hp"}, [2] = {"hp_lvl",       "hpperlevel"}, [3] = {"mp_base",      "mp"}, [4] = {"mp_lvl",       "mpperlevel"}, [5] = {"ms",           "movespeed"}, [6] = {"arm_base",     "armor"}, [7] = {"arm_lvl",      "armorperlevel"}, [8] = {"mr_base",      "spellblock"}, [9] = {"mr_lvl",       "spellblockperlevel"}, [10] = {"range",       "attackrange"}, [11] = {"hp5_base",    "hpregen"}, [12] = {"hp5_lvl",     "hpregenperlevel"}, [13] = {"mp5_base",    "mpregen"}, [14] = {"mp5_lvl",     "mpregenperlevel"}, [15] = {"dam_base",    "attackdamage"}, [16] = {"dam_lvl",     "attackdamageperlevel"}, [17] = {"attack_delay", "attackspeedoffset"}, [18] = {"as_lvl",      "attackspeedperlevel"}, [19] = {"as_lvl1",     "attackspeed"} }

function p.main(frame) -- local args -- if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local titleobject = mw.title.new(args[1]) local o           = json.decode(titleobject:getContent) local s           = "" local championdata = {} for jsonchampname in pairs(o['data']) do       table.insert(championdata, {jsonchampname, o['data'][jsonchampname]['name']}) end table.sort(championdata, function(a, b) return a[2] < b[2] end) --   -- Generate lua data output --   s = s .. '-- \n' s = s .. '-- Champion data for patch version: ' .. o['version'] .. '\n' s = s .. '\n' s = s .. 'return {\n'

for i, champname in pairs(championdata) do       local t = o['data'][champname[1]] s = s .. ' ["' .. t['name'] .. '"] = {\n' s = s .. '   ["id"]         = '  .. t['key']                           .. ',\n' s = s .. '   ["apiname"]    = "' .. t['id']                            .. '",\n' s = s .. '   ["title"]      = "' .. t['title']                         .. '",\n' s = s .. '   ["attack"]     = '  .. t['info']['attack']                .. ',\n' s = s .. '   ["defense"]    = '  .. t['info']['defense']               .. ',\n' s = s .. '   ["magic"]      = '  .. t['info']['magic']                 .. ',\n' s = s .. '   ["difficulty"] = '  .. t['info']['difficulty']            .. ',\n' s = s .. '   ["herotype"]   = "'  .. t['tags'][1]                      .. '",\n' if t['tags'][2] ~= nil then s = s .. '   ["alttype"]    = "'  .. t['tags'][2]                  .. '",\n' end s = s .. '   ["resource"]   = "'  .. t['partype']                      .. '",\n' s = s .. '   ["stats"] = {\n' s = s .. '     ["hp_base"]  = '  .. t['stats']['hp']                   .. ',\n' s = s .. '     ["hp_lvl"]   = '  .. t['stats']['hpperlevel']           .. ',\n' s = s .. '     ["mp_base"]  = '  .. t['stats']['mp']                   .. ',\n' s = s .. '     ["mp_lvl"]   = '  .. t['stats']['mpperlevel']           .. ',\n' s = s .. '     ["arm_base"] = '  .. t['stats']['armor']                .. ',\n' s = s .. '     ["arm_lvl"]  = '  .. t['stats']['armorperlevel']        .. ',\n' s = s .. '     ["mr_base"]  = '  .. t['stats']['spellblock']           .. ',\n' s = s .. '     ["mr_lvl"]   = '  .. t['stats']['spellblockperlevel']   .. ',\n' s = s .. '     ["hp5_base"] = '  .. t['stats']['hpregen']              .. ',\n' s = s .. '     ["hp5_lvl"]  = '  .. t['stats']['hpregenperlevel']      .. ',\n' s = s .. '     ["mp5_base"] = '  .. t['stats']['mpregen']              .. ',\n' s = s .. '     ["mp5_lvl"]  = '  .. t['stats']['mpregenperlevel']      .. ',\n' s = s .. '     ["dam_base"] = '  .. t['stats']['attackdamage']         .. ',\n' s = s .. '     ["dam_lvl"]  = '  .. t['stats']['attackdamageperlevel'] .. ',\n' if t['stats']['attackspeed'] ~= nil then s = s .. '     ["as_lvl1"]  = '     .. t['stats']['attackspeed']      .. ',\n' end if t['stats']['attackspeedoffset'] ~= nil then s = s .. '     ["attack_delay"] = ' .. t['stats']['attackspeedoffset'] .. ',\n' end s = s .. '     ["as_lvl"]   = '  .. t['stats']['attackspeedperlevel']  .. ',\n' s = s .. '     ["range"]    = '  .. t['stats']['attackrange']          .. ',\n' s = s .. '     ["ms"]       = '  .. t['stats']['movespeed']            .. '\n' s = s .. '   }\n' s = s .. ' }' .. lib.ternary(i ~= #championdata, ',\n','\n') end

s = s .. '}\n' s = s .. '-- \n' s = s .. '-- '   return 'Copy & paste data below to Module:StatTable/data/' .. o['version'] ..  ' ' .. mw.text.nowiki(s) .. ' Copy & paste data above to Module:StatTable/data/' .. o['version'] .. '' end

-- -- local funtions --

function pst2 local frame = mw.getCurrentFrame return frame:expandTemplate{ title = 'Data Annie', args = {'pst2', 'ms'} } end

return p -- --