Module:HeroData/nav: Difference between revisions

Jump to navigation Jump to search
Sur (talk | contribs)
m parameterize text size and card size
Sur (talk | contribs)
m functions merged
Line 3: Line 3:
local lang_module = require('Module:Lang')
local lang_module = require('Module:Lang')


-- for [[Template:Hero Navbox]] on /Heroes, i.e. {{Hero Card Nav|Hero=Abrams}} {{Hero Card Nav|Hero=Bebop}}
-- for [[Template:Deadlock_Wiki/Heroes]] on home page, i.e. [[Template:Hero card2]]
function p.get_hero_nav_cards(frame)
function p.get_hero_nav_cards(frame)
local current_or_upcoming = frame.args[1]
local in_herolabs = frame.args['in_herolabs'] --true or false
if current_or_upcoming ~= 'Current' and current_or_upcoming ~= 'Upcoming' then
local text_size = frame.args['text_size']
return 'First parameter must be Current or Upcoming'
local card_size = frame.args['card_size']
end
local sticker_size = frame.args['sticker_size']
local heroes = {}
for hero_key, hero_data in pairs(heroes_data) do
if hero_data["Name"] ~= nil and hero_data["IsDisabled"] == false then
if (hero_data["InDevelopment"] == false and current_or_upcoming == 'Current' or hero_data["InDevelopment"] == true and current_or_upcoming == 'Upcoming') then
table.insert(heroes, lang_module.get_string(hero_key))
end
end
end
--Order list alphabetically
table.sort(heroes) --O(nlogn)
--Add each item to output
local ret = ''
for index, hero_name in ipairs(heroes) do
ret = ret .. '{{Hero Card Nav|Hero=' .. hero_name .. '}} '
end
--Remove the last space
ret = string.sub(ret, 1, -(string.len(' '))-1)
return frame:preprocess(ret)
end
 
-- for [[Template:Deadlock_Wiki/Heroes]] on home page, i.e. [[Template:Hero card2]]
function p.get_hero_nav_cards_homepage(frame)
--true or false
local in_herolabs = frame.args[1]
local text_size = frame.args[2]
local card_size = frame.args[3]


if in_herolabs ~= 'true' and in_herolabs ~= 'false' then
if in_herolabs ~= 'true' and in_herolabs ~= 'false' then
return 'in_herolabs must be either true or false as the first unnamed parameter'
return 'in_herolabs must be either true or false as the first unnamed parameter'
end
end
if text_size == nil then text_size = 20 end
if card_size == nil then card_size = 132 end
--Iterate heroes
--Iterate heroes
Line 53: Line 20:
-- if herolabs is requested, only needs to have herolabs=true
-- if herolabs is requested, only needs to have herolabs=true
-- otherwise, needs to be not disabled, in development, nd herolabs is nil or false
-- otherwise, needs to be not disabled, in development, nd herolabs is nil or false
if ((in_herolabs == 'true' and hero_data['InHeroLabs']) or
this_in_herolabs = hero_data['InHeroLabs']
(in_herolabs == 'false' and not hero_data['IsDisabled'] and not hero_data['InDevelopment'] and (hero_data['InHeroLabs'] == nil or not hero_data['InHeroLabs']))) then
if this_in_herolabs == nil then this_in_herolabs = false end
if ((in_herolabs == 'true' and this_in_herolabs) or
(in_herolabs == 'false' and not hero_data['IsDisabled'] and not hero_data['InDevelopment'] and not this_in_herolabs)) then
local is_recommended = hero_data['Recommended']
local is_recommended = hero_data['IsRecommended']
if is_recommended == nil then
if is_recommended == nil then
is_recommended = false
is_recommended = false
Line 74: Line 44:
local ret = ''
local ret = ''
for index, hero_name in ipairs(heroes) do
for index, hero_name in ipairs(heroes) do
ret = ret .. '{{Hero_card2|name=' .. hero_name
ret = ret .. '{{Hero card2|name=' .. hero_name
ret = ret .. '|text_size=' .. text_size
ret = ret .. '|text_size=' .. text_size
ret = ret .. '|herolabs=' .. in_herolabs
ret = ret .. '|herolabs=' .. in_herolabs
ret = ret .. '|card_size=' .. card_size
ret = ret .. '|card_size=' .. card_size
ret = ret .. '|sticker_size=' .. sticker_size
ret = ret .. '}} '
ret = ret .. '}} '
end
end