Module:HeroDataArrays: Difference between revisions
Appearance
SerpentofSet (talk | contribs) mNo edit summary |
Gammaton32 (talk | contribs) corrections |
||
(10 intermediate revisions by 2 users not shown) | |||
Line 7: | Line 7: | ||
-- Just get heroes that are playable | -- Just get heroes that are playable | ||
for i, heroData in pairs(allHeroData) do | for i, heroData in pairs(allHeroData) do | ||
if heroData["IsDisabled | if heroData["IsDisabled"] == false then | ||
table.insert(inGameHeroData, heroData) | table.insert(inGameHeroData, heroData) | ||
end | end | ||
Line 19: | Line 19: | ||
local outData = {} | local outData = {} | ||
for i, heroData in ipairs(inGameHeroData) do -- Iterate over each hero | for i, heroData in ipairs(inGameHeroData) do -- Iterate over each hero | ||
local out = {} | local out = {} -- First creating a table to hold data | ||
for j, key in pairs(args) do | for j, key in pairs(args) do -- Iterate over each key: | ||
if string.find(key, ">") ~= nil then -- If key is actually a path of keys, | if string.find(key, ">") ~= nil then -- If the key is actually a path of keys, | ||
local node = heroData -- | local node = heroData -- start with the biggest node heroData, and | ||
for k in string.gmatch(key, "([^>]+)") do -- iterate over each key, | for k in string.gmatch(key, "([^>]+)") do -- iterate over each key, splitting on ">", | ||
if node[k] ~= nil then -- trying the key as a string e.g. "1", | |||
node = node[k] | |||
else -- else using the key as numeric, | |||
end | node = node[tonumber(k)] | ||
end -- drilling down the JSON node after node | |||
end | end | ||
out[key] = node | out[key] = node -- until outputting the final node | ||
else | else | ||
out[key] = heroData[key] | out[key] = heroData[key] -- or just grab the data if not a path | ||
end | end | ||
end | end | ||
outData[heroData["Name"]] = out | outData[heroData["Name"]] = out -- Save data in the big table of heroes | ||
end | end | ||
return(outData) | return(outData) | ||
Line 42: | Line 42: | ||
p.heroHealthTable = function(frame) | p.heroHealthTable = function(frame) | ||
heroHealthData = heroDataArray({"Name", "MaxHealth", "LevelScaling> | -- Pull data | ||
heroHealthData = heroDataArray({"Name", "MaxHealth", "LevelScaling>MaxHealth"}) | |||
z = "{| class=\"wikitable sortable mw-collapsible\" \n".. | -- Input table will be called a, output wikitable will be called z | ||
-- From a to z, haha get it | |||
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n".. | |||
"|+ Hero Base Health Stats \n".. | "|+ Hero Base Health Stats \n".. | ||
"! Hero !! | "! Hero !! Starting !! Added per PI !! At Max PI \n" | ||
-- Iterate over heroes adding a new row to the wikitable for each | |||
for i,a in pairs(heroHealthData) do | for i,a in pairs(heroHealthData) do | ||
z = z.. | z = z.. | ||
"|- \n".. | "|- \n".. | ||
"| "..frame:expandTemplate{title="PageRef", args={a["Name"] | "| style=\"text-align:left;\" | ".. | ||
" || "..a["MaxHealth"].." || +"..a["LevelScaling> | frame:expandTemplate{title="PageRef", args={a["Name"]}}.. | ||
tostring(tonumber(a["MaxHealth"])+tonumber(a["LevelScaling> | " || "..a["MaxHealth"].." || +"..a["LevelScaling>MaxHealth"].." || ".. | ||
tostring(tonumber(a["MaxHealth"])+tonumber(a["LevelScaling>MaxHealth"])*14).." \n" | |||
end | end | ||
-- Cap it off | |||
z = z.."|}" | z = z.."|}" | ||
Line 61: | Line 67: | ||
end | end | ||
p.heroRegenTable = function(frame) | |||
heroRegenData = heroDataArray({"Name", "BaseHealthRegen"}) | |||
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n".. | |||
"|+ Hero Base Health Regen \n".. | |||
"! Hero !! HP/s \n" | |||
for i,a in pairs(heroRegenData) do | |||
z = z.. | |||
"|- \n".. | |||
"| style=\"text-align:left;\" | ".. | |||
frame:expandTemplate{title="PageRef", args={a["Name"]}}.. | |||
" || "..a["BaseHealthRegen"].." \n" | |||
end | |||
z = z.."|}" | |||
return z | |||
end | |||
p.heroDpsTable = function(frame) | |||
heroDpsData = heroDataArray({"Name","ReloadSingle","ReloadDelay","ReloadTime", | |||
"ClipSize","RoundsPerSecond","BulletDamage","BulletsPerShot"}) | |||
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n".. | |||
"|+ Hero Base Damage \n".. | |||
"! Hero !! Reload Delay (s) !! Reload Time (s) !! Ammo !! Bullets per sec !! Bullet Damage !! Bullets Per Shot \n" | |||
for i,a in pairs(heroDpsData) do | |||
z = z.. | |||
"|- \n".. | |||
"| style=\"text-align:left;\" | ".. | |||
frame:expandTemplate{title="PageRef", args={a["Name"]}}.. | |||
" || "..a["ReloadDelay"].." || "..a["ReloadTime"].." || "..a["ClipSize"].. | |||
" || "..a["RoundsPerSecond"].." || "..a["BulletDamage"].." || "..a["BulletsPerShot"].." \n" | |||
end | |||
z = z.."|}" | |||
return z | |||
end | |||
return p | return p |
Latest revision as of 16:15, 6 February 2025
Overview[edit source]
This module consists of one generic function, heroDataArray, and a series of functions that create specific wikitables using the output from heroDataArray.
local p = {}
local allHeroData = mw.loadJsonData("Data:HeroData.json")
local inGameHeroData = {}
-- Just get heroes that are playable
for i, heroData in pairs(allHeroData) do
if heroData["IsDisabled"] == false then
table.insert(inGameHeroData, heroData)
end
end
-- heroDataArray takes as argument a table of any length containing keys or
-- paths of keys in the HeroData JSON, e.g. {Name, MaxHealth, LevelScaling>Health}.
-- A path of keys should be specified as such, with the ">" character separating
-- subsequent keys.
local heroDataArray = function(args)
local outData = {}
for i, heroData in ipairs(inGameHeroData) do -- Iterate over each hero
local out = {} -- First creating a table to hold data
for j, key in pairs(args) do -- Iterate over each key:
if string.find(key, ">") ~= nil then -- If the key is actually a path of keys,
local node = heroData -- start with the biggest node heroData, and
for k in string.gmatch(key, "([^>]+)") do -- iterate over each key, splitting on ">",
if node[k] ~= nil then -- trying the key as a string e.g. "1",
node = node[k]
else -- else using the key as numeric,
node = node[tonumber(k)]
end -- drilling down the JSON node after node
end
out[key] = node -- until outputting the final node
else
out[key] = heroData[key] -- or just grab the data if not a path
end
end
outData[heroData["Name"]] = out -- Save data in the big table of heroes
end
return(outData)
end
p.heroHealthTable = function(frame)
-- Pull data
heroHealthData = heroDataArray({"Name", "MaxHealth", "LevelScaling>MaxHealth"})
-- Input table will be called a, output wikitable will be called z
-- From a to z, haha get it
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
"|+ Hero Base Health Stats \n"..
"! Hero !! Starting !! Added per PI !! At Max PI \n"
-- Iterate over heroes adding a new row to the wikitable for each
for i,a in pairs(heroHealthData) do
z = z..
"|- \n"..
"| style=\"text-align:left;\" | "..
frame:expandTemplate{title="PageRef", args={a["Name"]}}..
" || "..a["MaxHealth"].." || +"..a["LevelScaling>MaxHealth"].." || "..
tostring(tonumber(a["MaxHealth"])+tonumber(a["LevelScaling>MaxHealth"])*14).." \n"
end
-- Cap it off
z = z.."|}"
return z
end
p.heroRegenTable = function(frame)
heroRegenData = heroDataArray({"Name", "BaseHealthRegen"})
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
"|+ Hero Base Health Regen \n"..
"! Hero !! HP/s \n"
for i,a in pairs(heroRegenData) do
z = z..
"|- \n"..
"| style=\"text-align:left;\" | "..
frame:expandTemplate{title="PageRef", args={a["Name"]}}..
" || "..a["BaseHealthRegen"].." \n"
end
z = z.."|}"
return z
end
p.heroDpsTable = function(frame)
heroDpsData = heroDataArray({"Name","ReloadSingle","ReloadDelay","ReloadTime",
"ClipSize","RoundsPerSecond","BulletDamage","BulletsPerShot"})
z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
"|+ Hero Base Damage \n"..
"! Hero !! Reload Delay (s) !! Reload Time (s) !! Ammo !! Bullets per sec !! Bullet Damage !! Bullets Per Shot \n"
for i,a in pairs(heroDpsData) do
z = z..
"|- \n"..
"| style=\"text-align:left;\" | "..
frame:expandTemplate{title="PageRef", args={a["Name"]}}..
" || "..a["ReloadDelay"].." || "..a["ReloadTime"].." || "..a["ClipSize"]..
" || "..a["RoundsPerSecond"].." || "..a["BulletDamage"].." || "..a["BulletsPerShot"].." \n"
end
z = z.."|}"
return z
end
return p