Skip to content

Commit

Permalink
IV: Add "Total strength" to box sort MenuItem
Browse files Browse the repository at this point in the history
fix #14
  • Loading branch information
nitoyon committed Jan 26, 2025
1 parent ccd5392 commit be964fa
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@
"sub skills": "Sub skills",
"unlocked only": "Unlocked only",
"total": "Total",
"total strength": "Total strength",
"skill count": "Skill count",

"select subskill at level xxx": "Select sub skill at <level/>",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@
"sub skills": "サブスキル",
"unlocked only": "解放済みのみ",
"total": "合計",
"total strength": "合計エナジー",
"skill count": "スキル回数",

"select subskill at level xxx": "<level/> のサブスキルを選択してください",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@
"sub skills": "서브 스킬",
"unlocked only": "오직 잠금 해제됨",
"total": "총계",
"total strength": "총 에너지",
"skill count": "스킬 수",

"select subskill at level xxx": "<level/>의 서브 스킬을 선택해주세요",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@
"sub skills": "副技能",
"unlocked only": "只包含已解锁",
"total": "合计",
"total strength": "总能量",
"skill count": "技能次数",

"select subskill at level xxx": "请选择 <level/> 的副技能",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@
"sub skills": "副技能",
"unlocked only": "只包含已開放",
"total": "合計",
"total strength": "總能量",
"skill count": "技能次數",

"select subskill at level xxx": "請選擇 <level/> 的副技能",
Expand Down
6 changes: 4 additions & 2 deletions src/ui/IvCalc/BoxSortConfigFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ const BoxSortConfigFooter = React.memo(({sortConfig, parameter, dispatch, onChan
return ret;
}, [t]);

if (sortConfig.sort !== "berry" &&
if (sortConfig.sort !== "total strength" &&
sortConfig.sort !== "berry" &&
sortConfig.sort !== "ingredient" &&
sortConfig.sort !== "skill count"
) {
Expand All @@ -97,7 +98,8 @@ const BoxSortConfigFooter = React.memo(({sortConfig, parameter, dispatch, onChan
<MenuItem value={100}>Lv. 100</MenuItem>
</SelectEx>
</span>
{sortConfig.sort === "berry" && <span className="field">
{(sortConfig.sort === "berry" || sortConfig.sort === "total strength") &&
<span className="field">
<SelectEx value={parameter.fieldIndex} onChange={onFieldChange}
sx={{padding: '0 .2rem', fontSize: '0.8rem'}}>
{fieldMenus}
Expand Down
17 changes: 14 additions & 3 deletions src/ui/IvCalc/BoxView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const BoxView = React.memo(({items, selectedId, parameter, dispatch}: {
descending: sortConfig.descending,
}), [filterConfig, sortConfig]);
const footerSortTypes = React.useMemo(() =>
["level", "name", "pokedexno", "rp", "berry", "ingredient", "skill count"], []);
["level", "name", "pokedexno", "rp", "total strength", "berry", "ingredient", "skill count"], []);

return <>
<div style={{
Expand Down Expand Up @@ -182,6 +182,17 @@ function sortPokemonItems(filtered: PokemonBoxItem[],
b.iv.level !== a.iv.level ? b.iv.level - a.iv.level :
b.id - a.id), ''];
}
else if (sort === "total strength") {
const cache: {[id: string]: number} = {};
filtered.forEach((item) => {
const strength = new PokemonStrength(item.iv, parameter);
cache[item.id] = strength.calculate().totalStrength;
});
return [filtered.sort((a, b) =>
cache[b.id] !== cache[a.id] ? cache[b.id] - cache[a.id] :
b.iv.pokemon.id !== a.iv.pokemon.id ? b.iv.pokemon.id - a.iv.pokemon.id :
b.id - a.id), ''];
}
else if (sort === "berry") {
const cache: {[id: string]: number} = {};
filtered.forEach((item) => {
Expand Down Expand Up @@ -243,7 +254,7 @@ function sortPokemonItems(filtered: PokemonBoxItem[],
}

/** Represents the field by which the box are sorted. */
export type BoxSortType = "level"|"name"|"pokedexno"|"rp"|"berry"|"ingredient"|"skill count";
export type BoxSortType = "level"|"name"|"pokedexno"|"rp"|"total strength"|"berry"|"ingredient"|"skill count";

/**
* Pokemon box sort configuration.
Expand Down Expand Up @@ -400,7 +411,7 @@ function loadBoxSortConfig(): BoxSortConfig {
return ret;
}
if (typeof(json.sort) === "string" &&
["level", "name", "pokedexno", "rp", "berry", "ingredient", "skill count"].includes(json.sort)) {
["level", "name", "pokedexno", "rp", "berry", "total strength", "ingredient", "skill count"].includes(json.sort)) {
ret.sort = json.sort;
}
if (typeof(json.ingredient) === "string" &&
Expand Down

0 comments on commit be964fa

Please sign in to comment.