Module:HeroDataArrays: Difference between revisions
Jump to navigation
Jump to search
SerpentofSet (talk | contribs) start hero data grabber |
SerpentofSet (talk | contribs) No edit summary |
||
Line 3: | Line 3: | ||
local inGameHeroData = {} | local inGameHeroData = {} | ||
for | -- Just get heroes that are playable | ||
for i, heroData in pairs(allHeroData) do | |||
if heroData["IsDisabled"] == false and heroData["InDevelopment"] == false then | if heroData["IsDisabled"] == false and heroData["InDevelopment"] == false then | ||
table.insert(inGameHeroData, heroData) | table.insert(inGameHeroData, heroData) | ||
Line 11: | Line 12: | ||
local p = {} | local p = {} | ||
-- heroDataArray takes as arguments any keys or path of keys in the HeroData JSON, | |||
-- e.g. Name, MaxHealth or LevelScaling>Health. A path of keys should be specified | |||
-- as such, with the ">" character separating subsequent keys. | |||
--{{#invoke:HeroDataArrays|heroDataArray|...}} | |||
p.heroDataArray = function(frame) | p.heroDataArray = function(frame) | ||
local outData = {} | local outData = {} | ||
for i, heroData in ipairs(inGameHeroData) do | for i, heroData in ipairs(inGameHeroData) do -- Iterate over each hero | ||
local out = {} | local out = {} | ||
for j, | for j, key in pairs(frame.args) do | ||
if | if string.find(key, ">") ~= nil then -- If key is actually a path of keys, | ||
local node = heroData | local node = heroData -- starting with the biggest node heroData, | ||
for k, | for k in string.gmatch(key, "([^>]+)") do -- iterate over each key, | ||
node = node[ | _node = node[k] -- progressing down each node in the path, | ||
if _node == nil then -- trying the numeric index if the string | |||
_node = node[tonumber(k)] -- index fails. | |||
end | |||
node = _node | |||
end | end | ||
out[ | out[key] = node | ||
else | else | ||
out[ | out[key] = heroData[key] | ||
end | end | ||
end | end | ||
Line 31: | Line 40: | ||
return(outData) | return(outData) | ||
end | end | ||
return p | return p |
Revision as of 15:48, 18 October 2024
Overview
This module consists of one generic function, heroDataArray, and a series of functions that create specific wikitables using the output from heroDataArray.
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 and heroData["InDevelopment"] == false then
table.insert(inGameHeroData, heroData)
end
end
local p = {}
-- heroDataArray takes as arguments any keys or path of keys in the HeroData JSON,
-- e.g. Name, MaxHealth or LevelScaling>Health. A path of keys should be specified
-- as such, with the ">" character separating subsequent keys.
--{{#invoke:HeroDataArrays|heroDataArray|...}}
p.heroDataArray = function(frame)
local outData = {}
for i, heroData in ipairs(inGameHeroData) do -- Iterate over each hero
local out = {}
for j, key in pairs(frame.args) do
if string.find(key, ">") ~= nil then -- If key is actually a path of keys,
local node = heroData -- starting with the biggest node heroData,
for k in string.gmatch(key, "([^>]+)") do -- iterate over each key,
_node = node[k] -- progressing down each node in the path,
if _node == nil then -- trying the numeric index if the string
_node = node[tonumber(k)] -- index fails.
end
node = _node
end
out[key] = node
else
out[key] = heroData[key]
end
end
outData[heroData["Name"]] = out
end
return(outData)
end
return p