Skip to content

Commit cad3c85

Browse files
committed
Refactor utility functions for professions and shipping
Moved and reorganized GetXpInfo, GetProfessionData, GetProfession, and GetShippedItems functions for better code structure and clarity. Updated comments and improved separation of concerns in Utility.tsx.
1 parent 99a3186 commit cad3c85

1 file changed

Lines changed: 94 additions & 88 deletions

File tree

src/Components/Utility/Utility.tsx

Lines changed: 94 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const parseData = ({playerData, collectionStatus, specialRequests, availableSpec
9292
moneyEarned: playerData.totalMoneyEarned || 0, //DONE
9393
professions: GetProfessionData(playerData.professions.int) , //DONE?
9494
shippedItems: GetShippedItems(playerData.basicShipped) || [],//DONE
95-
cropsShipped: GetCropsAchievements(playerData.basicShipped?.item),//DONE
95+
cropsShipped: GetCropsAchievements(playerData.basicShipped?.item),//Refactored DONE
9696
mineralsFound: GetArrayData(playerData.mineralsFound?.item) || [], //DONE
9797
cookedItems: GetCookingData(playerData.recipesCooked, playerData.cookingRecipes.item) || [], //DONE
9898
fishCaught: GetFishes(playerData.fishCaught.item) || [],
@@ -111,6 +111,97 @@ const parseData = ({playerData, collectionStatus, specialRequests, availableSpec
111111
return fullPlayerData;
112112
}
113113

114+
/* XP Data */
115+
const GetXpInfo = (xp: number[]): experienceType[] => {
116+
const SKILLS = ["Farming", "Fishing", "Foraging", "Mining", "Combat"]
117+
118+
let skillLevelData: experienceType[] = []
119+
xp.forEach((_skill, id) => {
120+
if (SKILLS[id] !== undefined){
121+
skillLevelData.push({
122+
skill: SKILLS[id] || "Unknown",
123+
xp: _skill,
124+
levelInfo: Levels.find((level) => level.val >= _skill) || { id: 10, val: 15000 }
125+
})
126+
}
127+
})
128+
return skillLevelData
129+
}
130+
/* End of XP Data */
131+
/* Profession Data */
132+
133+
const GetProfessionData = (professions: number[]): professionsType[] =>{
134+
let data: professionsType[] = [];
135+
if(Array.isArray(professions)){
136+
professions.forEach(item => {
137+
let d = ProfNames.professions.find( p => p.id === item)
138+
if (d !== undefined) {
139+
data = [...data, d]
140+
}
141+
});
142+
}
143+
return data;
144+
}
145+
146+
//TODO: generate json file for professions and implement in the profession tab
147+
const GetProfession = (id: number): string => {
148+
const professionMap: { [key: number]: string } = {
149+
0: "Rancher",
150+
1: "Tiller",
151+
2: "Coopmaster",
152+
3: "Shepherd",
153+
4: "Artisan",
154+
5: "Agriculturist",
155+
6: "Fisher",
156+
7: "Trapper",
157+
8: "Angler",
158+
9: "Pirate",
159+
10: "Mariner",
160+
11: "Luremaster",
161+
12: "Forester",
162+
13: "Gatherer",
163+
14: "Lumberjack",
164+
15: "Tapper",
165+
16: "Botanist",
166+
17: "Tracker",
167+
18: "Miner",
168+
19: "Geologist",
169+
20: "Blacksmith",
170+
21: "Prospector",
171+
22: "Excavator",
172+
23: "Gemologist",
173+
24: "Fighter",
174+
25: "Scout",
175+
26: "Brute",
176+
27: "Defender",
177+
28: "Acrobat",
178+
29: "Desperado"
179+
};
180+
181+
return professionMap[id] || "";
182+
}
183+
/* End of Profession Data */
184+
185+
/* Shipping Related Achievements */
186+
const GetShippedItems = (allShipped: itemType) :generalFormatedItemType[] => {
187+
let data: generalFormatedItemType[] = []
188+
if(!allShipped?.item || allShipped?.item.length === 0) return data;
189+
//Parses the shipped info
190+
let shipped = allShipped.item.map( val => {return {id: val.key.int, times: val.value.int}})
191+
192+
ShipItems.shipping.forEach(item => {
193+
let d = {
194+
name: item.item_name,
195+
image: GetImages(item.item_name),
196+
id: item.item_id,
197+
shipped: (shipped && shipped.length > 0 ? shipped.find(i => i.id === item.item_id )?.times || 0 : 0)
198+
}
199+
data.push(d);
200+
})
201+
return data;
202+
}
203+
/* End of Shipping Related Achievements */
204+
114205
const GetCookingData = (cooked: itemType, known: itemsType[]): generalFormatedItemType[] =>{
115206
let data: generalFormatedItemType[] = [];
116207
Dishes.Dishes.forEach(item => {
@@ -153,40 +244,6 @@ const GetCraftingRecipes = (recipes: itemsType[]): generalFormatedItemType[] =>
153244
return data
154245
}
155246

156-
const GetXpInfo = (xp: number[]): experienceType[] => {
157-
const SKILLS = ["Farming", "Fishing", "Foraging", "Mining", "Combat"]
158-
159-
let skillLevelData: experienceType[] = []
160-
xp.forEach((_skill, id) => {
161-
if (SKILLS[id] !== undefined){
162-
skillLevelData.push({
163-
skill: SKILLS[id] || "Unknown",
164-
xp: _skill,
165-
levelInfo: Levels.find((level) => level.val >= _skill) || { id: 10, val: 15000 }
166-
})
167-
}
168-
})
169-
return skillLevelData
170-
}
171-
172-
const GetShippedItems = (allShipped: itemType) :generalFormatedItemType[] => {
173-
let data: generalFormatedItemType[] = []
174-
if(!allShipped?.item || allShipped?.item.length === 0) return data;
175-
//Parses the shipped info
176-
let shipped = allShipped.item.map( val => {return {id: val.key.int, times: val.value.int}})
177-
178-
ShipItems.shipping.forEach(item => {
179-
let d = {
180-
name: item.item_name,
181-
image: GetImages(item.item_name),
182-
id: item.item_id,
183-
shipped: (shipped && shipped.length > 0 ? shipped.find(i => i.id === item.item_id )?.times || 0 : 0)
184-
}
185-
data.push(d);
186-
})
187-
return data;
188-
}
189-
190247
/* Crop Related Achievements */
191248
const GetCropsAchievements = (allShipped: itemsType[]) : cropsShippedType => {
192249
const poly_crops: generalFormatedItemType[] = []
@@ -254,6 +311,7 @@ const GetFishes = (allFished: itemsType[]) => {
254311

255312
return data
256313
}
314+
257315
const GetFriendshipData = (allFriends: friendshipDataType[]): formatedFriendshipDataType[] => {
258316
let data: formatedFriendshipDataType[] = []
259317
if(Array.isArray(allFriends)){
@@ -347,7 +405,7 @@ const ValidateKnown = (k:itemsType[], name: string) => {
347405
}
348406
}
349407

350-
408+
/* Utility methods*/
351409
const GetImages = (name: string): string => {
352410
const imageMap: { [key: string]: string } = {
353411
"Wild Seeds (Sp)": "Spring_Seeds",
@@ -367,58 +425,6 @@ const GetImages = (name: string): string => {
367425
return imageMap[name] || name.split(" ").join("_").replace(/['":]/g, "");
368426
}
369427

370-
const CleanTimes = (obj: itemsType) => {
371-
return (obj !== undefined ? obj.value.int : 0)
372-
}
373-
const GetProfessionData = (professions: number[]): professionsType[] =>{
374-
let data: professionsType[] = [];
375-
if(Array.isArray(professions)){
376-
professions.forEach(item => {
377-
let d = ProfNames.professions.find( p => p.id === item)
378-
if (d !== undefined) {
379-
data = [...data, d]
380-
}
381-
});
382-
}
383-
return data;
384-
}
385-
386-
const GetProfession = (id: number): string => {
387-
const professionMap: { [key: number]: string } = {
388-
0: "Rancher",
389-
1: "Tiller",
390-
2: "Coopmaster",
391-
3: "Shepherd",
392-
4: "Artisan",
393-
5: "Agriculturist",
394-
6: "Fisher",
395-
7: "Trapper",
396-
8: "Angler",
397-
9: "Pirate",
398-
10: "Mariner",
399-
11: "Luremaster",
400-
12: "Forester",
401-
13: "Gatherer",
402-
14: "Lumberjack",
403-
15: "Tapper",
404-
16: "Botanist",
405-
17: "Tracker",
406-
18: "Miner",
407-
19: "Geologist",
408-
20: "Blacksmith",
409-
21: "Prospector",
410-
22: "Excavator",
411-
23: "Gemologist",
412-
24: "Fighter",
413-
25: "Scout",
414-
26: "Brute",
415-
27: "Defender",
416-
28: "Acrobat",
417-
29: "Desperado"
418-
};
419-
420-
return professionMap[id] || "";
421-
}
422428
const NameTranslate = (name: string): string => {
423429
const nameMap: { [key: string]: string } = {
424430
"Cheese Cauliflower": "Cheese Cauli.",

0 commit comments

Comments
 (0)