Module:ElementAchievementBadges: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
-- Module:ElementAchievementBadges
--[[
-- Renders achievement badges for Person templates and handles all badge-type achievements.
* Name: ElementAchievementBadges
* Author: Mark W. Datysgeld
* Description: Element module that renders achievement badges for Person templates and handles all badge-type achievements
* Notes: Creates blocks for Blueprint framework; loads achievement data using AchievementSystem; filters for badge-type achievements; renders badges as HTML spans with CSS classes; includes category links; protected execution with error handling
]]


local p = {}
local p = {}
Line 66: Line 70:
                 or p.defaultConfig.badgeClass
                 or p.defaultConfig.badgeClass
              
              
             -- Build the badges HTML and category links
             -- Build the badges HTML
             local badgesHtml = {}
             local badgesHtml = {}
            local categoryLinks = {}
              
              
             -- Add a table row to contain the badges
             -- Add a table row to contain the badges
             table.insert(badgesHtml, '|-\n| colspan="2" class="' .. containerClass .. '" | ')
             table.insert(badgesHtml, '|-\n| colspan="2" class="' .. containerClass .. '" | ')
              
              
             -- Add each badge and collect category links
             -- Add each badge
             for _, achievement in ipairs(badgeAchievements) do
             for _, achievement in ipairs(badgeAchievements) do
                 -- For each badge, create a span with appropriate classes
                 -- For each badge, create a span with appropriate classes
Line 85: Line 88:
                     table.insert(badgesHtml, badgeSpan)
                     table.insert(badgesHtml, badgeSpan)
                 end
                 end
            end


                -- Add category link if it exists
            -- Get category links from the centralized function
                if achievement.category and achievement.category ~= "" then
            local categoryLinksString = Achievements.getCategoryLinks(badgeAchievements, frame)
                    table.insert(categoryLinks, "[[Category:" .. achievement.category .. "]]")
                end
            end
              
              
             -- Return the complete HTML with debug info and category links
             -- Return the complete HTML with debug info and category links
             return table.concat(badgesHtml) .. table.concat(categoryLinks) .. debugInfo
             return table.concat(badgesHtml) .. categoryLinksString .. debugInfo
         end
         end