Skip to content

Commit 0a03e50

Browse files
authored
Merge pull request #6 from TheCodeRaccoons/te-taking-project
Te taking project
2 parents 21d379d + 933e7e3 commit 0a03e50

12 files changed

Lines changed: 232 additions & 128 deletions

File tree

src/Components/AchieveTabs/Collection.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
import React, { useState, useEffect } from 'react'
2+
import type { museumCollectionType } from 'types/displayDataTypes';
23

34
interface CollectionProps {
4-
museumCollection: {
5-
artifacts: Array<{
6-
found: boolean;
7-
inMuseum: boolean;
8-
image: string;
9-
name: string;
10-
}>;
11-
minerals: Array<{
12-
found: boolean;
13-
inMuseum: boolean;
14-
image: string;
15-
name: string;
16-
}>;
17-
};
5+
museumCollection: museumCollectionType;
186
}
197

20-
const Collection: React.FC<CollectionProps> = ({ museumCollection }) => {
8+
const Collection = ({ museumCollection }: CollectionProps) => {
219
const [totalFound, setTotalFound] = useState(0);
2210
const [totalDelivered, setTotalDelivered] = useState(0);
2311
const [total, setTotal] = useState(0);

src/Components/AchieveTabs/Cooking.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@ import { useState, useEffect } from 'react'
22
import type { generalFormatedItemType } from 'types/savefile';
33

44
interface dishesCookedType {
5-
recipesCooked: generalFormatedItemType[];
5+
cookedItems: generalFormatedItemType[];
66
}
77

8-
const Food = ( recipesCooked : dishesCookedType) => {
8+
const Food = ( {cookedItems} : dishesCookedType) => {
99
const [dishesCooked, setDishesCooked] = useState(0);
10-
if(!recipesCooked) return <div>No cooking data available.</div>;
10+
if(!cookedItems) return <div>No cooking data available.</div>;
1111

12-
const canMap = (recipesCooked.recipesCooked && recipesCooked.recipesCooked.length > 0);
12+
const canMap = (cookedItems && cookedItems.length > 0);
13+
console.log("Cooking data:", cookedItems);
1314
useEffect(() => {
14-
const cookedCount = canMap ? recipesCooked.recipesCooked.map((num) => (num.times !== undefined && num.times > 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0;
15+
const cookedCount = canMap ? cookedItems.map((num) => (num.times !== undefined && num.times > 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0;
1516
setDishesCooked(cookedCount);
16-
}, [recipesCooked]);
17-
const cookedCount = canMap ? recipesCooked.recipesCooked.map((num) => (num.times !== undefined && num.times > 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0;
18-
const knownCount = canMap ? recipesCooked.recipesCooked.map((num) => (num.times !== undefined && num.times >= 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0;
17+
}, [cookedItems]);
18+
const cookedCount = canMap ? cookedItems.map((num) => (num.times !== undefined && num.times > 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0;
19+
const knownCount = canMap ? cookedItems.map((num) => (num.times !== undefined && num.times >= 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0;
1920

2021
return (
2122
<div className="progress-container">
22-
<span className="a-title"><h1>You have cooked {cookedCount}, knowing {knownCount} out of {recipesCooked.recipesCooked.length} recipes</h1></span>
23+
<span className="a-title"><h1>You have cooked {cookedCount}, knowing {knownCount} out of {cookedItems.length} recipes</h1></span>
2324
<br />
2425
<h2>Cooking Achievements</h2>
2526
<ul className="a-List">
@@ -29,7 +30,7 @@ const Food = ( recipesCooked : dishesCookedType) => {
2930
</ul>
3031
<br />
3132
{ canMap ?
32-
recipesCooked.recipesCooked.map((d, i) => <a href={`https://stardewvalleywiki.com/${d.link}`} target="blank" key={i}><img src={`https://stardew-tracker.s3.amazonaws.com/Cooking/${d.image}.png`} alt={d.name} className={ (d.times !== undefined) ? ((d.times > 0) ? "done" : "known" ): "" } title={(d.times !== undefined) ? (d.times > 0) ? `Cooked ${d.name} ${d.times} times` : `You haven't cooked ${d.name}` : `You don't know how to cook ${d.name}`} ></img></a>)
33+
cookedItems.map((d, i) => <a href={`https://stardewvalleywiki.com/${d.link}`} target="blank" key={i}><img src={`https://stardew-tracker.s3.amazonaws.com/Cooking/${d.image}.png`} alt={d.name} className={ (d.times !== undefined) ? ((d.times > 0) ? "done" : "known" ): "" } title={(d.times !== undefined) ? (d.times > 0) ? `Cooked ${d.name} ${d.times} times` : `You haven't cooked ${d.name}` : `You don't know how to cook ${d.name}`} ></img></a>)
3334
: null
3435
}
3536
</div>

src/Components/AchieveTabs/Fish.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import React, { useState, useEffect } from 'react'
2-
3-
interface FishItem {
4-
fished: boolean;
5-
image: string;
6-
name: string;
7-
}
2+
import type { generalFormatedItemType } from 'types/displayDataTypes';
83

94
interface FishProps {
10-
fishCaught: FishItem[];
5+
fishCaught: generalFormatedItemType[];
116
}
127

13-
const Fish: React.FC<FishProps> = ({ fishCaught }) => {
8+
const Fish = ({ fishCaught }: FishProps) => {
149
const [totalFished, setTotalFished] = useState(0);
1510

16-
const getCraftedItems = (items: FishItem[]) => {
11+
const getCraftedItems = (items: generalFormatedItemType[]) => {
1712
return items.map((num) => (num.fished) ? 1 : 0).reduce((n: number, next: number) => next + n, 0);
1813
};
1914

src/Components/Achievements/Achievements.tsx

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,28 @@ import Shipping from '../AchieveTabs/Shipping'
1212
import Earnings from '../AchieveTabs/moneyEarned'
1313
import Collection from '../AchieveTabs/Collection'
1414
import Quests from '../AchieveTabs/quests'
15+
import type { fullPlayerDataType } from 'types/displayDataTypes.js';
1516

16-
const Achievements = (props) => {
17+
const Achievements = ({
18+
playerName,
19+
farmName,
20+
experience,
21+
moneyEarned,
22+
professions,
23+
shippedItems,
24+
cropsShipped,
25+
mineralsFound,
26+
cookedItems,
27+
museumCollection,
28+
availableSpecialRequests,
29+
fishCaught,
30+
friendship,
31+
itemsCrafted,
32+
monstersKilled,
33+
questsDone,
34+
specialRequests,
35+
tailoredItems,
36+
}: fullPlayerDataType ) => {
1737
const TabImg = [
1838
{img: TabCook, alt: "Cooking"},
1939
{img: TabCraft, alt: "Crafting"},
@@ -37,59 +57,59 @@ const Achievements = (props) => {
3757
</TabList>
3858
<TabPanel>
3959
<section className="achievement-container">
40-
<Food recipesCooked={props.recipesCooked}></Food>
60+
<Food cookedItems={cookedItems}></Food>
4161
</section>
4262
</TabPanel>
4363
<TabPanel>
4464
<section className="achievement-container">
45-
<Crafting itemsCrafted={props.itemsCrafted}></Crafting>
65+
<Crafting itemsCrafted={itemsCrafted}></Crafting>
4666
</section>
4767
</TabPanel>
4868
<TabPanel>
4969
<section className="achievement-container">
50-
<Crops cropsShipped={props.cropsShipped} />
70+
<Crops cropsShipped={cropsShipped} />
5171
</section>
5272
</TabPanel>
5373
<TabPanel>
5474
<section className="achievement-container">
55-
<Fish fishCaught={props.fishCaught} />
75+
<Fish fishCaught={fishCaught} />
5676
</section>
5777
</TabPanel>
5878
<TabPanel>
5979
<section className="achievement-container">
60-
<Friendship friendship={props.friendship}/>
80+
<Friendship friendship={friendship}/>
6181
</section>
6282
</TabPanel>
6383
<TabPanel>
6484
<section className="achievement-container">
65-
<Monsters monstersKilled={props.monstersKilled}/>
85+
<Monsters monstersKilled={monstersKilled}/>
6686
</section>
6787
</TabPanel>
6888
<TabPanel>
6989
<section className="achievement-container">
70-
<Shipping shippedItems={props.shippedItems}/>
90+
<Shipping shippedItems={shippedItems}/>
7191
</section>
7292
</TabPanel>
7393
<TabPanel>
7494
<section className="achievement-container">
75-
<Earnings moneyEarned={props.moneyEarned}/>
95+
<Earnings moneyEarned={moneyEarned}/>
7696
</section>
7797
</TabPanel>
7898
<TabPanel>
7999
<section className="achievement-container">
80-
<Collection museumCollection={props.museumCollection} />
100+
<Collection museumCollection={museumCollection} />
81101
</section>
82102
</TabPanel>
83-
<TabPanel>
103+
{/* <TabPanel>
84104
<section className="achievement-container">
85-
<Quests questsDone={props.questsDone} specialReq={props.specialReq} pendingSpecialReq={props.pendingSpecialReq} />
105+
<Quests questsDone={questsDone} specialReq={specialRequests} pendingSpecialReq={pendingSpecialReq} />
86106
</section>
87107
</TabPanel>
88108
<TabPanel>
89109
<section className="achievement-container">
90-
<Quests questsDone={props.questsDone} specialReq={props.specialReq} pendingSpecialReq={props.pendingSpecialReq} />
110+
<Quests questsDone={questsDone} specialReq={specialRequests} pendingSpecialReq={pendingSpecialReq} />
91111
</section>
92-
</TabPanel>
112+
</TabPanel> */}
93113
</Tabs>
94114
</div>
95115
);

src/Components/Main/Main.tsx

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,28 @@ import Window4 from '@media/Windows/Window4.png'
88
import Loader from '@media/loader.gif'
99
import AdComponent from '../adsense/adComponent.js'
1010
import { useState } from 'react';
11+
import type { formattedSaveFileType, fullPlayerDataType } from 'types/displayDataTypes.js';
1112
//TODO: enable ads
1213
//import AdSense from 'react-adsense';
1314

1415
const Main = () => {
1516
const [hasData, setHasData] = useState(false);
1617
const [showLoader, setShowLoader] = useState(false);
17-
const [playerData, setPlayerData] = useState(null);
18-
const [farmhands, setFarmhands] = useState([])
18+
const [playerData, setPlayerData] = useState<fullPlayerDataType>({} as fullPlayerDataType);
19+
const [farmhands, setFarmhands] = useState<fullPlayerDataType[]>([]);
20+
const [globalFarmName, setFarmName] = useState("My Farm");
1921

20-
const UpdatePlayerData = (_playerData) => {
22+
const UpdatePlayerData = ({farmName, playerData, farmhandData}: formattedSaveFileType) => {
23+
console.log("Player data received", playerData, farmhandData);
24+
if(!playerData) {
25+
console.error("No player data received in Main component");
26+
return;
27+
}
2128
setHasData(true);
2229
setShowLoader(false);
23-
setFarmhands(_playerData.farmhandData);
24-
setPlayerData(_playerData.playerData[0]);
25-
}
26-
27-
const UpdateGamePrefix = (pref) => {
28-
console.log("Using prefix: " + pref)
29-
}
30-
31-
const GetCollection = (collection) => {
32-
let museumPieces = []
33-
if(collection.museumPieces.item !== undefined){
34-
museumPieces = [...collection.museumPieces.item]
35-
}
36-
return (museumPieces.length > 0) ? museumPieces : []
30+
setFarmName(farmName ? playerData.farmName : "My Farm");
31+
setFarmhands(farmhandData);
32+
setPlayerData(playerData);
3733
}
3834

3935
return (
@@ -75,13 +71,8 @@ const Main = () => {
7571
<div className="main-container">
7672
{
7773
hasData ?
78-
<Stats playerData={playerData} farmhands={farmhands} /> :
79-
<Viewer
80-
UpdatePlayerData={UpdatePlayerData}
81-
UpdateGamePrefix={UpdateGamePrefix}
82-
GetCollection={GetCollection}
83-
ShowLoader={setShowLoader}
84-
/>
74+
<Stats farmName={globalFarmName} playerData={playerData} farmhandData={farmhands} /> :
75+
<Viewer UpdatePlayerData={UpdatePlayerData} />
8576
}
8677
</div>
8778
<div className="adds">

src/Components/Skills/Skills.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import { useState } from 'react'
22
import SkillContainer from './SkillContainer/SkillContainer'
33
import {Farming, Mining, Foraging, Fishing, Combat} from '@media/Skills'
4+
import type { experienceType } from 'types/displayDataTypes'
45

5-
const Skills = (props) => {
6-
let [skills, setSkills] = useState(props.xp)
7-
let [skillImg, setSkillImg] = useState([Farming, Fishing, Foraging, Mining, Combat])
6+
interface SkillsProps {
7+
experience: experienceType[];
8+
}
89

10+
const Skills = ({ experience }: SkillsProps) => {
11+
const skillImg =[Farming, Fishing, Foraging, Mining, Combat];
12+
console.log("Skills data:", experience);
913
return (
1014
<section className="stats-container">
1115
<div className="skill-info">
12-
{skills.map((item, i: number) => (i === 5) ? "" :
16+
{experience.map((item, i: number) => (i === 5) ? "" :
1317
<SkillContainer
1418
key={i}
15-
index={i}
16-
skillImg={skillImg[i]}
19+
skillImg={skillImg[i] || ""}
1720
skillName={item.skill}
1821
xp={item.xp}
1922
levelInfo={item.levelInfo}

src/Components/Utility/Utility.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import type {
2929
questType,
3030
specialOrderType
3131
} from 'types/savefile';
32+
import type { fullPlayerDataType, museumCollectionType } from 'types/displayDataTypes';
3233

3334
//Gets the info from the farm hands as an array of the same type
3435
const GetFarmHands = (locations: gameLocationType[]): playerType[] => {
@@ -65,13 +66,16 @@ type getParsedUserDataType = Omit<getDetailedInfoType, 'playerData'> & {
6566

6667
//Calls the parser and creates an array of players depending on wether it is a single player or multiple
6768
const GetDetailedInfo = ({playerData , collectionStatus, specialRequests, availableSpecialRequests}: getDetailedInfoType) =>{
68-
let fullPlayerData: any = []
69+
let fullPlayerData: fullPlayerDataType[] = []
6970
if(Array.isArray(playerData)){
7071
playerData.forEach(p => {
71-
let playerFull = {
72+
let playerFull: fullPlayerDataType
73+
= {
7274
//...p,
7375
...parseData({playerData: p, collectionStatus, specialRequests, availableSpecialRequests})
7476
}
77+
78+
if(playerFull !== null)
7579
fullPlayerData.push(playerFull)
7680
})
7781
}
@@ -80,12 +84,11 @@ const GetDetailedInfo = ({playerData , collectionStatus, specialRequests, availa
8084
}
8185

8286
//Creates an object per player with the cleanup playerData.from the file
83-
const parseData = ({playerData, collectionStatus, specialRequests, availableSpecialRequests}: getParsedUserDataType) => {
84-
if(!playerData) return null;
87+
const parseData = ({playerData, collectionStatus, specialRequests, availableSpecialRequests}: getParsedUserDataType) : fullPlayerDataType => {
8588
//Not finished
8689
console.log("Parsing data for:", playerData)
87-
let fullPlayerData = {
88-
playerName: playerData.name,
90+
let fullPlayerData : fullPlayerDataType = {
91+
playerName: playerData.name || "Unknown",
8992
farmName: playerData.farmName, //TODO: Remove and make global if even needed
9093
experience: GetXpInfo(playerData.experiencePoints.int), //DONE
9194
moneyEarned: playerData.totalMoneyEarned || 0, //DONE
@@ -123,7 +126,7 @@ const GetXpInfo = (xp: number[]): experienceType[] => {
123126
levelInfo: Levels.find((level) => level.val >= _skill) || { id: 10, val: 15000 }
124127
})
125128
}
126-
})
129+
})
127130
return skillLevelData
128131
}
129132
/* End of XP Data */
@@ -355,7 +358,7 @@ const GetMonsterQuests = (allMonsters: itemsType[], slimesKilled: number): forma
355358
})
356359
return(mData)
357360
}
358-
const GetMCollection = (archeology: itemsType[], geology: itemsType[], currentCollection: itemsType[]) =>{
361+
const GetMCollection = (archeology: itemsType[], geology: itemsType[], currentCollection: itemsType[]) : museumCollectionType =>{
359362

360363
if(currentCollection === undefined || currentCollection.length === 0) return {artifacts: [], minerals: []};
361364

src/Components/Utility/monsterCategorie.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,6 @@
9191
"monsters": [
9292
"Serpent"
9393
]
94-
}]
94+
}
95+
]
9596
}

src/Components/Viewer/Viewer.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ import useLoadSaveFile from '@hooks/useLoadSaveFile';
44

55
interface ViewerProps {
66
UpdatePlayerData: (playerData: any) => void;
7-
UpdateGamePrefix?: (prefix: string) => void;
8-
GetCollection?: (collection: any) => any[];
9-
ShowLoader?: (show: boolean) => void;
107
}
118

12-
const Viewer = ({ UpdatePlayerData, UpdateGamePrefix, GetCollection, ShowLoader }: ViewerProps) => {
9+
const Viewer = ({ UpdatePlayerData }: ViewerProps) => {
1310
const inputRef = useRef<HTMLInputElement>(null);
1411
const { playerData, fileData, isLoading, error, selectFile } = useLoadSaveFile();
1512

0 commit comments

Comments
 (0)