Module:Abilities/details table: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Saag (talk | contribs)
Initial get_details_table function
Saag (talk | contribs)
added alt and other props
Line 2: Line 2:


local utils = require "Module:Abilities/utils"
local utils = require "Module:Abilities/utils"
local header_attrs = {'Radius', 'AbilityCastRange', 'AbilityDuration', 'AbilityCooldown', 'AbilityCooldownBetweenCharge', 'AbilityCharges'}


p.get_details_table = function(frame)
p.get_details_table = function(frame)
Line 28: Line 30:
if alt ~= nil then
if alt ~= nil then
for i, prop in pairs(alt) do
for i, prop in pairs(alt) do
local scale_type = prop.Scale and prop.Scale.Type or nil
local scale_value = prop.Scale and prop.Scale.Value or nil
local scale_value = prop.Scale and prop.Scale.Value or nil
local scale_type = prop.Scale and prop.Scale.Type or nil
rows = rows .. create_row(prop.Key, prop.Value, scale_type, scale_value)
rows = rows .. create_row(prop.Key, prop.Value, scale_type, scale_value)
end
end
end
end
-- then any header data, cooldowns, charges, range etc.
for i, attr in pairs(header_attrs) do
local prop = ability[attr]
if prop then
local scale_type = prop.Scale and prop.Scale.Type or nil
local scale_value = prop.Scale and prop.Scale.Value or nil
rows = rows .. create_row(attr, prop.Value, scale_type, scale_value)
end
end
end
end
-- then any header data, cooldowns, charges, range etc.
-- then other data that is hidden on the ability card
-- then other data that is hidden on the ability card
if ability.Other then
for i, prop in pairs(ability.Other) do
local scale_type = prop.Scale and prop.Scale.Type or nil
local scale_value = prop.Scale and prop.Scale.Value or nil
rows = rows .. create_row(prop.Key, prop.Value, scale_type, scale_value)
end
end
return rows
return rows
end
end

Revision as of 13:50, 1 October 2024

Overview

Abilities module handles any simple functions that don't require a submodule

Usage

Template:Ability card v2/Details

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


p = {}

local utils = require "Module:Abilities/utils"

local header_attrs = {'Radius', 'AbilityCastRange', 'AbilityDuration', 'AbilityCooldown', 'AbilityCooldownBetweenCharge', 'AbilityCharges'}

p.get_details_table = function(frame)
	local hero_name = frame.args[1]
	local ability_num = frame.args[2]

	local ability = utils.get_ability_card_data(hero_name, ability_num)
	if(ability == nil) then error(string.format('Ability %s#%s not found', hero_name, ability_num)) end

	local rows = ''
	for info_section_num=1, 10 do
		local info_section = ability['Info'..info_section_num]
		if info_section == nil then break end
		
		local main = info_section.Main
		if main ~= nil then
			-- display props from info sections first
			for i, prop in pairs(main.Props) do
				local scale_value = prop.Scale and prop.Scale.Value or nil
				local scale_type = prop.Scale and prop.Scale.Type or nil
				rows = rows .. create_row(prop.Key, prop.Value, scale_type, scale_value) 
			end
		end
		
		local alt = info_section.Alt
		if alt ~= nil then
			for i, prop in pairs(alt) do
				local scale_type = prop.Scale and prop.Scale.Type or nil
				local scale_value = prop.Scale and prop.Scale.Value or nil
				rows = rows .. create_row(prop.Key, prop.Value, scale_type, scale_value)
			end
		end
	end

	-- then any header data, cooldowns, charges, range etc.
	for i, attr in pairs(header_attrs) do
		local prop = ability[attr]
		if prop then
			local scale_type = prop.Scale and prop.Scale.Type or nil
			local scale_value = prop.Scale and prop.Scale.Value or nil
			rows = rows .. create_row(attr, prop.Value, scale_type, scale_value)	
		end
	end
	
	-- then other data that is hidden on the ability card
	if ability.Other then
		for i, prop in pairs(ability.Other) do
			local scale_type = prop.Scale and prop.Scale.Type or nil
			local scale_value = prop.Scale and prop.Scale.Value or nil
			rows = rows .. create_row(prop.Key, prop.Value, scale_type, scale_value)
		end
	end
	
	return rows
end

function create_row(key, value, scale_type, scale_value)
	local row = '|' .. key .. '||' .. value
	
	if scale_type and scale_value then
		row = row .. '||' .. scale_type .. '||' .. scale_value 	
	end
	
	return '\n|-\n'..row
end

return p