Module:HeroData/nav: Difference between revisionsGive feedback
m Reverted edits by Saag (talk) to last revision by Monster Domosed Tag: Rollback |
Fix alphabetical sorting for heroes starting with "The" (e.g., The Doorman). |
||
| Line 39: | Line 39: | ||
if hero_data["Name"] ~= nil then | if hero_data["Name"] ~= nil then | ||
-- 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, | -- otherwise, needs to be not disabled, in development, and herolabs is nil or false | ||
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) | ||
| Line 52: | Line 52: | ||
end | end | ||
local | -- ===== Create a sort key and store an object instead of a string ===== | ||
local hero_name = lang_module.get_string(hero_key, nil, 'en') | |||
local sort_key = hero_name | |||
-- If the name starts with "The ", make the sort key the rest of the string | |||
if string.sub(sort_key, 1, 4) == "The " then | |||
sort_key = string.sub(sort_key, 5) -- "Doorman" | |||
end | |||
local hero_wikitext = '|name=' .. hero_name .. | |||
'|link=' .. lang_module.get_string(hero_key, 'en') .. | '|link=' .. lang_module.get_string(hero_key, 'en') .. | ||
'|subpage=' .. subpage_str .. | '|subpage=' .. subpage_str .. | ||
'|recommended=' .. tostring(is_recommended) | '|recommended=' .. tostring(is_recommended) | ||
table.insert(heroes, | table.insert(heroes, {sort_key = sort_key, wikitext = hero_wikitext}) | ||
end | end | ||
end | end | ||
end | end | ||
-- | -- ===== Use a custom sort function ===== | ||
table.sort(heroes) | table.sort(heroes, function(a, b) | ||
return a.sort_key < b.sort_key | |||
end) | |||
-- Add each item to output | -- Add each item to output | ||
local ret = '' | local ret = '' | ||
for index, | -- ===== Access the wikitext property of the hero object ===== | ||
ret = ret .. '{{Hero card2' .. | for index, hero_object in ipairs(heroes) do | ||
ret = ret .. '{{Hero card2' .. hero_object.wikitext | |||
ret = ret .. '|text_size=' .. text_size | ret = ret .. '|text_size=' .. text_size | ||
ret = ret .. '|herolabs=' .. in_herolabs | ret = ret .. '|herolabs=' .. in_herolabs | ||
| Line 86: | Line 98: | ||
end | end | ||
end | end | ||
return p | return p | ||