Module:AchievementSystem: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 102: | Line 102: | ||
--[[ | --[[ | ||
Loads achievement data from MediaWiki:AchievementData.json | Loads achievement data from MediaWiki:AchievementData.json | ||
DEVELOPMENT MODE: Bypassing all caching for debugging | |||
@return table The achievement data structure or default empty structure on failure | @return table The achievement data structure or default empty structure on failure | ||
| Line 108: | Line 108: | ||
function Achievements.loadData() | function Achievements.loadData() | ||
local success, result = pcall(function() | local success, result = pcall(function() | ||
-- | -- BYPASSING ALL CACHING | ||
debugLog("CACHE BYPASS ENABLED: Loading directly from wiki page") | |||
-- | -- Load data directly from the wiki | ||
local | debugLog("Loading achievement data directly from " .. ACHIEVEMENT_DATA_PAGE) | ||
local content = safeGetPageContent(ACHIEVEMENT_DATA_PAGE) | |||
-- | -- Debug the raw JSON content | ||
if | if content then | ||
debugLog("Loaded | debugLog("Loaded raw JSON (" .. #content .. " bytes): " .. content:sub(1, 100) .. "...") | ||
else | |||
debugLog("ERROR: Could not load content from " .. ACHIEVEMENT_DATA_PAGE) | |||
end | end | ||
local data = safeParseJSON(content) | local data = safeParseJSON(content) | ||
-- If something went wrong, use default empty data | -- If something went wrong, use default empty data | ||
if not data then | if not data then | ||
debugLog("ERROR: Failed to | debugLog("ERROR: Failed to parse JSON data - using default empty structure") | ||
data = DEFAULT_DATA | data = DEFAULT_DATA | ||
else | else | ||
-- Count the achievement entries for debug purposes | -- Count the achievement entries for debug purposes | ||
local count = 0 | local count = 0 | ||
for k, | debugLog("Achievement entries:") | ||
count = count + 1 | for k, v in pairs(data.user_achievements or {}) do | ||
count = count + 1 | |||
debugLog("User/Page ID found: " .. k .. " with " .. #v .. " achievements") | |||
end | end | ||
debugLog("Loaded achievement data with " .. count .. " achievement entries") | debugLog("Loaded achievement data with " .. count .. " achievement entries") | ||
end | end | ||
-- | -- DON'T update cache variables | ||
dataCache = data | -- dataCache = data | ||
return data | return data | ||
| Line 228: | Line 223: | ||
-- This is a page ID, ensure it's treated as a string for table lookup | -- This is a page ID, ensure it's treated as a string for table lookup | ||
key = tostring(identifier) | key = tostring(identifier) | ||
debugLog("Searching for Page ID: " .. key) | debugLog("Searching for Page ID: " .. key .. " (type: " .. type(key) .. ")") | ||
end | end | ||
-- Debug the user_achievements structure | |||
debugLog("All available user_achievements keys:") | |||
for k, _ in pairs(data.user_achievements or {}) do | |||
debugLog(" - " .. k .. " (type: " .. type(k) .. ")") | |||
end | |||
-- Check if our key exists directly | |||
local keyExists = data.user_achievements[key] ~= nil | |||
debugLog("Key '" .. key .. "' exists in user_achievements: " .. tostring(keyExists)) | |||
local userAchievements = data.user_achievements[key] | local userAchievements = data.user_achievements[key] | ||
| Line 235: | Line 240: | ||
if not userAchievements or #userAchievements == 0 then | if not userAchievements or #userAchievements == 0 then | ||
debugLog("No achievements found for identifier: " .. key) | debugLog("No achievements found for identifier: " .. key) | ||
return nil | |||
-- Fallback: try a numeric key if the string version didn't work | |||
if tonumber(key) then | |||
local numKey = tonumber(key) | |||
debugLog("Trying fallback with numeric key: " .. numKey) | |||
userAchievements = data.user_achievements[numKey] | |||
if userAchievements and #userAchievements > 0 then | |||
debugLog("Found achievements using numeric key!") | |||
key = numKey | |||
else | |||
debugLog("No achievements found using numeric key either") | |||
return nil | |||
end | |||
else | |||
return nil | |||
end | |||
end | end | ||