Skip to content

Commit e5a0bfd

Browse files
committed
Refactor cooking achievements to be data-driven
Replaces hardcoded achievement items in the Cooking tab with a dynamic, data-driven approach. Achievements are now generated from a configuration array and passed as props, improving maintainability and scalability.
1 parent dbaffbc commit e5a0bfd

2 files changed

Lines changed: 57 additions & 32 deletions

File tree

src/Components/AchieveTabs/Cooking/index.tsx

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,28 @@
11
import type { cookingDataType } from 'types/displayDataTypes';
2-
import { Cook, SousChef, GourmetChef } from '@media/Achievements';
32
import './Cooking.css';
43
import { AchievementItem,ItemWithCounter } from '@components/common';
54

6-
const Food = ( {cookedItems, knownRecipes, alreadyCookedRecipes} : cookingDataType) => {
5+
const Food = ( {cookedItems, knownRecipes, alreadyCookedRecipes, totalRecipes, achievements} : cookingDataType) => {
6+
console.log('a', achievements)
77
return (
88
<div className="progress-container">
99
<span className="a-title">
1010
<h2>
11-
Has cooked {alreadyCookedRecipes}, knowing {knownRecipes} out of 81 recipes
11+
Has cooked {alreadyCookedRecipes}, knowing {knownRecipes} out of {totalRecipes} recipes
1212
</h2>
1313
</span>
1414
<br />
1515
<h2>Cooking Achievements</h2>
1616
<div className="section-achievements">
17-
<AchievementItem
18-
done={alreadyCookedRecipes >= 10}
19-
image={Cook}
20-
achievementName="Cook"
21-
achievementDesc="Cook a total of 10 dishes"
22-
achievementHoverDesc={alreadyCookedRecipes >= 10 ?
23-
'Achievement unlocked!' :
24-
'You need to cook at least 10 dishes to unlock this achievement.'}
25-
/>
26-
<AchievementItem
27-
done={alreadyCookedRecipes >= 25}
28-
image={SousChef}
29-
achievementName="Sous Chef"
30-
achievementDesc="Cook a total of 25 dishes"
31-
achievementHoverDesc={alreadyCookedRecipes >= 25 ?
32-
'Achievement unlocked!' :
33-
`You need to cook ${25 - alreadyCookedRecipes} more dishes to unlock this achievement.`}
34-
/>
35-
<AchievementItem
36-
done={alreadyCookedRecipes >= 81}
37-
image={GourmetChef}
38-
achievementName="Gourmet Chef"
39-
achievementDesc="Cook a total of 81 dishes"
40-
achievementHoverDesc={alreadyCookedRecipes >= 81 ?
41-
'Achievement unlocked!' :
42-
`You need to cook ${81 - alreadyCookedRecipes} more dishes to unlock this achievement.`}
43-
/>
17+
{achievements && achievements.map((ach, i) => (
18+
<AchievementItem
19+
key={i}
20+
done={ach.done}
21+
image={ach.image}
22+
achievementName={ach.name}
23+
achievementDesc={ach.description}
24+
achievementHoverDesc={ach.hoverDesc}
25+
/>))}
4426
</div>
4527
<br />
4628
<div className="dishes-grid">

src/Utility/Parsers/parseCookingItems.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
import type { itemsType, itemType } from "types/savefile";
22
import { Dishes } from "../JSON";
33
import { GetImages, ValidateKnown } from "./Utils";
4-
import type { cookingDataType, generalFormatedItemType } from "types/displayDataTypes";
4+
import type { achievementType, cookingDataType, generalFormatedItemType } from "types/displayDataTypes";
5+
import { Cook, SousChef, GourmetChef } from '@media/Achievements';
6+
7+
8+
let CookingAchievements = [{
9+
goal: 10,
10+
image: Cook,
11+
name: 'Cook',
12+
done: false,
13+
description: 'Cook a total of 10 dishes',
14+
hoverDesc: ''
15+
},{
16+
goal: 25,
17+
image: SousChef,
18+
name: 'Cook',
19+
description: 'Cook a total of 25 dishes',
20+
hoverDesc: ''
21+
},{
22+
goal: Dishes.Dishes.length,
23+
image: GourmetChef,
24+
name: 'Cook',
25+
description: 'Cook All dishes',
26+
hoverDesc: ''
27+
}
28+
];
529

630
export const GetCookingData = (cooked: itemType, known: itemsType[]): cookingDataType =>{
731
let data: generalFormatedItemType[] = [];
@@ -23,7 +47,26 @@ export const GetCookingData = (cooked: itemType, known: itemsType[]): cookingDat
2347
}
2448
data.push(d);
2549
})
26-
return { knownRecipes, alreadyCookedRecipes: alreadyCooked, cookedItems: data };
50+
const totalRecipes = Dishes.Dishes.length;
51+
return {
52+
knownRecipes,
53+
alreadyCookedRecipes: alreadyCooked,
54+
cookedItems: data,
55+
achievements: GetAchievementData(alreadyCooked),
56+
totalRecipes };
57+
}
58+
59+
const GetAchievementData = (alreadyCooked: number) : achievementType[] => {
60+
let achievements = CookingAchievements.map(ach => {
61+
return {
62+
...ach,
63+
done: alreadyCooked >= ach.goal,
64+
hoverDesc: alreadyCooked >= ach.goal ?
65+
'Achievement unlocked!' :
66+
`You need to cook ${ach.goal - alreadyCooked} more dishes to unlock this achievement.`
67+
}
68+
});
69+
return achievements;
2770
}
2871

2972
const GetCooked = (cookedItems:itemsType[], id: number): number => {

0 commit comments

Comments
 (0)