Skip to content

Commit

Permalink
Refacto achievements list
Browse files Browse the repository at this point in the history
  • Loading branch information
Elanis committed May 10, 2024
1 parent 5b90953 commit ce20ba7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 30 deletions.
File renamed without changes.
27 changes: 27 additions & 0 deletions src/components/AchievementsList/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import './index.css';

export default function AchievementsList({ achievements, t }) {
console.log(achievements);
return (
<div class="achievement-list">
{achievements.map((currentAchievement) => {
return (
<div class="achievement-list-item">
<img src={`/img/alchemistry/achievements/${currentAchievement.name}_ok.png`} />
<div class="achievement-list-item-body">
<div class="achievement-list-item-title">
{t(`alchemistry:achievements:NEW_ACHIEVEMENT_1_${currentAchievement.index}_NAME`)}
</div>
<span class={'achievement-list-rarity' + ((currentAchievement.percent < 10) ? ' achievement-list-rarity-rare' : '')}>
{Math.floor(currentAchievement.percent)}%
</span>
<div class="achievement-list-item-description">
{currentAchievement.description}
</div>
</div>
</div>
);
})}
</div>
);
}
13 changes: 13 additions & 0 deletions src/components/AlchemistryAchievementDescription/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { neededItems, neededIngredients } from '/src/business/alchemistry_neededItems.js';

export default function AlchemistryAchievementDescription({ achievement, t }) {
return (
<div>
{t(`alchemistry:achievements:NEW_ACHIEVEMENT_1_${achievement.index}_DESC`).replace('N/A', '')}
{neededItems[achievement.name] && <details>
<summary>Item needed</summary>{/* TODO: i18n */}
You should create <b>{neededItems[achievement.name]}</b>{neededIngredients[achievement.name] && ` using ${neededIngredients[achievement.name]}`}.
</details>}
</div>
);
}
45 changes: 15 additions & 30 deletions src/pages/alchemistry/achievements.astro
Original file line number Diff line number Diff line change
@@ -1,49 +1,34 @@
---
import AchievementsList from '/src/components/AchievementsList';
import AlchemistryAchievementDescription from '/src/components/AlchemistryAchievementDescription';
import Layout from '/src/layout/layout.astro';
import { achievements } from '/src/business/alchemistry_achievementManager.js';
import { APP_ID } from '/src/business/alchemistry_constants.js';
import { neededItems, neededIngredients } from '/src/business/alchemistry_neededItems.js';
import getAchievementsPercentagesForGame from '/src/business/getAchievementsPercentagesForGame.js';
import { getLangFromUrl, useTranslations } from '/src/i18n/utils';
import '/src/css/achievements.css';
const lang = getLangFromUrl(Astro.url);
const t = useTranslations(lang);
const achievementsPercentages = await getAchievementsPercentagesForGame(APP_ID);
if(achievementsPercentages.length !== Object.keys(achievements).length) {
throw new Error('There are some missing achievements to generate the wiki');
}
const achievementsToDisplay = achievementsPercentages.map((achievementData) => {
const achievement = {
name: achievementData.name,
index: Object.keys(achievements).indexOf(achievementData.name),
percent: achievementData.percent
};
achievement.description = AlchemistryAchievementDescription({ t, achievement });
return achievement;
});
---
<Layout title="Alchemistry - Achievements">
<div class="achievement-list">
{achievementsPercentages.map((achievementData) => {
const achievement = achievementData.name;
const index = Object.keys(achievements).indexOf(achievement);

return (
<div class="achievement-list-item">
<img src={`/img/alchemistry/achievements/${achievement}_ok.png`} />
<div class="achievement-list-item-body">
<div class="achievement-list-item-title">
{t(`alchemistry:achievements:NEW_ACHIEVEMENT_1_${index}_NAME`)}
</div>
<span class={'achievement-list-rarity' + ((achievementData.percent < 10) ? ' achievement-list-rarity-rare' : '')}>
{Math.floor(achievementData.percent)}%
</span>
<div class="achievement-list-item-description">
{t(`alchemistry:achievements:NEW_ACHIEVEMENT_1_${index}_DESC`).replace('N/A', '')}
{neededItems[achievement] && <details>
<summary>Item needed</summary>{/* TODO: i18n */}
You should create <b>{neededItems[achievement]}</b>{neededIngredients[achievement] && ` using ${neededIngredients[achievement]}`}.
</details>}
</div>
</div>
</div>
);
})}
</div>
<AchievementsList t={t} achievements={achievementsToDisplay} />
</Layout>

0 comments on commit ce20ba7

Please sign in to comment.