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: | ||
--[[ | --[[ | ||
* Name: ElementAchievementHeader | |||
* Author: Mark W. Datysgeld | |||
* 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 | |||
]] | |||
local p = {} | local p = {} | ||
| Line 34: | Line 33: | ||
end | end | ||
-- | -- CRITICAL: WE MUST PRE-LOAD THE JSON DATA WITH THE FRAME BEFORE GETTING ANY ACHIEVEMENTS | ||
pcall(function() | |||
Achievements.loadData(frame) | |||
Achievements.loadTypes(frame) | |||
end) | |||
-- | -- Now get the title achievement | ||
local | local titleAchievement = Achievements.getTitleAchievement(pageId, frame) | ||
-- | -- Minimal debug comment only visible in source | ||
local debugInfo = string.format( | local debugInfo = string.format( | ||
"<!-- Achievement | "<!-- Achievement Header: pageId=%s -->", | ||
pageId or "nil" | |||
pageId | |||
) | ) | ||
-- Always create a row for debugging purposes | -- Always create a row for debugging purposes | ||
if | if titleAchievement then | ||
-- Achievement found | -- 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" | ' .. | ||
'<div class="achievement-foreground-layer">%s</div>%s%s', | |||
titleAchievement.id, titleAchievement.id, titleAchievement.name, titleAchievement.name, debugInfo, categoryLink | |||
) | ) | ||
else | else | ||
-- No achievement found | -- No achievement found: create empty phantom row | ||
return string.format( | return string.format( | ||
'|-\n! colspan="2" class="achievement-header-phantom" | | '|-\n! colspan="2" class="achievement-header-phantom" | ' .. | ||
'<div class="achievement-foreground-layer"></div>%s', | |||
debugInfo | debugInfo | ||
) | ) | ||