Module:AbilityData: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Saag (talk | contribs)
added more attrs
Saag (talk | contribs)
m Fixed get_ability_name
 
(97 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {};
local data = mw.loadJsonData("Data:AbilityCards.json")
local data = mw.loadJsonData("Data:HeroData.json")
 
local p = {}


-- 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_key, ability_num)
for i,v in pairs(data) do
local ui_data = data[hero_key]
if (v["Name"] == hero_name) then
if(ui_data == nil) then return "Hero Not Found" end
return v["BoundAbilities"][tonumber(ability_number)]
return ui_data[tonumber(ability_num)]
end
end
return nil
end
end


--{{#invoke:AbilityData|get_ability_card|HERO_NAME|ABILITY_NUMBER}}--
--{{#invoke:AbilityData|get_ability_name|HERO_NAME|ABILITY_NUM}}--
p.get_ability_card = function(frame)
p.get_ability_name = 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 == nil) then return "Ability Not Found" end
        -- Pass the table fields to the template
return ability.Name
        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 used_keys[1]
        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
end


function get_effects(ability, used_keys)
--Write's an ability link for a given ability name in english
    effects = {}
--Siphon Life --> Abrams#(1)_Siphon_Life
    for key, value in pairs(ability) do
function ability_to_hyperlink(ability_name_to_search)
    if not string_in_list(key, used_keys) then
if (ability_name_to_search == nil) then return "No ability name provided" end
table.insert(effects, effect_value)
local hero_name
local ability_name
-- Iterate heros
for hero_key, hero_data in pairs(data) do
-- Iterate abilities
hero_name = hero_data["Name"]
for ability_num, ability_data in pairs(hero_data) do
if (ability_num ~= "Name") then
ability_name = ability_data["Name"]
if (ability_name == ability_name_to_search) then
-- Ability number and hero found
-- "Siphon Life" > "Siphon_Life"
ability_name = ability_name:gsub(" ", "_")
return hero_name .. "#(" .. ability_num .. ")_" .. ability_name
end
end
end
end
    end
end
return effects
end
return nil
 
function find_width_key(ability)
    for key, value in pairs(ability) do
        if type(key) == "string" and key:sub(-5) == "Width" then
            return key, value
        end
    end
    return nil
end
end


function string_in_list(str, list)
--Writes an ability's icon from its name
    for _, value in ipairs(list) do
--Shoulder Charge --> [[File:Shoulder Charge.png|link=Abrams#(1)_Shoulder_Charge|size=20px]] [[Abrams...|Shoulder Charge]]
        if value == str then
p.write_ability_icon = function(frame)
            return true
local ability_name = frame.args[1]
        end
local custom_display_text = frame.args[2]
    end
if (custom_display_text == nil or custom_display_text == "") then custom_display_text = ability_name end
    return false
local size = 20
local hyperlink = ability_to_hyperlink(ability_name)
if (hyperlink == nil) then return "Ability " .. ability_name .. " not found" end
local icon = "[[File:" .. ability_name .. ".png|link=" .. hyperlink .. "|" .. size .. "px]]"
icon = '<span style="position: relative; bottom: 2px; filter: brightness(0) saturate(100%);">' .. icon .. '</span>'
local link = "[[" .. hyperlink .. "|" .. custom_display_text .. "]]"
return icon .. " " .. link
end
end


return p
return p

Latest revision as of 17:25, 26 October 2024

Deprecated[edit source]

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


local data = mw.loadJsonData("Data:AbilityCards.json")

local p = {}

-- returns the table of a specific item
function get_ability(hero_key, ability_num)
	local ui_data = data[hero_key]
	if(ui_data == nil) then return "Hero Not Found" end
	return ui_data[tonumber(ability_num)]
end

--{{#invoke:AbilityData|get_ability_name|HERO_NAME|ABILITY_NUM}}--
p.get_ability_name = function(frame)
	local hero_name = frame.args[1]
	local ability_num = frame.args[2]
	
	local ability = get_ability(hero_name, ability_num)
	if(ability == nil) then return "Ability Not Found" end
	return ability.Name
end

--Write's an ability link for a given ability name in english
--Siphon Life --> Abrams#(1)_Siphon_Life
function ability_to_hyperlink(ability_name_to_search)
	if (ability_name_to_search == nil) then return "No ability name provided" end
	local hero_name
	local ability_name
	
	-- Iterate heros
	for hero_key, hero_data in pairs(data) do
		-- Iterate abilities
		hero_name = hero_data["Name"]
		for ability_num, ability_data in pairs(hero_data) do
			if (ability_num ~= "Name") then
				ability_name = ability_data["Name"]
				if (ability_name == ability_name_to_search) then
					-- Ability number and hero found
					-- "Siphon Life" > "Siphon_Life"
					ability_name = ability_name:gsub(" ", "_")
					return hero_name .. "#(" .. ability_num .. ")_" .. ability_name
				end
			end
		end
	end
	
	return nil
end

--Writes an ability's icon from its name
--Shoulder Charge --> [[File:Shoulder Charge.png|link=Abrams#(1)_Shoulder_Charge|size=20px]] [[Abrams...|Shoulder Charge]]
p.write_ability_icon = function(frame)
	local ability_name = frame.args[1]
	local custom_display_text = frame.args[2]
	if (custom_display_text == nil or custom_display_text == "") then custom_display_text = ability_name end
	
	local size = 20
	
	local hyperlink = ability_to_hyperlink(ability_name)
	if (hyperlink == nil) then return "Ability " .. ability_name .. " not found" end
	
	local icon = "[[File:" .. ability_name .. ".png|link=" .. hyperlink .. "|" .. size .. "px]]"
	icon = '<span style="position: relative; bottom: 2px; filter: brightness(0) saturate(100%);">' .. icon .. '</span>'
	
	local link = "[[" .. hyperlink .. "|" .. custom_display_text .. "]]"
	
	return icon .. " " .. link
end

return p