Module:ElementAchievementBadges: Difference between revisions

// via Wikitext Extension for VSCode
 
// via Wikitext Extension for VSCode
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
--[[  
--[[
* Module:ElementAchievementBadges
* Name: ElementAchievementBadges
* Renders achievement badges for person templates
* Author: Mark W. Datysgeld
* Displays all badge-type achievements for the user
* 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
* Integrates with Blueprint template system.
]]
]]


local p = {}
local p = {}
Line 36: Line 35:
             end
             end
              
              
             -- CRITICAL: We must pre-load the JSON data with the frame before getting any achievements
             -- CRITICAL: WE MUST PRE-LOAD THE JSON DATA WITH THE FRAME BEFORE GETTING ANY ACHIEVEMENTS
            -- This is how LuaTemplatePerson.lua ensures the JSON is loaded correctly
             pcall(function()
             pcall(function()
                 Achievements.loadData(frame)
                 Achievements.loadData(frame)
Line 43: Line 41:
             end)
             end)
              
              
             -- Get all user achievements first
             -- Get all badge-type achievements using the centralized function
            local userAchievements = Achievements.getUserAchievements(pageId)
             local badgeAchievements = Achievements.getBadgeAchievements(pageId, frame)
           
            -- Filter for only badge type achievements
             local badgeAchievements = {}
            local types = Achievements.loadTypes(frame)
           
            -- Build a lookup table for achievement types
            local typeDefinitions = {}
            for _, typeData in ipairs(types) do
                if typeData.id and typeData.type then
                    typeDefinitions[typeData.id] = typeData
                end
            end
           
            -- Filter user achievements to only include badge types
            for _, achievement in ipairs(userAchievements) do
                local achType = achievement.type
                if achType and typeDefinitions[achType] and typeDefinitions[achType].type == "badge" then
                    -- Add achievement display name from type definition
                    achievement.name = typeDefinitions[achType].name or achType
                    table.insert(badgeAchievements, achievement)
                end
            end
              
              
             -- Minimal debug info for troubleshooting
             -- Minimal debug info for troubleshooting
Line 113: Line 89:
                 end
                 end
             end
             end
            -- Get category links from the centralized function
            local categoryLinksString = Achievements.getCategoryLinks(badgeAchievements, frame)
              
              
             -- Return the complete HTML with debug info
             -- Return the complete HTML with debug info and category links
             return table.concat(badgesHtml) .. debugInfo
             return table.concat(badgesHtml) .. categoryLinksString .. debugInfo
         end
         end