Module:ElementAchievementHeader: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
 
(13 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 25: Line 24:
         -- Protected execution wrapper
         -- Protected execution wrapper
         local function execute()
         local function execute()
            local frame = mw.getCurrentFrame()
           
             -- Get the current page ID
             -- Get the current page ID
             local pageId = mw.title.getCurrentTitle().id
             local pageId = mw.title.getCurrentTitle().id
             if not pageId then
             if not pageId then
                 return "" -- No page ID, can't get achievements
                -- Include debug comment when no page ID available
                 return "<!-- Achievement Header: No page ID available -->"
             end
             end
              
              
             -- Get title achievement data with frame for JSON loading
             -- CRITICAL: WE MUST PRE-LOAD THE JSON DATA WITH THE FRAME BEFORE GETTING ANY ACHIEVEMENTS
             local achievementId, displayName, achievementType = Achievements.getTitleAchievement(pageId, mw.getCurrentFrame())
             pcall(function()
                Achievements.loadData(frame)
                Achievements.loadTypes(frame)
            end)
              
              
             -- If no title achievement found, return empty string
             -- Now get the title achievement
             if not achievementId or achievementId == "" then
             local titleAchievement = Achievements.getTitleAchievement(pageId, frame)
                return ""
            end
              
              
             -- Create the achievement header HTML
             -- Minimal debug comment only visible in source
             local headerClass = template.config.achievementHeader
             local debugInfo = string.format(
                 and template.config.achievementHeader.headerClass
                 "<!-- Achievement Header: pageId=%s -->",
                 or p.defaultConfig.headerClass
                 pageId or "nil"
            )
              
              
             -- Build header HTML properly aligned with CSS expectations in Achievements.css
             -- Always create a row for debugging purposes
             -- Important: The CSS classes must be directly on the table cell element
             if titleAchievement then
            -- The CSS animations are attached to these elements via pseudo-elements
                -- Get category link from the centralized function
           
                local categoryLink = Achievements.getCategoryLinks({ { type = titleAchievement.id } }, frame)
            -- Debug information to help diagnose the issue
 
            local debugInfo = string.format("<!-- Achievement Debug: ID=%s, Name=%s, Type=%s, PageID=%s -->",  
                 -- Achievement found: create populated row with achievement data
                achievementId or "nil",
                 return string.format(
                 displayName or "nil",
                    '|-\n! colspan="2" class="achievement-header %s" data-achievement-id="%s" data-achievement-name="%s" | ' ..
                achievementType or "nil",
                    '<div class="achievement-foreground-layer">%s</div>%s%s',
                 pageId or "nil")
                    titleAchievement.id, titleAchievement.id, titleAchievement.name, titleAchievement.name, debugInfo, categoryLink
           
                )
            return string.format(
            else
                '|-\n! colspan="2" class="%s %s" data-achievement-id="%s" data-achievement-name="%s" | %s%s',
                -- No achievement found: create empty phantom row
                headerClass, achievementId, achievementId, displayName, displayName, debugInfo
                return string.format(
             )
                    '|-\n! colspan="2" class="achievement-header-phantom" | ' ..
                    '<div class="achievement-foreground-layer"></div>%s',
                    debugInfo
                )
             end
         end
         end
          
          
Line 71: Line 79:
         else
         else
             local ok, result = pcall(execute)
             local ok, result = pcall(execute)
             return ok and result or ""
             return ok and result or "<!-- Achievement Header: Protected execution failed -->"
         end
         end
     end
     end