diff --git a/constants/Games.ts b/constants/Games.ts index 89b4e2d24..988ed20bc 100644 --- a/constants/Games.ts +++ b/constants/Games.ts @@ -3,6 +3,7 @@ import { isCompletePathology, isCompleteSokopath } from '@root/helpers/validator import validatePathologySolution, { validatePathologyLevelValid as validatePathologyLevel } from '@root/helpers/validators/validatePathology'; import validateSokopathSolution, { validateSokopathLevel } from '@root/helpers/validators/validateSokopath'; import Level from '@root/models/db/level'; +import { AchievementCategory } from './achievements/achievementInfo'; import Direction from './direction'; import { GameId } from './GameId'; import Theme from './theme'; @@ -17,6 +18,7 @@ export const APP_DOMAIN = process.env.NEXT_PUBLIC_APP_DOMAIN || 'thinky.gg'; export const Games: Record = { [GameId.THINKY]: { id: GameId.THINKY, + achievementCategories: [AchievementCategory.SOCIAL], allowMovableOnExit: false, baseUrl: process.env.NODE_ENV !== 'development' ? `https://${APP_DOMAIN}` : 'http://localhost:3000', defaultTheme: Theme.Dark, @@ -42,6 +44,13 @@ export const Games: Record = { }, [GameId.PATHOLOGY]: { id: GameId.PATHOLOGY, + achievementCategories: [ + AchievementCategory.PROGRESS, + AchievementCategory.CREATOR, + AchievementCategory.SKILL, + AchievementCategory.REVIEWER, + AchievementCategory.MULTIPLAYER, + ], allowMovableOnExit: false, baseUrl: process.env.NODE_ENV !== 'development' ? `https://pathology.${APP_DOMAIN}` : 'http://pathology.localhost:3000', chapterCount: 4, @@ -71,6 +80,13 @@ export const Games: Record = { }, [GameId.SOKOPATH]: { id: GameId.SOKOPATH, + achievementCategories: [ + AchievementCategory.PROGRESS, + AchievementCategory.CREATOR, + AchievementCategory.SKILL, + AchievementCategory.REVIEWER, + AchievementCategory.MULTIPLAYER, + ], allowMovableOnExit: true, baseUrl: process.env.NODE_ENV !== 'development' ? `https://sokopath.${APP_DOMAIN}` : 'http://sokopath.localhost:3000', defaultTheme: Theme.Winter, @@ -110,6 +126,7 @@ export interface ValidateLevelResponse { export interface Game { id: GameId; + achievementCategories: AchievementCategory[]; /** * If movables can start on exits */ diff --git a/constants/achievements/AchievementRulesSocial.ts b/constants/achievements/AchievementRulesSocial.ts index 8d7238200..1829e78aa 100644 --- a/constants/achievements/AchievementRulesSocial.ts +++ b/constants/achievements/AchievementRulesSocial.ts @@ -11,7 +11,7 @@ AchievementRulesSocial[AchievementType.COMMENT_1] = { getDescription: () => 'Wrote a comment', name: 'Chatty', emoji: '💬', - discordNotification: true, + discordNotification: false, secret: false, unlocked: ({ commentCount }) => { return (commentCount >= 1); @@ -21,7 +21,7 @@ AchievementRulesSocial[AchievementType.COMMENT_5] = { getDescription: () => 'Wrote 5 comments', name: 'Conversationalist', emoji: '🗣️', - discordNotification: true, + discordNotification: false, secret: false, unlocked: ({ commentCount }) => { return (commentCount >= 5); diff --git a/helpers/refreshAchievements.ts b/helpers/refreshAchievements.ts index 918e137d2..f8441cea2 100644 --- a/helpers/refreshAchievements.ts +++ b/helpers/refreshAchievements.ts @@ -100,8 +100,9 @@ export async function refreshAchievements(gameId: GameId, userId: Types.ObjectId // it is more efficient to just grab all their achievements then to loop through and query each one if they have it const game = Games[gameId]; const fetchPromises = []; + const adjustedCategories = categories.filter((category) => game.achievementCategories.includes(category)); - for (const category of categories) { + for (const category of adjustedCategories) { fetchPromises.push(AchievementCategoryFetch[category](gameId, userId)); } @@ -114,7 +115,7 @@ export async function refreshAchievements(gameId: GameId, userId: Types.ObjectId const neededData = neededDataArray.reduce((acc, cur) => ({ ...acc, ...cur }), {}); let achievementsCreated = 0; - for (const category of categories) { + for (const category of adjustedCategories) { const achievementsCreatedPromises = []; const categoryRulesTable = AchievementCategoryMapping[category]; diff --git a/server/scripts/save.ts b/server/scripts/save.ts index 9ee21270d..b47559a4b 100644 --- a/server/scripts/save.ts +++ b/server/scripts/save.ts @@ -6,13 +6,14 @@ import { AchievementCategory } from '@root/constants/achievements/achievementInfo'; import { GameId } from '@root/constants/GameId'; +import { Games } from '@root/constants/Games'; +import { refreshAchievements } from '@root/helpers/refreshAchievements'; import Level from '@root/models/db/level'; import MultiplayerProfile from '@root/models/db/multiplayerProfile'; import PlayAttempt from '@root/models/db/playAttempt'; import Record from '@root/models/db/record'; import UserConfig from '@root/models/db/userConfig'; import { AttemptContext } from '@root/models/schemas/playAttemptSchema'; -import { queueRefreshAchievements } from '@root/pages/api/internal-jobs/worker'; import cliProgress from 'cli-progress'; import dotenv from 'dotenv'; import dbConnect from '../../lib/dbConnect'; @@ -306,8 +307,7 @@ async function integrityCheckAcheivements() { progressBar.start(users.length, 0); for (const user of users) { - // TODO - loop through all games and refresh achievements for each game - await queueRefreshAchievements(GameId.PATHOLOGY, user._id, allAchievementCategories as AchievementCategory[], { session: null }); + await Promise.all(Object.values(Games).map((game) => refreshAchievements(game.id, user._id, allAchievementCategories))); progressBar.increment(); }