Module:HeroData/nav: Difference between revisions

Sur (talk | contribs)
m now sorts the heroes alphabetically
Sur (talk | contribs)
m initial for homepage nav
Line 3: Line 3:
local lang_module = require('Module:Lang')
local lang_module = require('Module:Lang')


-- for [[Template:Hero Navbox]], i.e. {{Hero Card Nav|Hero=Abrams}} {{Hero Card Nav|Hero=Bebop}}
-- for [[Template:Hero Navbox]] on /Heroes, i.e. {{Hero Card Nav|Hero=Abrams}} {{Hero Card Nav|Hero=Bebop}}
function p.get_hero_nav_cards(frame)
function p.get_hero_nav_cards(frame)
local current_or_upcoming = frame.args[1]
local current_or_upcoming = frame.args[1]
Line 12: Line 12:
local heroes = {}
local heroes = {}
for hero_key, hero_data in pairs(heroes_data) do
for hero_key, hero_data in pairs(heroes_data) do
local card = ''
if hero_data["Name"] ~= nil and hero_data["IsDisabled"] == false then
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
if (hero_data["InDevelopment"] == false and current_or_upcoming == 'Current' or hero_data["InDevelopment"] == true and current_or_upcoming == 'Upcoming') then
Line 36: Line 34:
end
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]
if in_herolabs ~= 'true' and in_herolabs ~= 'false' then
return 'First must be either true or false for in_herolabs'
end
--Iterate heroes
local heroes = {}
for hero_key, hero_data in pairs(heroes_data) do
if hero_data["Name"] ~= nil then
-- if herolabs is requested, only needs to have herolabs=true
-- otherwise, needs to be not disabled, in development, nd herolabs is nil or false
if ((in_herolabs == 'true' and hero_data['InHeroLabs']) or
(in_herolabs == 'false' and not hero_data['IsDisabled'] and not hero_data['InDevelopment'] and (hero_data['InHeroLabs'] == nil or not hero_data['InHeroLabs']))) then
local is_recommended = hero_data['Recommended']
if is_recommended == nil then
is_recommended = false
end
local hero_str = lang_module.get_string(hero_key) .. '|recommended=' .. tostring(is_recommended)
table.insert(heroes, hero_str)
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_card2|name=' .. hero_name
ret = ret .. '|herolabs=' .. in_herolabs
ret = ret .. '|text-size=20'
ret = ret .. '}} '
end
--Remove the last space
ret = string.sub(ret, 1, -(string.len(' '))-1)
return frame:preprocess(ret)
end
return p
return p