Module:AbilityData: Difference between revisions
Jump to navigation
Jump to search
build ability card template inside script |
load data from HeroData.json |
||
Line 1: | Line 1: | ||
local p = {}; | local p = {}; | ||
local data = mw.loadJsonData("Data: | local data = mw.loadJsonData("Data:HeroData.json") | ||
-- returns the table of a specific item | -- returns the table of a specific item | ||
function | function get_ability(hero_name, ability_number) | ||
for i,v in pairs(data) do | for i,v in pairs(data) do | ||
if (v["Name"] == | if (v["Name"] == hero_name) then | ||
return v | return v["BoundAbilities"][tonumber(ability_number)] | ||
end | end | ||
end | end | ||
Line 12: | Line 12: | ||
end | 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) | |||
local ability = | |||
if ability then | if ability then | ||
Line 36: | Line 24: | ||
title = "Ability card", | title = "Ability card", | ||
args = { | args = { | ||
name = ability. | name = ability.Name, | ||
duration = ability. | duration = ability.AbilityDuration, | ||
cooldown = ability. | cooldown = ability.AbilityCooldown, | ||
description = ability. | description = ability.Description, | ||
effect1 = ability.effect1, | -- effect1 = ability.effect1, | ||
effect2 = ability.effect2, | -- effect2 = ability.effect2, | ||
upgrade1 = ability. | upgrade1 = ability.Upgrades[1].Description, | ||
upgrade2 = ability. | upgrade2 = ability.Upgrades[2].Description, | ||
upgrade3 = ability. | upgrade3 = ability.Upgrades[3].Description | ||
} | } | ||
} | } | ||
else | else | ||
return "Ability data not found for hero " .. hero_name .. " and num " .. ability_num | |||
end | end | ||
end | end | ||
return p | return p |
Revision as of 21:09, 13 September 2024
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