Module:AchievementSystem: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 248: | Line 248: | ||
return 'Unknown' | return 'Unknown' | ||
end | end | ||
-- Direct console log for better visibility of what we're looking up | |||
mw.log("NAME-DEBUG: Looking up name for achievement type: " .. achievementType) | |||
local data = Achievements.loadData() | local data = Achievements.loadData() | ||
if not data or not data.achievement_types then | if not data or not data.achievement_types then | ||
mw.log("NAME-DEBUG: No achievement data available for name lookup") | |||
return achievementType -- Fall back to the ID as a last resort | return achievementType -- Fall back to the ID as a last resort | ||
end | |||
-- Log the loaded data to see what's available | |||
mw.log("NAME-DEBUG: Achievement types found: " .. #data.achievement_types) | |||
-- Print all available achievements to diagnose | |||
for i, typeData in ipairs(data.achievement_types) do | |||
mw.log("NAME-DEBUG: Achievement #" .. i .. ": id='" .. tostring(typeData.id) .. | |||
"', name='" .. tostring(typeData.name) .. "'") | |||
end | end | ||
| Line 258: | Line 270: | ||
for _, typeData in ipairs(data.achievement_types) do | for _, typeData in ipairs(data.achievement_types) do | ||
if typeData.id == achievementType then | if typeData.id == achievementType then | ||
mw.log("NAME-DEBUG: MATCH FOUND! Achievement type '" .. achievementType .. | |||
return typeData.name | "' has name '" .. tostring(typeData.name) .. "'") | ||
-- Make absolutely sure we're returning the name, not the ID | |||
if typeData.name and typeData.name ~= "" then | |||
return typeData.name | |||
else | |||
mw.log("NAME-DEBUG: Achievement found but name is empty, using ID as fallback") | |||
return achievementType | |||
end | |||
end | end | ||
end | end | ||
-- If we get here, we couldn't find the achievement type | -- If we get here, we couldn't find the achievement type | ||
mw.log("NAME-DEBUG: No match found for achievement type: " .. achievementType) | |||
return achievementType -- Fall back to the ID as a last resort | return achievementType -- Fall back to the ID as a last resort | ||
end | end | ||
| Line 303: | Line 323: | ||
if isTestPage(pageId) then | if isTestPage(pageId) then | ||
mw.log("TITLE-DEBUG: Returning title-test achievement class for test page") | mw.log("TITLE-DEBUG: Returning title-test achievement class for test page") | ||
-- | |||
local achievementName = | -- Explicitly look up the achievement name for title-test in JSON | ||
local data = Achievements.loadData() | |||
local achievementName = nil | |||
if data and data.achievement_types then | |||
for _, typeData in ipairs(data.achievement_types) do | |||
if typeData.id == "title-test" and typeData.name then | |||
achievementName = typeData.name | |||
mw.log("TITLE-DEBUG: Found title-test achievement with name: " .. achievementName) | |||
break | |||
end | |||
end | |||
end | |||
-- Fallback if name not found in JSON | |||
if not achievementName or achievementName == "" then | |||
achievementName = "Title Test" | |||
mw.log("TITLE-DEBUG: Using fallback name for title-test: " .. achievementName) | |||
end | |||
return "achievement-title-test", achievementName | return "achievement-title-test", achievementName | ||
end | end | ||
| Line 354: | Line 391: | ||
if isTestPage(pageId) then | if isTestPage(pageId) then | ||
debugLog("Creating test achievement for test page") | debugLog("Creating test achievement for test page") | ||
-- Look up the | |||
-- Look up the proper title-test achievement name from JSON | |||
local achievementName = Achievements.getAchievementName("title-test") | local achievementName = Achievements.getAchievementName("title-test") | ||
return '<div class="achievement-box-simple" data-achievement-type="title-test" | mw.log("ACHIEVEMENT-BOX: Using achievement name from getAchievementName(): " .. achievementName) | ||
htmlEncode(achievementName) .. '</div>' | |||
return '<div class="achievement-box-simple" data-achievement-type="title-test" data-achievement-name="' .. | |||
htmlEncode(achievementName) .. '">' .. htmlEncode(achievementName) .. '</div>' | |||
end | end | ||