Skip to content

Commit 71cbdc5

Browse files
committed
Refactor fish achievements and display logic
Reworked fish achievement logic by introducing a parser (parseFishItems.ts) that aggregates caught fish, total, and achievement progress. Updated types and components to use the new fishCaughtType structure, improved achievement and fish item rendering, and removed legacy fish parsing code from Utility/index.tsx.
1 parent 17581f0 commit 71cbdc5

6 files changed

Lines changed: 121 additions & 45 deletions

File tree

src/Components/AchieveTabs/Fish/index.tsx

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,50 @@
1-
import React, { useState, useEffect } from 'react'
2-
import type { generalFormatedItemType } from 'types/displayDataTypes';
1+
import { AchievementItem, ItemWithCounter } from '@components/common';
2+
import type { fishCaughtType } from 'types/displayDataTypes';
33

4-
interface FishProps {
5-
fishCaught: generalFormatedItemType[];
6-
}
7-
8-
const Fish = ({ fishCaught }: FishProps) => {
9-
const [totalFished, setTotalFished] = useState(0);
10-
11-
const getCraftedItems = (items: generalFormatedItemType[]) => {
12-
return items.map((num) => (num.fished) ? 1 : 0).reduce((n: number, next: number) => next + n, 0);
13-
};
14-
15-
useEffect(() => {
16-
setTotalFished(getCraftedItems(fishCaught));
17-
}, [fishCaught]);
4+
const Fish = ({
5+
fishCaught,
6+
catchedFish,
7+
total,
8+
achievements }: fishCaughtType) => {
189

1910
return (
2011
<div className="progress-container">
21-
<span className="a-title"><h1>{ `You've fished ${totalFished} out of ${fishCaught.length}`}</h1></span>
12+
<span className="a-title">
13+
<h2>
14+
Has fished {fishCaught} out of {total}.
15+
</h2>
16+
</span>
2217
<br />
2318
<h2>Fishing Achievements</h2>
24-
<ul className="a-List">
25-
<li>Fisherman: {(totalFished >= 10) ? <span className="completed">You have this achievement</span> : <span className="pending">You need to catch {15 - totalFished} more fish to get this</span> } </li>
26-
<li>Ol' Mariner: {(totalFished >= 24) ? <span className="completed">You have this achievement</span> : <span className="pending">You need to catch {30 - totalFished} more fish to get this </span>}</li>
27-
<li>Master Angler : {(totalFished >= fishCaught.length) ? <span className="completed">You have this achievement</span> : <span className="pending">You need to catch {fishCaught.length - totalFished} more fish to get this </span>}</li>
28-
</ul>
19+
20+
<div className="section-achievements">
21+
{achievements && achievements.map((ach, i) => (
22+
<AchievementItem
23+
key={i}
24+
done={ach.done}
25+
image={ach.image}
26+
achievementName={ach.name}
27+
achievementDesc={ach.description}
28+
achievementHoverDesc={ach.hoverDesc}
29+
/>))}
30+
</div>
2931
<br />
30-
{fishCaught.map((fish, i) => <a href={`https://stardewvalleywiki.com/${fish.image}`} target="_blank" rel="noreferrer" key={i}><img key={i} src={`https://stardew-tracker.s3.amazonaws.com/Fishing/${fish.image}.png`} alt={fish.name} className={ (fish.fished) ? "done" : ""} title={(fish.fished) ? `You've caught ${fish.name}` : `You haven't fished ${fish.name}`} ></img></a>)}
31-
32+
<div className="item-grid">
33+
{ catchedFish ?
34+
catchedFish.map((d, i) =>
35+
<ItemWithCounter
36+
key={i}
37+
link={`https://stardewvalleywiki.com/${d.link}`}
38+
src={`https://stardew-tracker.s3.amazonaws.com/Fishing/${d.image}.png`}
39+
name={d.name}
40+
state={ (d.fished) ? "done" : "unknown" }
41+
hoverDesc={(d.fished) ? `Has caught ${d.name}`
42+
: `You haven't caught ${d.name}`}
43+
times={d.fished ? null : undefined}
44+
/>)
45+
: <div>No fishing data available.</div>
46+
}
47+
</div>
3248
</div>
3349
);
3450
};

src/Components/Achievements/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const Achievements = ({
4848
{img: TabQuests, alt: "Quests"},
4949
{img: TabGrandpa, alt: "Grandpa's evaluation"}
5050
];
51+
console.log("Achievements:", fishCaught);
5152
console.log("Professions in Achievements:", professions);
5253
return (
5354
<div className="file-container">
@@ -77,7 +78,7 @@ const Achievements = ({
7778
</TabPanel>
7879
<TabPanel>
7980
<section className="achievement-container">
80-
<Fish fishCaught={fishCaught} />
81+
<Fish {...fishCaught} />
8182
</section>
8283
</TabPanel>
8384
<TabPanel>

src/Components/common/ItemWithCounter.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type ItemWithCounterProps = {
55
name: string;
66
state: 'done' | 'known' | 'unknown';
77
hoverDesc?: string;
8-
times?: number | undefined;
8+
times?: number | undefined | null;
99
}
1010

1111
const ItemWithCounter = ({
@@ -32,6 +32,7 @@ const ItemWithCounter = ({
3232
</img>
3333
{times === undefined ?
3434
<p className="item-unknown">?</p> :
35+
times === null ? null :
3536
<p className="item-times"> x{times}</p> }
3637
</a>
3738
);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import type { itemsType } from "types/savefile";
2+
import { Fishes } from "../JSON";
3+
import { GetImages } from "./Utils";
4+
import type { achievementType, generalFormatedItemType } from "types/displayDataTypes";
5+
import { Fisherman, OlMariner, MasterAngler } from '@media/Achievements';
6+
7+
let CookingAchievements = [{
8+
goal: 10,
9+
image: Fisherman,
10+
name: 'Fisherman',
11+
done: false,
12+
description: 'Catch a total of 10 unique fishes',
13+
hoverDesc: ''
14+
},{
15+
goal: 24,
16+
image: OlMariner,
17+
name: 'Ol\' Mariner',
18+
done: false,
19+
description: 'Catch a total of 24 unique fishes',
20+
hoverDesc: ''
21+
},{
22+
goal: Fishes.length,
23+
image: MasterAngler,
24+
name: 'Master Angler',
25+
done: false,
26+
description: 'Catch All fishes',
27+
hoverDesc: ''
28+
}
29+
];
30+
31+
export const GetFishes = (allFished: itemsType[]) => {
32+
const totalFishes = Fishes.length;
33+
let data: generalFormatedItemType[] = []
34+
let fishCaught = 0;
35+
36+
Fishes.forEach(item => {
37+
let caught = (Array.isArray(allFished)) ? (allFished.find(i => i.key.int === item.id ) !== undefined) : false
38+
if(caught) fishCaught++;
39+
let d = {
40+
name: item.name,
41+
image: GetImages(item.name),
42+
id: item.id,
43+
fished: caught
44+
}
45+
data.push(d)
46+
})
47+
48+
return {
49+
catchedFish: data,
50+
fishCaught,
51+
total: totalFishes,
52+
achievements: GetAchievementData(fishCaught)
53+
}
54+
}
55+
56+
const GetAchievementData = (alreadyCooked: number) : achievementType[] => {
57+
let achievements = CookingAchievements.map(ach => {
58+
return {
59+
...ach,
60+
done: alreadyCooked >= ach.goal,
61+
hoverDesc: alreadyCooked >= ach.goal ?
62+
'Achievement unlocked!' :
63+
`You need to catch ${ach.goal - alreadyCooked} more fishes to unlock this achievement.`
64+
}
65+
});
66+
return achievements;
67+
}

src/Utility/index.tsx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import type { fullPlayerDataType, museumCollectionType } from 'types/displayData
3939
import { GetCookingData } from './Parsers/parseCookingItems';
4040
import { GetCraftingRecipes } from './Parsers/parseCraftingItems';
4141
import { GetCropsAchievements } from './Parsers/parseCropItems';
42+
import { GetFishes } from './Parsers/parseFishItems';
4243

4344
//Gets the info from the farm hands as an array of the same type
4445
const GetFarmHands = (locations: gameLocationType[]): playerType[] => {
@@ -116,7 +117,7 @@ const parseData = ({
116117
cropsShipped: GetCropsAchievements(playerData.basicShipped?.item),//Refactored DONE
117118
//mineralsFound: GetArrayData(playerData.mineralsFound?.item) || [], //DONE
118119
cookingData: GetCookingData(playerData.recipesCooked, playerData.cookingRecipes.item) || [], //DONE
119-
fishCaught: GetFishes(playerData.fishCaught.item) || [],
120+
fishCaught: GetFishes(playerData.fishCaught.item),
120121
tailoredItems: GetArrayDataTimeless(playerData.tailoredItems) || [],
121122
itemsCrafted: GetCraftingRecipes(playerData.craftingRecipes.item) || [],
122123
friendship: GetFriendshipData(playerData.friendshipData.item) || [],
@@ -231,23 +232,6 @@ const GetShippedItems = (allShipped: itemType) :generalFormatedItemType[] => {
231232
return data;
232233
}
233234

234-
/* End of Crop Related Achievements */
235-
236-
const GetFishes = (allFished: itemsType[]) => {
237-
let data: generalFormatedItemType[] = []
238-
239-
Fishes.forEach(item => {
240-
let d = {
241-
name: item.name,
242-
image: GetImages(item.name),
243-
id: item.id,
244-
fished: (Array.isArray(allFished)) ? (allFished.find(i => i.key.int === item.id ) !== undefined) : false
245-
}
246-
data.push(d)
247-
})
248-
249-
return data
250-
}
251235

252236
const GetFriendshipData = (allFriends: friendshipDataType[]): formatedFriendshipDataType[] => {
253237
let data: formatedFriendshipDataType[] = []

src/types/displayDataTypes.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type fullPlayerDataType = {
1616
cookingData: cookingDataType;
1717
museumCollection: museumCollectionType;
1818
availableSpecialRequests: string[];
19-
fishCaught: generalFormatedItemType[];
19+
fishCaught: fishCaughtType;
2020
friendship: formatedFriendshipDataType[];
2121
itemsCrafted: itemsCraftedType;
2222
monstersKilled: formatedMonsterDataType[];
@@ -47,6 +47,13 @@ export type cropsShippedType = {
4747
poly_crops: generalFormatedItemType[];
4848
};
4949

50+
export type fishCaughtType = {
51+
fishCaught: number;
52+
catchedFish: generalFormatedItemType[];
53+
total: number;
54+
achievements?: achievementType[];
55+
}
56+
5057
export type achievementType = {
5158
done: boolean,
5259
goal: number,

0 commit comments

Comments
 (0)