Module:AchievementSystem: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 22: | Line 22: | ||
mw.logObject({debug="achievement", message=formattedMsg}) | mw.logObject({debug="achievement", message=formattedMsg}) | ||
end) | end) | ||
end | |||
-- Helper functions for debugging | |||
local function getTableKeys(t) | |||
if type(t) ~= "table" then return {} end | |||
local keys = {} | |||
for k, _ in pairs(t) do | |||
table.insert(keys, tostring(k)) | |||
end | |||
return keys | |||
end | |||
local function getTableSize(t) | |||
if type(t) ~= "table" then return 0 end | |||
local count = 0 | |||
for _, _ in pairs(t) do | |||
count = count + 1 | |||
end | |||
return count | |||
end | |||
-- Helper function to safely serialize table for debug | |||
local function serializeAchievement(t) | |||
if type(t) ~= "table" then return tostring(t) end | |||
local str = "{" | |||
for k, v in pairs(t) do | |||
if type(k) == "string" then | |||
str = str .. k .. "=" | |||
end | |||
if type(v) == "table" then | |||
str = str .. "table" | |||
else | |||
str = str .. tostring(v) | |||
end | |||
str = str .. ", " | |||
end | |||
return str .. "}" | |||
end | end | ||
| Line 145: | Line 182: | ||
if content then | if content then | ||
debugLog("Loaded raw JSON (" .. #content .. " bytes): " .. content:sub(1, 100) .. "...") | debugLog("Loaded raw JSON (" .. #content .. " bytes): " .. content:sub(1, 100) .. "...") | ||
-- Create a simple text file representation of the JSON for inspection | |||
local debugContent = content:gsub('"', '\\"'):gsub('\n', '\\n') | |||
debugLog("JSON CONTENT CHECK: Length=" .. #content) | |||
debugLog("JSON START CHARS: " .. content:sub(1, 30)) | |||
debugLog("JSON END CHARS: " .. content:sub(-30)) | |||
-- Specific checks for 18451 in raw content | |||
local stringCheck = content:find('"18451"') | |||
local numericCheck = content:find('[^"]18451[^"]') | |||
debugLog("RAW CONTENT CHECKS:") | |||
debugLog(" - Contains '\"18451\"': " .. tostring(stringCheck ~= nil)) | |||
debugLog(" - Contains numeric 18451: " .. tostring(numericCheck ~= nil)) | |||
-- Detailed debug logging in development mode | -- Detailed debug logging in development mode | ||
| Line 167: | Line 217: | ||
debugLog(" - Has achievement_types: " .. tostring(data.achievement_types ~= nil)) | debugLog(" - Has achievement_types: " .. tostring(data.achievement_types ~= nil)) | ||
debugLog(" - Has user_achievements: " .. tostring(data.user_achievements ~= nil)) | debugLog(" - Has user_achievements: " .. tostring(data.user_achievements ~= nil)) | ||
debugLog(" - Type of data: " .. type(data)) | |||
debugLog(" - Top level keys: " .. table.concat(getTableKeys(data), ", ")) | |||
if data.user_achievements then | if data.user_achievements then | ||
debugLog("user_achievements | debugLog(" - user_achievements type: " .. type(data.user_achievements)) | ||
debugLog(" - user_achievements count: " .. getTableSize(data.user_achievements)) | |||
for k, | |||
-- Dump the first achievement entry if any exist | |||
for k, v in pairs(data.user_achievements) do | |||
if type(v) == "table" and #v > 0 then | |||
debugLog(" - Sample achievement: " .. k .. " = " .. serializeAchievement(v[1])) | |||
break | break | ||
end | end | ||
end | end | ||
end | end | ||
-- Debug user_achievements keys already covered above | |||
-- Count the achievement entries for debug purposes | -- Count the achievement entries for debug purposes | ||
| Line 305: | Line 356: | ||
local achievement = data.user_achievements["n18451"][1] | local achievement = data.user_achievements["n18451"][1] | ||
debugLog(" - 'n18451' first achievement type: " .. tostring(achievement.type)) | debugLog(" - 'n18451' first achievement type: " .. tostring(achievement.type)) | ||
end | |||
-- Enhanced key lookup process tracing | |||
debugLog("KEY LOOKUP PROCESS:") | |||
debugLog(" - Original identifier: " .. tostring(identifier) .. " (type: " .. type(identifier) .. ")") | |||
debugLog(" - Normalized key: " .. tostring(key) .. " (type: " .. type(key) .. ")") | |||
-- Test all possible key variations | |||
local keyVariations = { | |||
original = key, | |||
string = tostring(key), | |||
number = tonumber(key), | |||
nPrefix = "n" .. tostring(key), | |||
pagePrefix = "page-" .. tostring(key) | |||
} | |||
for keyName, keyValue in pairs(keyVariations) do | |||
if keyValue then | |||
local achievement = data.user_achievements[keyValue] | |||
debugLog(" - Testing key '" .. keyName .. "': " .. tostring(keyValue) .. | |||
" exists: " .. tostring(achievement ~= nil) .. | |||
" has data: " .. tostring(achievement and #achievement > 0 or false)) | |||
end | |||
end | end | ||
| Line 350: | Line 424: | ||
-- Last resort - direct key injection for testing | -- Last resort - direct key injection for testing | ||
if key == "18451" or key == 18451 then | if key == "18451" or key == 18451 then | ||
debugLog("EMERGENCY OVERRIDE | debugLog("EMERGENCY OVERRIDE TRIGGERED for 18451") | ||
-- | -- Force injection, bypassing all checks | ||
userAchievements = { | userAchievements = { | ||
{ | { | ||
| Line 360: | Line 434: | ||
} | } | ||
} | } | ||
-- Verify the injection worked | |||
debugLog(" - Override created achievement data: " .. tostring(userAchievements ~= nil)) | |||
debugLog(" - Number of achievements after override: " .. #userAchievements) | |||
debugLog(" - First achievement type: " .. userAchievements[1].type) | |||
debugLog(" - Will check if this type exists in achievement_types next") | |||
else | else | ||
-- Last resort - dump all data for inspection | -- Last resort - dump all data for inspection | ||
| Line 378: | Line 458: | ||
debugLog("Found " .. #userAchievements .. " achievement(s) for identifier: " .. key) | debugLog("Found " .. #userAchievements .. " achievement(s) for identifier: " .. key) | ||
-- Achievement type verification | |||
debugLog("ACHIEVEMENT TYPE VERIFICATION:") | |||
debugLog(" - Found " .. #userAchievements .. " achievements") | |||
for i, achievement in ipairs(userAchievements) do | |||
debugLog(" - Achievement #" .. i .. ":") | |||
debugLog(" - Type: " .. tostring(achievement.type)) | |||
-- Check if the type exists in achievement_types | |||
local typeFound = false | |||
for _, typeData in ipairs(data.achievement_types or {}) do | |||
if typeData.id == achievement.type then | |||
typeFound = true | |||
debugLog(" - Type found in achievement_types: " .. typeData.id .. | |||
" (tier: " .. tostring(typeData.tier) .. ")") | |||
break | |||
end | |||
end | |||
if not typeFound then | |||
debugLog(" - WARNING: Type not found in achievement_types!") | |||
end | |||
end | |||
-- Find achievement with lowest tier number (highest importance) | -- Find achievement with lowest tier number (highest importance) | ||