-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add getInterpolateObject for relics and light cones #2563
Conversation
WalkthroughThe pull request introduces several enhancements across multiple files, focusing on improving the functionality of document displays and character statistics in a gaming context. Key modifications include the integration of a new Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
[sr-frontend] [Thu Dec 5 04:09:59 UTC 2024] - Deployed 67b37b5 to https://genshin-optimizer-prs.github.io/pr/2563/sr-frontend (Takes 3-5 minutes after this completes to be available) [sr-frontend] [Fri Dec 6 01:24:32 UTC 2024] - Deployed 5556390 to https://genshin-optimizer-prs.github.io/pr/2563/sr-frontend (Takes 3-5 minutes after this completes to be available) [Fri Dec 6 02:15:45 UTC 2024] - Deleted deployment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (7)
libs/sr/formula-ui/src/lightCone/sheets/PastSelfInMirror.tsx (2)
33-33
: Consider adding error handling for compute()The
compute()
call might return undefined values. Consider adding error handling or providing a default value.-calc.compute(own.lightCone.superimpose).val +calc.compute(own.lightCone.superimpose)?.val ?? 0
Line range hint
48-48
: Address TODO commentsThere are two TODO comments that need attention:
- Translation needed for "Duration"
- Conditional display logic for skill point recovery based on brEffect_ threshold
Would you like me to help implement these TODOs or create GitHub issues to track them?
Also applies to: 57-57
libs/sr/stats/src/char.ts (1)
53-68
: Improve error messages ingetCharStatBoostStat
.Include
bonusStats
in the error messages for better debugging context.For example:
- throw new Error(`No stat boost levels found for character ${ck}`) + throw new Error(`No stat boost levels found for character ${ck} and bonusStats ${bonusStats}`)libs/sr/formula-ui/src/char/sheets/RuanMei.tsx (4)
Line range hint
82-95
: Address TODO comments for translationsSeveral TODO comments indicate missing translations in the skill section:
- "skill active" text
- "Ally DMG Increase" title
- "Duration" translation
Would you like me to help create a tracking issue for these missing translations?
Line range hint
146-156
: Address critical TODO items in ultimate ability sectionSeveral TODO comments indicate missing functionality:
- Action delay percentage for Thanatoplum Rebloom trigger
- Damage multiplier increase from e6
- Zone duration increase from e6
These TODOs appear to be feature-related rather than just translations and might affect gameplay calculations.
Would you like me to help create detailed issues for tracking these missing features?
Line range hint
193-220
: Refactor temporary visualization codeThe comment "TODO: Move this to proper document" suggests this is temporary code. Consider:
- Moving these fields to their proper location
- Creating a separate component if needed
- Documenting the intended final structure
Would you like assistance in designing the proper structure for this visualization?
Line range hint
235-238
: Standardize translation keys for stats and effectsSeveral TODO comments indicate missing translations for stats and effects:
- "Ignore DEF" in Eidolon 1
- "talent" and "ult" in Eidolon 3
- "basic" and "skill" in Eidolon 5
Consider creating a standardized set of translation keys for these common game terms.
Would you like assistance in creating a standardized translation key structure?
Also applies to: 276-286, 333-344
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (8)
libs/pando/ui-sheet/src/components/DocumentDisplay.tsx
(2 hunks)libs/sr/formula-ui/src/char/sheets/RuanMei.tsx
(11 hunks)libs/sr/formula-ui/src/lightCone/sheets/PastSelfInMirror.tsx
(2 hunks)libs/sr/formula-ui/src/relic/cavern/WatchmakerMasterOfDreamMachinations.tsx
(2 hunks)libs/sr/stats/src/char.ts
(1 hunks)libs/sr/stats/src/index.ts
(1 hunks)libs/sr/stats/src/lightCone.ts
(1 hunks)libs/sr/stats/src/relic.ts
(1 hunks)
🔇 Additional comments (20)
libs/pando/ui-sheet/src/components/DocumentDisplay.tsx (2)
8-8
: LGTM: Clean import addition
The addition of TagContext import is well-placed and necessary for the new tag-based evaluation functionality.
69-71
: Verify tag handling in calculator context
The integration of TagContext looks good, but let's ensure proper handling of edge cases.
Let's verify the calculator's withTag implementation and tag handling:
Consider adding tag validation to handle undefined cases:
const calculator = useContext(CalcContext)
const tag = useContext(TagContext)
if (!calculator) return null
+ if (!tag) return null // Or provide a default behavior
return <div>{evalIfFunc(textDocument.text, calculator.withTag(tag))}</div>
libs/sr/formula-ui/src/lightCone/sheets/PastSelfInMirror.tsx (2)
5-9
: LGTM: Import changes align with PR objectives
The addition of own
and getLightConeInterpolateObject
imports supports the new interpolation functionality for light cones as described in the PR objectives.
28-35
: Verify interpolation accuracy for all light cones
As mentioned in the PR objectives, there's a known issue where the light cone interpolation references the current character's light cone for all descriptions. This implementation might need adjustment to handle different light cones correctly.
Let's verify the interpolation behavior:
libs/sr/stats/src/index.ts (1)
12-14
: LGTM!
The exports are correctly re-exported from the respective modules.
libs/sr/stats/src/lightCone.ts (2)
4-6
: LGTM!
The function getLightConeStat
correctly retrieves light cone stats.
14-23
: Ensure valid indices in getLightConeInterpolateObject
.
To prevent potential runtime errors, consider adding checks to ensure that superimpose
is within the valid range of the superimposeParams
array.
If superimpose
can be outside the bounds of superimposeParams
, you might want to add validation or default values.
libs/sr/stats/src/relic.ts (2)
4-6
: LGTM!
The function getRelicStat
correctly retrieves relic stats.
14-21
: Ensure valid indices in getRelicInterpolateObject
.
To prevent potential runtime errors, consider adding checks to ensure that setEffects[setEffectIndex]
exists before accessing it.
Ensure that numRequired
corresponds to valid indices in the setEffects
array.
libs/sr/formula-ui/src/relic/cavern/WatchmakerMasterOfDreamMachinations.tsx (3)
6-9
: LGTM!
The import statements correctly include the necessary functions.
28-28
: LGTM!
The getRelicInterpolateObject
function is correctly used to interpolate 2-Set effects.
47-47
: LGTM!
The getRelicInterpolateObject
function is correctly used to interpolate 4-Set effects.
libs/sr/stats/src/char.ts (1)
5-7
: LGTM!
The function getCharStat
correctly retrieves character stats.
libs/sr/formula-ui/src/char/sheets/RuanMei.tsx (7)
11-14
: LGTM! Import changes align with architecture refactoring
The change from getInterpolateObject
to getCharInterpolateObject
is consistent with the PR's objective to split interpolation functions for better organization.
41-44
: LGTM! Basic ability interpolation properly configured
The interpolation for basic ability description is correctly implemented with appropriate parameters (character key, ability type, and calculator value).
73-76
: LGTM! Skill ability interpolation properly configured
The interpolation for skill ability description is correctly implemented with appropriate parameters.
122-125
: LGTM! Ultimate ability interpolation properly configured
The interpolation for ultimate ability description is correctly implemented with appropriate parameters.
177-180
: LGTM! Talent ability interpolation properly configured
The interpolation for talent ability description is correctly implemented with appropriate parameters.
228-228
: LGTM! Eidolon interpolations consistently implemented
The interpolation changes are consistently applied across all six eidolons with the correct parameters (character key, 'eidolon', eidolon number).
Also applies to: 249-249, 269-269, 295-295, 324-324, 350-350
Line range hint 1-354
: Verify completeness of interpolation changes
Let's verify that all text interpolations have been updated to use the new getCharInterpolateObject
:
✅ Verification successful
Let me try another verification script with a different approach:
All interpolation calls are properly using the new getCharInterpolateObject
The verification shows:
- No instances of old
getInterpolateObject
found - All calculator-based text interpolations (
text: (calculator) =>
) usegetCharInterpolateObject
- All description texts (
ranks.*.desc
) usegetCharInterpolateObject
- Other
chg()
calls are for simple string lookups that don't require interpolation
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for any remaining usage of old interpolation function
# and verify all text interpolations use the new function
# Check for any remaining usage of old interpolation function
rg "getInterpolateObject(?!Char)" "libs/sr/formula-ui/src/char/sheets/RuanMei.tsx"
# Verify all chg calls with desc are using the new function
rg "chg\([^)]*desc" "libs/sr/formula-ui/src/char/sheets/RuanMei.tsx"
Length of output: 883
Script:
#!/bin/bash
# Search for all text interpolation patterns in the file
rg -A 1 "text: \(calculator\) =>" "libs/sr/formula-ui/src/char/sheets/RuanMei.tsx"
# Search for any remaining getInterpolateObject using pcre2
rg --pcre2 "getInterpolateObject(?!Char)" "libs/sr/formula-ui/src/char/sheets/RuanMei.tsx"
# Search for all chg function calls
rg "chg\(" "libs/sr/formula-ui/src/char/sheets/RuanMei.tsx"
Length of output: 1565
const sheet: UISheetElement = { | ||
title: chg('passive.name'), | ||
img: icon, | ||
documents: [ | ||
{ | ||
type: 'text', | ||
text: chg('passive.description'), // TODO: getInterpolateObject for lightcone | ||
text: (calc) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use SuperImposeWrapper
from https://github.com/frzyc/genshin-optimizer/blob/master/libs/sr/formula-ui/src/lightCone/util.tsx#L6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (2)
libs/sr/formula-ui/src/lightCone/sheets/PastSelfInMirror.tsx (1)
Line range hint
62-62
: Address TODO comments in the code.There are two TODO items that need attention:
- Translation needed for "Duration"
- Conditional logic for showing "Skill Point recovered" based on
brEffect_
thresholdWould you like me to help implement these TODOs or create GitHub issues to track them?
Also applies to: 71-71
libs/sr/stats/src/char.ts (1)
76-77
: Handle cases where stat boost data may be undefined ingetCharStatBoost
.The function assumes that
skillTree['statBoost' + bonusStats]
exists. If it does not,undefined
is returned, which may lead to errors in calling functions.Consider adding a check or default value to handle undefined cases.
Apply this diff to add validation:
export function getCharStatBoost( ck: CharacterGenderedKey, bonusStats: StatBoostKey | `${StatBoostKey}` ) { const { skillTree } = getCharStat(ck) + const statBoost = skillTree[`statBoost${bonusStats}`] + if (!statBoost) { + throw new Error(`No stat boost found for character ${ck} with bonusStat ${bonusStats}`) + } - return skillTree[`statBoost${bonusStats}`] + return statBoost }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
libs/sr/formula-ui/src/lightCone/sheets/PastSelfInMirror.tsx
(2 hunks)libs/sr/stats/src/char.ts
(1 hunks)
🔇 Additional comments (5)
libs/sr/formula-ui/src/lightCone/sheets/PastSelfInMirror.tsx (3)
6-9
: LGTM! Import changes align with PR objectives.
The addition of getLightConeInterpolateObject
import supports the new interpolation functionality for light cones.
28-37
: Correctly implemented SuperImposeWrapper as suggested.
The implementation follows the recommended approach using SuperImposeWrapper
from the light cone utilities.
31-34
: Verify interpolation accuracy for different light cones.
As mentioned in the PR objectives, there's a known issue where light cone interpolation references the superimpose of the current character's light cone for all descriptions. This could lead to inaccurate descriptions.
Let's verify the interpolation behavior:
libs/sr/stats/src/char.ts (2)
8-10
: Function getCharStat
looks good.
The implementation correctly retrieves character statistics.
20-40
: Add validation in getCharInterpolateObject
to prevent runtime errors.
Consider adding checks to ensure that the accessed properties exist before using them:
- For
'eidolon'
, verify thatallStats.char[ck].rankMap[skLevel as Rank]
exists before accessing.params
. - For other
skType
s, verify thatallStats.char[ck].skillTree[skType].skillParamList[skIndex]
exists before accessing it.
This will prevent potential runtime errors when invalid skLevel
or skIndex
values are passed.
export function getCharStatBoostStatKey( | ||
ck: CharacterGenderedKey, | ||
bonusStats: StatBoostKey | `${StatBoostKey}` | ||
) { | ||
return getCharStatBoostStat(ck, bonusStats).statKey | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Ensure getCharStatBoostStatKey
handles undefined boost data gracefully.
If getCharStatBoostStat
returns undefined
, accessing .statKey
will cause a runtime error.
Consider adding a check to handle cases where getCharStatBoostStat
may be undefined
.
Apply this diff to add validation:
export function getCharStatBoostStatKey(
ck: CharacterGenderedKey,
bonusStats: StatBoostKey | `${StatBoostKey}`
) {
+ const statBoost = getCharStatBoostStat(ck, bonusStats)
+ if (!statBoost) {
+ throw new Error(`No stat boost found for character ${ck}`)
+ }
- return getCharStatBoostStat(ck, bonusStats).statKey
+ return statBoost.statKey
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export function getCharStatBoostStatKey( | |
ck: CharacterGenderedKey, | |
bonusStats: StatBoostKey | `${StatBoostKey}` | |
) { | |
return getCharStatBoostStat(ck, bonusStats).statKey | |
} | |
export function getCharStatBoostStatKey( | |
ck: CharacterGenderedKey, | |
bonusStats: StatBoostKey | `${StatBoostKey}` | |
) { | |
const statBoost = getCharStatBoostStat(ck, bonusStats) | |
if (!statBoost) { | |
throw new Error(`No stat boost found for character ${ck}`) | |
} | |
return statBoost.statKey | |
} |
export function getCharStatBoostStatValue( | ||
ck: CharacterGenderedKey, | ||
bonusStats: StatBoostKey | `${StatBoostKey}` | ||
) { | ||
return getCharStatBoostStat(ck, bonusStats).value | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Ensure getCharStatBoostStatValue
handles undefined boost data gracefully.
Similar to the previous function, if getCharStatBoostStat
returns undefined
, accessing .value
will cause a runtime error.
Consider adding a check to handle cases where getCharStatBoostStat
may be undefined
.
Apply this diff to add validation:
export function getCharStatBoostStatValue(
ck: CharacterGenderedKey,
bonusStats: StatBoostKey | `${StatBoostKey}`
) {
+ const statBoost = getCharStatBoostStat(ck, bonusStats)
+ if (!statBoost) {
+ throw new Error(`No stat boost found for character ${ck}`)
+ }
- return getCharStatBoostStat(ck, bonusStats).value
+ return statBoost.value
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export function getCharStatBoostStatValue( | |
ck: CharacterGenderedKey, | |
bonusStats: StatBoostKey | `${StatBoostKey}` | |
) { | |
return getCharStatBoostStat(ck, bonusStats).value | |
} | |
export function getCharStatBoostStatValue( | |
ck: CharacterGenderedKey, | |
bonusStats: StatBoostKey | `${StatBoostKey}` | |
) { | |
const statBoost = getCharStatBoostStat(ck, bonusStats) | |
if (!statBoost) { | |
throw new Error(`No stat boost found for character ${ck}`) | |
} | |
return statBoost.value | |
} |
export function getCharStatBoostStat( | ||
ck: CharacterGenderedKey, | ||
bonusStats: StatBoostKey | `${StatBoostKey}` | ||
) { | ||
const boost = getCharStatBoost(ck, bonusStats) | ||
const levels = boost.levels | ||
if (!levels?.length) { | ||
throw new Error(`No stat boost levels found for character ${ck}`) | ||
} | ||
const entries = Object.entries(levels[0].stats ?? {}) | ||
if (!entries.length) { | ||
throw new Error(`No stats found in stat boost for character ${ck}`) | ||
} | ||
const [statKey, value] = entries[0] | ||
return { statKey, value } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add null checks in getCharStatBoostStat
to prevent runtime errors.
The function assumes that boost
and levels[0]
are defined. If getCharStatBoost
returns undefined
, or if levels
is empty, accessing properties will cause runtime errors.
Consider adding checks to ensure boost
, levels
, and entries
exist before accessing them.
Apply this diff to add validation:
export function getCharStatBoostStat(
ck: CharacterGenderedKey,
bonusStats: StatBoostKey | `${StatBoostKey}`
) {
const boost = getCharStatBoost(ck, bonusStats)
+ if (!boost) {
+ throw new Error(`No stat boost found for character ${ck}`)
+ }
const levels = boost.levels
if (!levels?.length) {
throw new Error(`No stat boost levels found for character ${ck}`)
}
const entries = Object.entries(levels[0].stats ?? {})
if (!entries.length) {
throw new Error(`No stats found in stat boost for character ${ck}`)
}
const [statKey, value] = entries[0]
return { statKey, value }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export function getCharStatBoostStat( | |
ck: CharacterGenderedKey, | |
bonusStats: StatBoostKey | `${StatBoostKey}` | |
) { | |
const boost = getCharStatBoost(ck, bonusStats) | |
const levels = boost.levels | |
if (!levels?.length) { | |
throw new Error(`No stat boost levels found for character ${ck}`) | |
} | |
const entries = Object.entries(levels[0].stats ?? {}) | |
if (!entries.length) { | |
throw new Error(`No stats found in stat boost for character ${ck}`) | |
} | |
const [statKey, value] = entries[0] | |
return { statKey, value } | |
} | |
export function getCharStatBoostStat( | |
ck: CharacterGenderedKey, | |
bonusStats: StatBoostKey | `${StatBoostKey}` | |
) { | |
const boost = getCharStatBoost(ck, bonusStats) | |
if (!boost) { | |
throw new Error(`No stat boost found for character ${ck}`) | |
} | |
const levels = boost.levels | |
if (!levels?.length) { | |
throw new Error(`No stat boost levels found for character ${ck}`) | |
} | |
const entries = Object.entries(levels[0].stats ?? {}) | |
if (!entries.length) { | |
throw new Error(`No stats found in stat boost for character ${ck}`) | |
} | |
const [statKey, value] = entries[0] | |
return { statKey, value } | |
} |
Describe your changes
KNOWN ISSUE: Light cone interpolation looks at the current char's light cone superimpose for all light cone description interpolations, which isn't always correct.
Issue or discord link
Testing/validation
Checklist before requesting a review (leave this PR as draft if any part of this list is not done.)
yarn run mini-ci
locally to validate format and lint.Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Documentation
Refactor