Module:HeroData/nav: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Gammaton32 (talk | contribs) No edit summary |
Gammaton32 (talk | contribs) refactored hero list function for other functions to call for |
||
| Line 4: | Line 4: | ||
local lang_module = require('Module:Lang') | local lang_module = require('Module:Lang') | ||
-- | -- Shared helper function | ||
function | local function get_heroes(in_herolabs, include_key) | ||
local | local heroes = {} | ||
for hero_key, hero_data in pairs(heroes_data) do | for hero_key, hero_data in pairs(heroes_data) do | ||
-- hero_werewolf_transformed is consolidated in Silver's page | |||
if hero_data["Name"] ~= nil and hero_key ~= 'hero_werewolf_transformed' then | if hero_data["Name"] ~= nil and hero_key ~= 'hero_werewolf_transformed' then | ||
local this_hero_status = hero_release_module.get_hero_release_status(hero_key) | local this_hero_status = hero_release_module.get_hero_release_status(hero_key) | ||
if ((in_herolabs == 'true' and this_hero_status == 'HeroLabs') or | if ((in_herolabs == 'true' and this_hero_status == 'HeroLabs') or | ||
(in_herolabs == 'false' and this_hero_status == 'Released')) then | (in_herolabs == 'false' and this_hero_status == 'Released')) then | ||
local is_recommended = hero_data['IsRecommended'] | local is_recommended = hero_data['IsRecommended'] or false | ||
--- Create a sort key for each hero to ensure correct alphabetical ordering. | |||
-- Create a sort key for each hero to ensure correct alphabetical ordering. | |||
-- This logic handles special cases like "The Doorman" by looking for a "_sort" version of the hero's key in the language files. | -- This logic handles special cases like "The Doorman" by looking for a "_sort" version of the hero's key in the language files. | ||
local hero_name = lang_module.get_string(hero_key, nil, 'en') | local hero_name = lang_module.get_string(hero_key, nil, 'en') | ||
local sort_key_to_find = hero_key .. '_sort' | local sort_key_to_find = hero_key .. '_sort' | ||
local potential_sort_key = lang_module.get_string(sort_key_to_find, nil, 'en') | local potential_sort_key = lang_module.get_string(sort_key_to_find, nil, 'en') | ||
local sort_key | local sort_key | ||
-- The lang_module returns the requested key (wrapped in HTML) if a translation is not found. | -- The lang_module returns the requested key (wrapped in HTML) if a translation is not found. | ||
| Line 71: | Line 36: | ||
end | end | ||
local | -- Store reusable hero data | ||
local hero = { | |||
key = hero_key, | |||
name = hero_name, | |||
sort_key = sort_key, | |||
link = lang_module.get_string(hero_key, 'en'), | |||
table.insert(heroes, | recommended = tostring(is_recommended) | ||
} | |||
table.insert(heroes, hero) | |||
end | end | ||
end | end | ||
end | end | ||
-- Sort | -- Sort heroes | ||
table.sort(heroes, function(a, b) | table.sort(heroes, function(a, b) | ||
return a.sort_key < b.sort_key | return a.sort_key < b.sort_key | ||
end) | end) | ||
return heroes | |||
end | |||
-- for [[Template:Deadlock_Wiki/Heroes]] | |||
function p.get_hero_nav_cards(frame) | |||
local in_herolabs = frame.args['in_herolabs'] or 'false' | |||
local text_size = frame.args['text_size'] | |||
local card_size = frame.args['card_size'] | |||
local sticker_size = frame.args['sticker_size'] | |||
local herolabs_text_size = frame.args['herolabs_text_size'] | |||
local debug_mode = frame.args['debug_mode'] == 'true' | |||
local lang_code = lang_module.get_lang_code() | |||
local subpage_str = '' | |||
if lang_code ~= 'en' then | |||
subpage_str = '/' .. lang_code | |||
end | |||
local heroes = get_heroes(in_herolabs) | |||
local ret = '' | local ret = '' | ||
for | |||
ret = ret .. '{{Hero card2' .. | for _, hero in ipairs(heroes) do | ||
ret = ret .. '{{Hero card2' | |||
ret = ret .. '|name=' .. hero.name | |||
ret = ret .. '|link=' .. hero.link | |||
ret = ret .. '|subpage=' .. subpage_str | |||
ret = ret .. '|recommended=' .. hero.recommended | |||
ret = ret .. '|text_size=' .. text_size | ret = ret .. '|text_size=' .. text_size | ||
ret = ret .. '|herolabs=' .. in_herolabs | ret = ret .. '|herolabs=' .. in_herolabs | ||
| Line 96: | Line 90: | ||
ret = ret .. '|sticker_size=' .. sticker_size | ret = ret .. '|sticker_size=' .. sticker_size | ||
ret = ret .. '|herolabs_text_size=' .. herolabs_text_size | ret = ret .. '|herolabs_text_size=' .. herolabs_text_size | ||
ret = ret .. '}} ' | ret = ret .. '}}' | ||
end | |||
if debug_mode then | if debug_mode then | ||
return ret | return ret | ||
else | else | ||
return frame:preprocess(ret) | return frame:preprocess(ret) | ||
end | end | ||
| Line 111: | Line 102: | ||
-- for [[Template:Roster]] | -- for [[Template:Roster]] | ||
function p.get_hero_roster(frame) | function p.get_hero_roster(frame) | ||
local in_herolabs = frame.args['in_herolabs'] or 'false' | |||
local debug_mode = frame.args['debug_mode'] == 'true' | |||
local lang_code = lang_module.get_lang_code() | |||
local subpage_str = '' | local subpage_str = '' | ||
if lang_code ~= 'en' then | if lang_code ~= 'en' then | ||
subpage_str = '/' .. lang_code | subpage_str = '/' .. lang_code | ||
end | end | ||
local heroes = get_heroes(in_herolabs) | |||
local ret = '' | local ret = '' | ||
for | |||
ret = ret .. '{{HeroRosterCard' .. | for _, hero in ipairs(heroes) do | ||
ret = ret .. '{{HeroRosterCard' | |||
ret = ret .. '|name=' .. hero.name | |||
ret = ret .. '|key=' .. hero.key | |||
ret = ret .. '}}' | ret = ret .. '}}' | ||
end | |||
if debug_mode then | if debug_mode then | ||
return ret | return ret | ||
else | else | ||
return frame:preprocess(ret) | return frame:preprocess(ret) | ||
end | end | ||
| Line 204: | Line 134: | ||
p.get_hero_bulletpoints = function(frame) | p.get_hero_bulletpoints = function(frame) | ||
local subpage = frame.args['1'] | local subpage = frame.args['1'] | ||
local in_herolabs = frame.args['in_herolabs'] or 'false' | |||
local | local debug_mode = frame.args['debug_mode'] == 'true' | ||
local lang_code = lang_module.get_lang_code() | |||
local subpage_str = '' | local subpage_str = '' | ||
if lang_code ~= 'en' then | if lang_code ~= 'en' then | ||
subpage_str = '/' .. lang_code | subpage_str = '/' .. lang_code | ||
end | end | ||
local heroes = get_heroes(in_herolabs) | |||
local ret = '' | |||
for _, hero in ipairs(heroes) do | |||
for | |||
if subpage then | if subpage then | ||
ret = ret .. '{{PageRef|'.. | ret = ret .. '{{PageRef|'.. hero.name | ||
ret = ret .. '|alt_link='.. | ret = ret .. '|alt_link='.. hero.name | ||
ret = ret .. '/'.. subpage | ret = ret .. '/'.. subpage | ||
ret = ret ..'}} • ' | ret = ret ..'}} • ' | ||
else | else | ||
ret = ret .. '{{HeroIcon|'.. | ret = ret .. '{{HeroIcon|'.. hero.name | ||
ret = ret ..'}} • ' | ret = ret ..'}} • ' | ||
end | end | ||