Skip to content

Commit

Permalink
achievementCategories
Browse files Browse the repository at this point in the history
  • Loading branch information
sspenst committed May 15, 2024
1 parent 9269f1c commit dc445b2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
17 changes: 17 additions & 0 deletions constants/Games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -17,6 +18,7 @@ export const APP_DOMAIN = process.env.NEXT_PUBLIC_APP_DOMAIN || 'thinky.gg';
export const Games: Record<GameId, Game> = {
[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,
Expand All @@ -42,6 +44,13 @@ export const Games: Record<GameId, Game> = {
},
[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,
Expand Down Expand Up @@ -71,6 +80,13 @@ export const Games: Record<GameId, Game> = {
},
[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,
Expand Down Expand Up @@ -110,6 +126,7 @@ export interface ValidateLevelResponse {

export interface Game {
id: GameId;
achievementCategories: AchievementCategory[];
/**
* If movables can start on exits
*/
Expand Down
4 changes: 2 additions & 2 deletions constants/achievements/AchievementRulesSocial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions helpers/refreshAchievements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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];

Expand Down
6 changes: 3 additions & 3 deletions server/scripts/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit dc445b2

Please sign in to comment.