Module:HeroDataArrays

Revision as of 06:10, 18 October 2024 by SerpentofSet (talk | contribs) (start hero data grabber)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 = {}

for heroKey, heroData in pairs(allHeroData) do
	if heroData["IsDisabled"] == false and heroData["InDevelopment"] == false then
		table.insert(inGameHeroData, heroData)
	end
end

local p = {}

p.heroDataArray = function(frame)
	local outData = {}
	
	for i, heroData in ipairs(inGameHeroData) do
		local out = {}
		for j, keyPath in pairs(frame.args) do
			if type(keyPath)=="table" then 
				local node = heroData
				for k, key in pairs(keyPath) do
					node = node[key]
				end
				out[table.concat(keyPath,"")] = node
			else
				out[keyPath] = heroData[keyPath]
			end
		end
		outData[heroData["Name"]] = out
	end
	return(outData)
end

--=p.heroDataArray{args={"Name", "MaxHealth", "{LevelScaling, Health}"}}

return p