Skip to content

Commit

Permalink
remove achievement state hack
Browse files Browse the repository at this point in the history
  • Loading branch information
dhenkel92 committed May 29, 2024
1 parent b1cef53 commit a4960fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions common/achievement/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ const assembleAchievementData = async (userAchievements: achievements_with_templ
let currentAchievementIndex = userAchievements.findIndex((ua) => !ua.achievedAt);
currentAchievementIndex = currentAchievementIndex >= 0 ? currentAchievementIndex : userAchievements.length - 1;

let achievementTemplates = await prisma.achievement_template.findMany({
const achievementTemplates = await prisma.achievement_template.findMany({
where: { group: userAchievements[currentAchievementIndex].template.group, isActive: true },
orderBy: { groupOrder: 'asc' },
});
const derivedTemplates = deriveAchievementTemplates(userAchievements[currentAchievementIndex].template.group);
achievementTemplates = [...achievementTemplates, ...derivedTemplates];
achievementTemplates.push(...derivedTemplates);
achievementTemplates.sort((left, right) => left.groupOrder - right.groupOrder);

let maxValue: number = achievementTemplates.length;
Expand Down Expand Up @@ -202,7 +202,7 @@ const assembleAchievementData = async (userAchievements: achievements_with_templ
maxValue = Object.keys(conditionDataAggregations).reduce((acc, key) => acc + conditionDataAggregations[key].valueToAchieve, 0);
}

const state: AchievementState = getAchievementState(userAchievements, currentAchievementIndex, achievementTemplates);
const state: AchievementState = getAchievementState(userAchievements, currentAchievementIndex);
const isNewAchievement = state === AchievementState.COMPLETED && !userAchievements[currentAchievementIndex].isSeen;

const achievementContext = transformPrismaJson(
Expand Down
4 changes: 2 additions & 2 deletions common/achievement/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ export function renderAchievementWithContext(
return currentAchievementContext as achievement_template;
}

export function getAchievementState(userAchievements: user_achievement[], currentAchievementIndex: number, templates: achievement_template[]) {
export function getAchievementState(userAchievements: user_achievement[], currentAchievementIndex: number) {
return userAchievements.length === 0
? AchievementState.INACTIVE
: userAchievements.length === templates.length && userAchievements[currentAchievementIndex].achievedAt
: userAchievements[currentAchievementIndex].achievedAt
? AchievementState.COMPLETED
: AchievementState.ACTIVE;
}
Expand Down

0 comments on commit a4960fa

Please sign in to comment.