Module:Abilities/utils: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Saag (talk | contribs)
No edit summary
Saag (talk | contribs)
No edit summary
Line 1: Line 1:
local p = {}
local data = mw.loadJsonData("Data:AbilityCards.json")
local data = mw.loadJsonData("Data:AbilityCards.json")


-- returns the table of a specific item
-- returns the table of a specific item
function get_ability_card_data(hero_name, ability_num)
function p.get_ability_card_data(hero_name, ability_num)
local hero_key = get_hero_key(hero_name)
local hero_key = get_hero_key(hero_name)
if(hero_key == nil) then return "Hero Not Found" end
if(hero_key == nil) then return "Hero Not Found" end
Line 8: Line 10:
end
end


function get_hero_key(hero_name)
function p.get_hero_key(hero_name)
for i, hero in pairs(data) do
for i, hero in pairs(data) do
if hero["Name"] == hero_name then
if hero["Name"] == hero_name then
Line 16: Line 18:
return nil
return nil
end
end
return p

Revision as of 11:30, 1 October 2024

Overview

Common internal functions that are shared amongst any Abilities/ modules

Submodules

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 p = {}

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

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

function p.get_hero_key(hero_name)
	for i, hero in pairs(data) do
		if hero["Name"] == hero_name then
			return i
		end
	end
	return nil
end

return p