Module:HeroData/nav: Difference between revisions

Refactored for performance optimization
3D model function
 
(One intermediate revision by the same user not shown)
Line 125: Line 125:
     for _, hero in ipairs(heroes) do
     for _, hero in ipairs(heroes) do
         -- Lua optimization: clean ternary fallback for page_title assignment
         -- Lua optimization: clean ternary fallback for page_title assignment
         local page_title = subpage and (hero.name .. '/' .. subpage) or hero.name
         local page_title = subpage and (hero.link .. '/' .. subpage) or hero.name


         -- Skip redlinks entirely when enabled
         -- Skip redlinks entirely when enabled
Line 131: Line 131:
             local item
             local item
             if subpage then
             if subpage then
                 item = string.format('{{PageRef|%s|alt_link=%s}}', hero.name, page_title)
                 item = string.format('{{PageRef|%s|alt_link=%s}}', hero.link, page_title)
             else
             else
                 item = string.format('{{HeroIcon|%s}}', hero.name)
                 item = string.format('{{HeroIcon|%s}}', hero.link)
             end
             end
             table.insert(parts, item)
             table.insert(parts, item)
Line 159: Line 159:


     for _, hero in ipairs(heroes) do
     for _, hero in ipairs(heroes) do
         table.insert(parts, string.format('File:%s%s|%s%s\n', hero.name, file_name, hero.name, description))
         table.insert(parts, string.format('File:%s%s|%s%s\n', hero.link, file_name, hero.name, description))
     end
     end
      
      
     local ret = '<gallery>\n' .. table.concat(parts) .. '</gallery>'
     local ret = '<gallery>\n' .. table.concat(parts) .. '</gallery>'
    if debug_mode then
        return ret
    else
        return frame:preprocess(ret)
    end
end
-- Generate 3D model gallery
function p.get_hero_models(frame)
    local in_herolabs = frame.args['in_herolabs'] or 'false'
    local debug_mode = frame.args['debug_mode'] == 'true'
    local heroes = get_heroes(in_herolabs)
    local parts = {}
    for _, hero in ipairs(heroes) do
        table.insert(parts, string.format('{{3D Model|%s}}', hero.name))
    end
    local ret = table.concat(parts)


     if debug_mode then
     if debug_mode then