Module:AbilityData

Revision as of 21:09, 13 September 2024 by Saag (talk | contribs) (load data from HeroData.json)

Deprecated

This module is being replaced by multiple modules in Module:Abilities. Any new functions should be created there


local p = {};
local data = mw.loadJsonData("Data:HeroData.json")

-- returns the table of a specific item
function get_ability(hero_name, ability_number)
	for i,v in pairs(data) do
		if (v["Name"] == hero_name) then
			return v["BoundAbilities"][tonumber(ability_number)]
		end
	end
	return nil
end

--{{#invoke:AbilityData|get_ability_card|HERO_NAME|ABILITY_NUMBER}}--
p.get_ability_card = function(frame)
    local hero_name = frame.args[1]
    local ability_num = frame.args[2]

    local ability = get_ability(hero_name, ability_num)

    if ability then
        -- Pass the table fields to the template
        return frame:expandTemplate{
            title = "Ability card",
            args = {
                name = ability.Name,
                duration = ability.AbilityDuration,
                cooldown = ability.AbilityCooldown,
                description = ability.Description,
                -- effect1 = ability.effect1,
                -- effect2 = ability.effect2,
                upgrade1 = ability.Upgrades[1].Description,
                upgrade2 = ability.Upgrades[2].Description,
                upgrade3 = ability.Upgrades[3].Description
            }
        }
    else
    	return "Ability data not found for hero " .. hero_name .. " and num " .. ability_num
    end
end

return p