Module:Abilities/details table: Difference between revisions

No edit summary
Initial get_details_table function
Line 8: Line 8:


local ability = utils.get_ability_card_data(hero_name, ability_num)
local ability = utils.get_ability_card_data(hero_name, ability_num)
if(ability == nil) then return "Ability Not Found" end
if(ability == nil) then error(string.format('Ability %s#%s not found', hero_name, ability_num)) end
 
local rows = ''
local rows = ''
for info_section_num=1, 10 do
for info_section_num=1, 10 do
Line 15: Line 15:
if info_section == nil then break end
if info_section == nil then break end
-- display props from info sections first
local main = info_section.Main
for prop in info_section.Main.Props do
if main ~= nil then
local scale_value = prop.Scale and prop.Scale.Value or nil
-- display props from info sections first
local scale_type = prop.Scale and prop.Scale.Type or nil
for i, prop in pairs(main.Props) do
rows = rows .. create_row(prop.Key, prop.Value, scale_type, scale_value)
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
end
for prop in info_section.Alt.Props do
local alt = info_section.Alt
local scale_value = prop.Scale and prop.Scale.Value or nil
if alt ~= nil then
local scale_type = prop.Scale and prop.Scale.Type or nil
for i, prop in pairs(alt) do
rows = rows .. create_row(prop.Key, prop.Value, scale_type, scale_value)
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
end
end
end
Line 36: Line 42:


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


return p
return p