Module:AchievementSystem: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 90: Line 90:
     achievement_types = {},
     achievement_types = {},
     user_achievements = {},
     user_achievements = {},
    cache_control = { version = 0 }
}
}
--------------------------------------------------------------------------------
-- Configuration
--------------------------------------------------------------------------------
-- This array maps legacy achievement IDs to standardized ones
local ACHIEVEMENT_TYPE_MAPPING = {
    ["title-test"] = "dev-role",
    ["jedi"]      = "ach1",
    ["champion"]  = "ach2",
    ["sponsor"]  = "ach3"
}
-- Normalizes achievement type to handle variants or legacy types
local function normalizeAchievementType(achievementType)
    if not achievementType then return nil end
   
    -- If it's already a standard type, return it directly
    if achievementType == "dev-role" or
      achievementType == "ach1" or
      achievementType == "ach2" or
      achievementType == "ach3" then
        return achievementType
    end
   
    -- Otherwise check the mapping table
    return ACHIEVEMENT_TYPE_MAPPING[achievementType] or achievementType
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 441: Line 413:
      
      
     return nil
     return nil
end
--------------------------------------------------------------------------------
-- Diagnostic Function: Log badges for a page to console
--------------------------------------------------------------------------------
function Achievements.debugBadgesForPage(pageId)
    if not pageId or pageId == '' then
        return "ERROR: No page ID provided"
    end
    local userAchievements = Achievements.getUserAchievements(pageId)
    if #userAchievements == 0 then
        return "No achievements found for page ID " .. pageId
    end
   
    -- Build output string instead of logging
    local output = {}
    table.insert(output, "Found " .. #userAchievements .. " achievements for page ID " .. pageId)
   
    -- Add each achievement to output
    for i, achievement in ipairs(userAchievements) do
        local achType = achievement.type or "nil"
        local typeDef = Achievements.getAchievementDefinition(achType)
       
        if typeDef then
            table.insert(output, "[" .. i .. "] " .. achType ..
                  " (Name: " .. (typeDef.name or "unnamed") ..
                  ", Type: " .. (typeDef.type or "unspecified") ..
                  ", Tier: " .. (typeDef.tier or "none") .. ")")
        else
            table.insert(output, "[" .. i .. "] " .. achType .. " (WARNING: No definition found)")
        end
    end
   
    return table.concat(output, "\n")
end
end