Skip to content

Commit 952ac4a

Browse files
committed
Refactor skill XP info extraction logic
Moved SKILLS array inside GetXpInfo, switched to using push instead of spread for array updates, and improved variable naming for clarity. Also updated level lookup to use Levels directly.
1 parent c208ea5 commit 952ac4a

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

src/Components/Utility/Utility.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import type {
2929
specialOrderType
3030
} from 'types/savefile';
3131

32-
const SKILLS = ["Farming", "Fishing", "Foraging", "Mining", "Combat"]
33-
3432
/* Gather the XML and handling the file */
3533
//Gets the info from the farm hands as an array of the same type
3634
const GetFarmHands = (locations: gameLocationType[]): playerType[] => {
@@ -147,26 +145,28 @@ const GetCraftingRecipes = (recipes: itemsType[]): generalFormatedItemType[] =>
147145
image: GetImages(item),
148146
times: recipes.find(i => i.key.string === item)?.value.int || 0,
149147
}
150-
data = [...data, d]
148+
data.push(d)
151149
})
152150
}
153151
return data
154152
}
155153

156-
const GetXpInfo = (xp: number[]): experienceType[] => {
157-
let data: experienceType[] = []
158-
xp.forEach((item, id) => {
154+
const GetXpInfo = (xp: number[]): experienceType[] => {
155+
const SKILLS = ["Farming", "Fishing", "Foraging", "Mining", "Combat"]
156+
157+
let skillLevelData: experienceType[] = []
158+
xp.forEach((_skill, id) => {
159159
if (SKILLS[id] !== undefined){
160-
let d: experienceType = {
160+
skillLevelData.push({
161161
skill: SKILLS[id] || "Unknown",
162-
xp: item,
163-
levelInfo: Levels.Levels.find((level) => level.val >= item) || { id: 10, val: 15000 }
164-
}
165-
data = [...data, d]
162+
xp: _skill,
163+
levelInfo: Levels.find((level) => level.val >= _skill) || { id: 10, val: 15000 }
164+
})
166165
}
167166
})
168-
return data
169-
}
167+
return skillLevelData
168+
}
169+
170170
const GetShippedItems = (allShipped: itemType) :generalFormatedItemType[] => {
171171
let data: generalFormatedItemType[] = []
172172
if(!allShipped?.item || allShipped?.item.length === 0) return data;

0 commit comments

Comments
 (0)