Module:ElementAchievementHeader: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
--[[  
--[[
* Module:ElementAchievementHeader
* Name: ElementAchievementHeader
* Renders the achievement header for person templates
* Author: Mark W. Datysgeld
* Displays title achievements with special styling
* Description: Element module that renders achievement headers for Person templates and handles all title-type achievements
*
* Notes: Creates blocks for Blueprint framework; loads achievement data using AchievementSystem; filters for title-type achievements; renders with animated backgrounds using two-layer approach for readability; includes phantom row when no achievements found; protected execution with error handling
* Integrates with Blueprint template system.
]]
]]


local p = {}
local p = {}
Line 34: Line 33:
             end
             end
              
              
             -- Use getTitleAchievement function that specifically checks for type="title"
             -- CRITICAL: WE MUST PRE-LOAD THE JSON DATA WITH THE FRAME BEFORE GETTING ANY ACHIEVEMENTS
             -- IMPORTANT: The function returns achievementId, displayName, achievementId
             pcall(function()
            -- We need to directly use these return values correctly
                Achievements.loadData(frame)
            local achievementId, displayName, achievementId2 = Achievements.getTitleAchievement(pageId, frame)
                Achievements.loadTypes(frame)
            end)
              
              
             -- Include more comprehensive debug information
             -- Now get the title achievement
             local pageName = mw.title.getCurrentTitle().fullText or "[Unknown]"
             local titleAchievement = Achievements.getTitleAchievement(pageId, frame)
              
              
             -- Get user achievements directly for debugging
             -- Minimal debug comment only visible in source
            local userAchievements = {}
            pcall(function() userAchievements = Achievements.getUserAchievements(pageId) or {} end)
            local achievementCount = #userAchievements
           
            -- Format the debug output with more details
             local debugInfo = string.format(
             local debugInfo = string.format(
                 "<!-- Achievement Debug: Page='%s', ID='%s', Found=%d achievements, "..
                 "<!-- Achievement Header: pageId=%s -->",
                "Title Data: ID='%s', Name='%s', ID2='%s' -->",
                 pageId or "nil"
                pageName,
                 pageId or "nil",
                achievementCount,
                achievementId or "nil",
                displayName or "nil",
                achievementId2 or "nil"
             )
             )
              
              
             -- Always create a row for debugging purposes
             -- Always create a row for debugging purposes
             if achievementId ~= "" and displayName ~= "" and achievementId2 ~= "" then
             if titleAchievement then
                 -- Achievement found - create populated row with achievement data
                -- Get category link from the centralized function
                local categoryLink = Achievements.getCategoryLinks({ { type = titleAchievement.id } }, frame)
 
                 -- Achievement found: create populated row with achievement data
                 return string.format(
                 return string.format(
                     '|-\n! colspan="2" class="achievement-header %s" data-achievement-id="%s" data-achievement-name="%s" | %s%s',
                     '|-\n! colspan="2" class="achievement-header %s" data-achievement-id="%s" data-achievement-name="%s" | ' ..
                     achievementId, achievementId, displayName, displayName, debugInfo
                    '<div class="achievement-foreground-layer">%s</div>%s%s',
                     titleAchievement.id, titleAchievement.id, titleAchievement.name, titleAchievement.name, debugInfo, categoryLink
                 )
                 )
             else
             else
                 -- No achievement found - create phantom row with visible debug info
                 -- No achievement found: create empty phantom row
                 return string.format(
                 return string.format(
                     '|-\n! colspan="2" class="achievement-header-phantom" | No Achievement Found %s',
                     '|-\n! colspan="2" class="achievement-header-phantom" | ' ..
                    '<div class="achievement-foreground-layer"></div>%s',
                     debugInfo
                     debugInfo
                 )
                 )