Module:Abilities/details table: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Saag (talk | contribs)
added alt and other props
Saag (talk | contribs)
mNo edit summary
 
(17 intermediate revisions by the same user not shown)
Line 2: Line 2:


local utils = require "Module:Abilities/utils"
local utils = require "Module:Abilities/utils"
local lang = require"Module:Lang"
local commonutils = require"Module:Utilities"


local header_attrs = {'Radius', 'AbilityCastRange', 'AbilityDuration', 'AbilityCooldown', 'AbilityCooldownBetweenCharge', 'AbilityCharges'}
local header_attrs = {'Radius', 'AbilityCastRange', 'AbilityDuration', 'AbilityCooldown', 'AbilityCooldownBetweenCharge', 'AbilityCharges'}
Line 8: Line 10:
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 = utils.get_ability_card_data(hero_name, ability_num)
local hero_key = utils.get_hero_key(hero_name)
local ability = utils.get_ability_card_data(hero_key, ability_num)
if(ability == nil) then error(string.format('Ability %s#%s not found', hero_name, ability_num)) end
if(ability == nil) then error(string.format('Ability %s#%s not found', hero_name, ability_num)) end


Line 23: Line 26:
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
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, frame)  
end
end
end
end
Line 32: Line 35:
local scale_type = prop.Scale and prop.Scale.Type or nil
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
rows = rows .. create_row(prop.Key, prop.Value, scale_type, scale_value)
rows = rows .. create_row(prop.Key, prop.Value, scale_type, scale_value, frame)
end
end
end
end
Line 43: Line 46:
local scale_type = prop.Scale and prop.Scale.Type or nil
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
rows = rows .. create_row(attr, prop.Value, scale_type, scale_value)
rows = rows .. create_row(attr, prop.Value, scale_type, scale_value, frame)
end
end
end
end
Line 49: Line 52:
-- then other data that is hidden on the ability card
-- then other data that is hidden on the ability card
if ability.Other then
if ability.Other then
for i, prop in pairs(ability.Other) do
for attr, prop in pairs(ability.Other) do
local scale_type = prop.Scale and prop.Scale.Type or nil
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
rows = rows .. create_row(prop.Key, prop.Value, scale_type, scale_value)
rows = rows .. create_row(attr, prop.Value, scale_type, scale_value, frame)
end
end
end
end
Line 59: Line 62:
end
end


function create_row(key, value, scale_type, scale_value)
local UPGRADE_COST_MAP = {1, 2, 5}
local row = '|' .. key .. '||' .. value
p.get_upgrade_table = function(frame)
local hero_name = frame.args[1]
local ability_num = frame.args[2]
local upgrade_num = frame.args[3]
 
local hero_key = utils.get_hero_key(hero_name)
local ability = utils.get_ability_card_data(hero_key, ability_num)
if(ability == nil) then error(string.format('Ability %s#%s not found', hero_name, ability_num)) end
 
local rows = '\n|-\n'
for i, upgrade in pairs(ability.Upgrades) do
local data_rows = ''
-- track number of attributes so we can assign the correct rowspan for the upgrade cost column
local num_of_attrs = 0
for key, value in pairs(upgrade) do
if key ~= 'DescKey' then
local scale_type = upgrade.Scale and upgrade.Scale.Type or nil
local scale_value = upgrade.Scale and upgrade.Scale.Value or nil
data_rows = data_rows .. create_row(key, value, scale_type, scale_value, frame, true)
num_of_attrs = num_of_attrs + 1
end
end
rows = rows .. string.format("\n!rowspan=%s style=\"background-color: #121212; color: #FFEFD7; text-align: center; text-wrap: nowrap;\" | [[File:Ability_point_unlock_icon.png|20px|link=Ability_Point]] '''%s'''\n", num_of_attrs, UPGRADE_COST_MAP[i])
rows = rows .. data_rows
end
 
return rows
end
 
-- with_plus=true will include the "+" symbol before the number, as by default it will be omiitted
function create_row(key, value, scale_type, scale_value, frame, with_plus)
if key == nil or value == nil then
return ''
end
-- get localized label, if none exists, fallback to one that is based on the key
local label = lang.get_string(key..'_label')
if label == '' then
label = commonutils.add_space_before_cap(key)
end
local formatted_value = utils.format_value_with_prepost(key, value, frame, with_plus~=true)
 
local row = '|' .. label .. '||' .. formatted_value
if scale_type and scale_value then
if scale_type and scale_value then
row = row .. '||' .. scale_type .. '||' .. scale_value
row = row .. '||' .. scale_type .. '||' .. scale_value .. '%'
end
return row .. '\n|-\n'
end
 
function create_upgrade_row(key, upgrades)
local row = ''
for i, upgrade in paris(upgrades) do
local scale_type = prop.Scale and prop.Scale.Type or nil
local scale_value = prop.Scale and prop.Scale.Value or nil
row = row .. upgrade[key]
end
end
return '\n|-\n'..row
return row
end
end


return p
return p

Latest revision as of 17:40, 26 October 2024

Overview[edit source]

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

Usage[edit source]

Template:Ability card v2/Details

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


p = {}

local utils = require "Module:Abilities/utils"
local lang = require"Module:Lang"
local commonutils = require"Module:Utilities"

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 hero_key = utils.get_hero_key(hero_name)
	local ability = utils.get_ability_card_data(hero_key, 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, frame) 
			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, frame)
			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, frame)	
		end
	end
	
	-- then other data that is hidden on the ability card
	if ability.Other then
		for attr, 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(attr, prop.Value, scale_type, scale_value, frame)
		end
	end
	
	return rows
end

local UPGRADE_COST_MAP = {1, 2, 5}
p.get_upgrade_table = function(frame)
	local hero_name = frame.args[1]
	local ability_num = frame.args[2]
	local upgrade_num = frame.args[3]

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

	local rows = '\n|-\n'
	
	for i, upgrade in pairs(ability.Upgrades) do
		local data_rows = ''
		
		-- track number of attributes so we can assign the correct rowspan for the upgrade cost column
		local num_of_attrs = 0
		for key, value in pairs(upgrade) do
			if key ~= 'DescKey' then
				local scale_type = upgrade.Scale and upgrade.Scale.Type or nil
				local scale_value = upgrade.Scale and upgrade.Scale.Value or nil
				data_rows = data_rows .. create_row(key, value, scale_type, scale_value, frame, true)	
				num_of_attrs = num_of_attrs + 1
			end
		end
		rows = rows .. string.format("\n!rowspan=%s style=\"background-color: #121212; color: #FFEFD7; text-align: center; text-wrap: nowrap;\" | [[File:Ability_point_unlock_icon.png|20px|link=Ability_Point]] '''%s'''\n", num_of_attrs, UPGRADE_COST_MAP[i])
		rows = rows .. data_rows
	end

	return rows
end

-- with_plus=true will include the "+" symbol before the number, as by default it will be omiitted
function create_row(key, value, scale_type, scale_value, frame, with_plus)
	if key == nil or value == nil then
		return ''	
	end
	
	-- get localized label, if none exists, fallback to one that is based on the key
	local label = lang.get_string(key..'_label')
	if label == '' then
		label = commonutils.add_space_before_cap(key)	
	end
	
	local formatted_value = utils.format_value_with_prepost(key, value, frame, with_plus~=true)

	local row = '|' .. label .. '||' .. formatted_value
	
	if scale_type and scale_value then
		row = row .. '||' .. scale_type .. '||' .. scale_value .. '%' 	
	end
	
	return row .. '\n|-\n'
end

function create_upgrade_row(key, upgrades)
	local row = ''
	for i, upgrade in paris(upgrades) do
		local scale_type = prop.Scale and prop.Scale.Type or nil
		local scale_value = prop.Scale and prop.Scale.Value or nil
		row = row .. upgrade[key]
		
	end
	
	return row
end

return p