Module:Abilities/icon

From Deadlock Wiki
Revision as of 16:47, 26 October 2024 by Saag (talk | contribs) (Created ability icon module from original Module:AbilityData)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Overview[edit source]

Searches for an icon based on the (English) name of the ability

Usage[edit source]

Template:AbilityIcon

Submodules[edit source]

Abilities - Simple functions. Eg. getting ability name

Abilities/utils - Common internal functions that are shared amongst any Abilities/ modules

Abilities/card - Generates hero ability cards

Abilities/icon - Searches for an icon based on the (English) name of the ability

Abilities/details table (WIP) - Generates details table to show raw ability data


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

local p = {}

--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