diff --git a/src/views/achievements/AchievementsView.tsx b/src/views/achievements/AchievementsView.tsx index 9ef315a6..a3bfbaca 100644 --- a/src/views/achievements/AchievementsView.tsx +++ b/src/views/achievements/AchievementsView.tsx @@ -158,6 +158,11 @@ export const AchievementsView: FC = props => return progress; }, [ achievementCategories ]); + const scaledProgressPercent = useMemo(() => + { + return ~~((((getProgress - 0) * (100 - 0)) / (getMaxProgress - 0)) + 0); + }, [ getProgress, getMaxProgress ]); + const getSelectedCategory = useMemo(() => { if(!achievementCategories || !achievementCategories.length) return null; @@ -220,8 +225,10 @@ export const AchievementsView: FC = props => <> - - { LocalizeText('achievements.categories.totalprogress', [ 'progress', 'limit' ], [ getProgress.toString(), getMaxProgress.toString() ]) } + + + { LocalizeText('achievements.categories.totalprogress', [ 'progress', 'limit' ], [ getProgress.toString(), getMaxProgress.toString() ]) } + { LocalizeText('achievements.categories.score', [ 'score' ], [ achievementScore.toString() ]) } diff --git a/src/views/achievements/common/GetAchievementLevel.ts b/src/views/achievements/common/GetAchievementLevel.ts new file mode 100644 index 00000000..c62bf7aa --- /dev/null +++ b/src/views/achievements/common/GetAchievementLevel.ts @@ -0,0 +1,8 @@ +import { AchievementData } from '@nitrots/nitro-renderer'; + +export const GetAchievementLevel = (achievement: AchievementData) => +{ + if(achievement.finalLevel) return achievement.level; + + return (achievement.level - 1); +} diff --git a/src/views/achievements/common/GetScaledProgressPercent.ts b/src/views/achievements/common/GetScaledProgressPercent.ts new file mode 100644 index 00000000..8708a709 --- /dev/null +++ b/src/views/achievements/common/GetScaledProgressPercent.ts @@ -0,0 +1,8 @@ +import { AchievementData } from '@nitrots/nitro-renderer'; + +export const GetScaledProgressPercent = (achievement: AchievementData) => +{ + if(!achievement) return 0; + + return ~~(((((achievement.currentPoints + achievement.scoreAtStartOfLevel) - 0) * (100 - 0)) / ((achievement.scoreLimit + achievement.scoreAtStartOfLevel) - 0)) + 0); +} diff --git a/src/views/achievements/views/achievement-details/AchievementDetailsView.tsx b/src/views/achievements/views/achievement-details/AchievementDetailsView.tsx index be50d707..5ab5d320 100644 --- a/src/views/achievements/views/achievement-details/AchievementDetailsView.tsx +++ b/src/views/achievements/views/achievement-details/AchievementDetailsView.tsx @@ -1,9 +1,11 @@ -import { FC, useMemo } from 'react'; +import { FC } from 'react'; import { LocalizeBadgeDescription, LocalizeBadgeName, LocalizeText } from '../../../../api'; import { NitroLayoutFlex, NitroLayoutFlexColumn } from '../../../../layout'; import { NitroLayoutBase } from '../../../../layout/base'; import { CurrencyIcon } from '../../../shared/currency-icon/CurrencyIcon'; import { AchievementUtilities } from '../../common/AchievementUtilities'; +import { GetAchievementLevel } from '../../common/GetAchievementLevel'; +import { GetScaledProgressPercent } from '../../common/GetScaledProgressPercent'; import { AchievementBadgeView } from '../achievement-badge/AchievementBadgeView'; import { AchievementDetailsViewProps } from './AchievementDetailsView.types'; @@ -11,25 +13,17 @@ export const AchievementDetailsView: FC = props => { const { achievement = null } = props; - const getAchievementLevel = useMemo(() => - { - if(achievement.finalLevel) return achievement.level; - - return (achievement.level - 1); - }, [ achievement ]); - if(!achievement) return null; - const currentAmount = achievement.currentPoints; - const maxAmount = achievement.scoreLimit; - const scoreAtStartOfLevel = achievement.scoreAtStartOfLevel; + const achievementLevel = GetAchievementLevel(achievement); + const scaledProgressPercent = GetScaledProgressPercent(achievement); return ( - { LocalizeText('achievements.details.level', [ 'level', 'limit' ], [ getAchievementLevel.toString(), achievement.levelCount.toString() ]) } + { LocalizeText('achievements.details.level', [ 'level', 'limit' ], [ achievementLevel.toString(), achievement.levelCount.toString() ]) } @@ -41,20 +35,24 @@ export const AchievementDetailsView: FC = props => { LocalizeBadgeDescription(AchievementUtilities.getBadgeCode(achievement)) } - { ((achievement.levelRewardPoints > 0) || (maxAmount > 0)) && + { ((achievement.levelRewardPoints > 0) || (achievement.scoreLimit > 0)) && { (achievement.levelRewardPoints > 0) && - + { LocalizeText('achievements.details.reward') } - + { achievement.levelRewardPoints } } - { (maxAmount > 0) && - LocalizeText('achievements.details.progress', [ 'progress', 'limit' ], [ (currentAmount + scoreAtStartOfLevel).toString(), (maxAmount + scoreAtStartOfLevel).toString() ]) } + { (achievement.scoreLimit > 0) && + + + { LocalizeText('achievements.details.progress', [ 'progress', 'limit' ], [ (achievement.currentPoints + achievement.scoreAtStartOfLevel).toString(), (achievement.scoreLimit + achievement.scoreAtStartOfLevel).toString() ]) } + + } } diff --git a/src/views/achievements/views/achievement-list/AchievementListView.tsx b/src/views/achievements/views/achievement-list/AchievementListView.tsx index 8cb6d7e1..4475e263 100644 --- a/src/views/achievements/views/achievement-list/AchievementListView.tsx +++ b/src/views/achievements/views/achievement-list/AchievementListView.tsx @@ -9,9 +9,9 @@ export const AchievementListView: FC = props => return ( - { achievements && (achievements.length > 0) && achievements.map(achievement => + { achievements && (achievements.length > 0) && achievements.map((achievement, index) => { - return setSelectedAchievementId(achievement.achievementId) } />; + return setSelectedAchievementId(achievement.achievementId) } />; }) } );