Module:HeroData/nav: Difference between revisions

refactored hero list function for other functions to call for
added no_redlinks variable
Line 3: Line 3:
local hero_release_module = require('Module:HeroData/release')
local hero_release_module = require('Module:HeroData/release')
local lang_module = require('Module:Lang')
local lang_module = require('Module:Lang')
local utilities = require('Module:Utilities')


-- Shared helper function
-- Shared helper function
Line 132: Line 133:


-- for [[Template:Quotes Navbox]] etc.
-- for [[Template:Quotes Navbox]] etc.
local utilities = require('Module:Utilities')
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 in_herolabs = frame.args['in_herolabs'] or 'false'
     local debug_mode = frame.args['debug_mode'] == 'true'
     local debug_mode = frame.args['debug_mode'] == 'true'
    local no_redlinks = frame.args['no_redlinks'] == 'true'  -- default: false
    local heroes = get_heroes(in_herolabs)
    local parts = {}


     local lang_code = lang_module.get_lang_code()
     for _, hero in ipairs(heroes) do
        local page_title = hero.name
        if subpage then
            page_title = hero.name .. '/' .. subpage
        end


    local subpage_str = ''
        -- Skip redlinks entirely when enabled
    if lang_code ~= 'en' then
        if not (no_redlinks and not utilities.page_exists(page_title)) then
        subpage_str = '/' .. lang_code
            local item
            if subpage then
                item = '{{PageRef|' .. hero.name .. '|alt_link=' .. page_title .. '}}'
            else
                item = '{{HeroIcon|' .. hero.name .. '}}'
            end
            table.insert(parts, item)
        end
     end
     end


     local heroes = get_heroes(in_herolabs)
     local ret = table.concat(parts, ' • ')


    local ret = ''
   
    for _, hero in ipairs(heroes) do
    if subpage then
            ret = ret .. '{{PageRef|'.. hero.name
            ret = ret .. '|alt_link='.. hero.name
            ret = ret .. '/'.. subpage
            ret = ret ..'}} • '
        else
            ret = ret .. '{{HeroIcon|'.. hero.name
            ret = ret ..'}} • '
        end
        end
   
        -- Remove the last bullet point
    ret = string.sub(ret, 1, -(string.len(' • '))-1)
   
     if debug_mode then
     if debug_mode then
         return ret
         return ret
     else -- evaluate wikitext if not in debug mode
     else
         return frame:preprocess(ret)
         return frame:preprocess(ret)
     end
     end