Module:AbilityData: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Saag (talk | contribs)
added more attrs
Saag (talk | contribs)
Formatted effect values
Line 1: Line 1:
local p = {};
local p = {}
local data = mw.loadJsonData("Data:HeroData.json")
local data = mw.loadJsonData("Data:HeroData.json")


-- returns the table of a specific item
-- returns the table of a specific item
function get_ability(hero_name, ability_number)
function get_ability(hero_name, ability_number)
for i,v in pairs(data) do
for i, v in pairs(data) do
if (v["Name"] == hero_name) then
if v["Name"] == hero_name then
return v["BoundAbilities"][tonumber(ability_number)]
return v["BoundAbilities"][tonumber(ability_number)]
end
end
Line 14: Line 14:
--{{#invoke:AbilityData|get_ability_card|HERO_NAME|ABILITY_NUMBER}}--
--{{#invoke:AbilityData|get_ability_card|HERO_NAME|ABILITY_NUMBER}}--
p.get_ability_card = function(frame)
p.get_ability_card = function(frame)
    local hero_name = frame.args[1]
local hero_name = frame.args[1]
    local ability_num = frame.args[2]
local ability_num = frame.args[2]


    local ability = get_ability(hero_name, ability_num)
local ability = get_ability(hero_name, ability_num)
    if ability then
if ability then
        -- Pass the table fields to the template
-- Pass the table fields to the template
        local width_key = find_width_key(ability)
local width_key = find_width_key(ability)
local used_keys = {
local used_keys = {
'Description', 'Radius', 'AbilityCastRange', 'AbilityDuration',
'Description', 'Radius', 'AbilityCastRange', 'AbilityDuration',
'AbilityDuration', 'AbilityCooldown', 'Upgrades', width_key
'AbilityDuration', 'AbilityCooldown', 'Upgrades', width_key
}
}
 
local effects = get_effects(ability, used_keys)
local effects = get_effects(ability, used_keys)
-- return used_keys[1]
 
        return frame:expandTemplate{
return frame:expandTemplate{
            title = "Ability card",
title = "Ability card",
            args = {
args = {
                name = ability.Name,
name = ability.Name,
                description = ability.Description,
description = ability.Description,
                radius = ability.Radius,
radius = ability.Radius,
                range       = ability.AbilityCastRange,
range = ability.AbilityCastRange,
                ability_width = ability[width_key],
ability_width = ability[width_key],
                duration = ability.AbilityDuration,
duration = ability.AbilityDuration,
                cooldown = ability.AbilityCooldown,
cooldown = ability.AbilityCooldown,
effect1 = effects[1],
effect1 = effects[1],
effect2 = effects[2],
effect2 = effects[2],
effect3 = effects[3],
effect3 = effects[3],
effect4 = effects[4],
effect4 = effects[4],
effect5 = effects[5],
effect5 = effects[5],
effect6 = effects[6],
effect6 = effects[6],
effect7 = effects[7],
effect7 = effects[7],
effect8 = effects[8],
effect8 = effects[8],
effect9 = effects[9],
effect9 = effects[9],
                upgrade1 = ability.Upgrades[1].Description,
upgrade1 = ability.Upgrades[1].Description,
                upgrade2 = ability.Upgrades[2].Description,
upgrade2 = ability.Upgrades[2].Description,
                upgrade3 = ability.Upgrades[3].Description
upgrade3 = ability.Upgrades[3].Description
            }
}
        }
}
    else
else
    return "Ability data not found for hero " .. hero_name .. " and num " .. ability_num
return "Ability data not found for hero " .. hero_name .. " and num " .. ability_num
    end
end
end
end


function get_effects(ability, used_keys)
function get_effects(ability, used_keys)
    effects = {}
effects = {}
    for key, value in pairs(ability) do
for key, value in pairs(ability) do
    if not string_in_list(key, used_keys) then
if not string_in_list(key, used_keys) then
local effect_value = string.format("'''%s''': %s", key, value)
table.insert(effects, effect_value)
table.insert(effects, effect_value)
end
end
    end
end
return effects
return effects
end
end


function find_width_key(ability)
function find_width_key(ability)
    for key, value in pairs(ability) do
for key, value in pairs(ability) do
        if type(key) == "string" and key:sub(-5) == "Width" then
if type(key) == "string" and key:sub(-5) == "Width" then
            return key, value
return key
        end
end
    end
end
    return nil
return nil
end
end


function string_in_list(str, list)
function string_in_list(str, list)
    for _, value in ipairs(list) do
for _, value in ipairs(list) do
        if value == str then
if value == str then
            return true
return true
        end
end
    end
end
    return false
return false
end
end


return p
return p

Revision as of 23:59, 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
		local width_key = find_width_key(ability)
		local used_keys = {
			'Description', 'Radius', 'AbilityCastRange', 'AbilityDuration',
			'AbilityDuration', 'AbilityCooldown', 'Upgrades', width_key
		}

		local effects = get_effects(ability, used_keys)

		return frame:expandTemplate{
			title = "Ability card",
			args = {
				name = ability.Name,
				description = ability.Description,
				radius = ability.Radius,
				range = ability.AbilityCastRange,
				ability_width = ability[width_key],
				duration = ability.AbilityDuration,
				cooldown = ability.AbilityCooldown,
				effect1 = effects[1],
				effect2 = effects[2],
				effect3 = effects[3],
				effect4 = effects[4],
				effect5 = effects[5],
				effect6 = effects[6],
				effect7 = effects[7],
				effect8 = effects[8],
				effect9 = effects[9],
				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

function get_effects(ability, used_keys)
	effects = {}
	for key, value in pairs(ability) do
		if not string_in_list(key, used_keys) then
			local effect_value = string.format("'''%s''': %s", key, value)
			table.insert(effects, effect_value)
		end
	end
	return effects
end

function find_width_key(ability)
	for key, value in pairs(ability) do
		if type(key) == "string" and key:sub(-5) == "Width" then
			return key
		end
	end
	return nil
end

function string_in_list(str, list)
	for _, value in ipairs(list) do
		if value == str then
			return true
		end
	end
	return false
end

return p