Skip to content
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 non-stacking buff back to NO4 in a smarter way #2592

Merged
merged 6 commits into from
Jan 10, 2025
Merged

Conversation

nguyentvan7
Copy link
Collaborator

@nguyentvan7 nguyentvan7 commented Jan 6, 2025

Describe your changes

Update NO4 to use tally to create a non-stacking buff. Unlike other attempts, this still places the buff in the teamBuff namespace, so it renders as a teambuff in all ways that are expected.
Additionally, it has a proper source defined as one of the characters who is actually providing the buff. When there are multiple sources, the one with the smallest string (I assume sorted alphabetically?) is chosen instead.
It also renders a strikethrough on the buffs that were disabled to prevent stacking, for better feedback for the user

Issue or discord link

Testing/validation

Optimized many scenarios around buff being enabled, disabled, enabled many times, etc on different characters. No errors or crashes were seen.

Mavuika is the only one with the buff enabled, 20% atk is given to everyone as expected
image

Citlali activates the buff, now she is the primary source and Mavuika's is rendered with a strikethrough (to show it is disabled/not stacked). Everyone still receives only a 20% buff
image

Checklist before requesting a review (leave this PR as draft if any part of this list is not done.)

  • I have commented my code in hard-to understand areas.
  • I have made corresponding changes to README or wiki.
  • For front-end changes, I have updated the corresponding English translations.
  • I have run yarn run mini-ci locally to validate format and lint.
  • If I have added a new library or app, I have updated the deployment scripts to ignore changes as needed

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for non-stackable artifact set bonuses.
    • Enhanced text display with line-through styling for specific variants.
  • Improvements

    • Updated type definitions to support more flexible buff and variant handling.
    • Refined artifact set bonus calculation logic.
    • Enhanced data handling capabilities for team buff calculations.
  • Technical Updates

    • Expanded type safety for team buff and node data structures.
    • Improved error handling and logic clarity in data merging processes.

@nguyentvan7 nguyentvan7 requested a review from frzyc January 6, 2025 02:22
Copy link

coderabbitai bot commented Jan 6, 2025

Walkthrough

This pull request introduces modifications to the artifact set bonus calculation logic, specifically for the Noblesse Oblige set. The changes involve updating import statements, introducing new functions like nonStackBuff, and modifying how set bonuses are tracked and represented. The modifications span multiple files, including sheet utilities, UI components, and type definitions, with a focus on enhancing the flexibility of buff handling and display.

Changes

File Change Summary
libs/gi/sheets/src/Artifacts/NoblesseOblige/index.tsx - Updated imports with equalStr, greaterEqStr, nonStackBuff
- Replaced set4 with set4TallyWrite
- Added set4Inactive variable
- Modified data and sheet objects
libs/gi/sheets/src/SheetUtil.tsx - Added new nonStackBuff function
- Imported NonStackBuff type and additional utility functions
libs/gi/ui/src/components/FieldDisplay.tsx - Added conditional text decoration based on strikethrough property
libs/gi/ui/src/util/getCalcDisplay.tsx - Imported Typography
- Wrapped formula display with Typography component
libs/gi/wr/src/formula.ts - Added allNonstackBuffs constant
- Created NonStackBuff type
- Updated tally object mapping
libs/gi/wr/src/type.d.ts - Extended Info type with strikethrough property
- Updated DynamicNumInput interface to support more node types
libs/gi/uidata/src/uiData.ts - Added import for nonStacking
- Modified getReadNode function to handle nonStacking path
libs/gi/wr/src/api.ts - Added import for nonStacking
- Enhanced error handling and logic in inferInfoMut and mergeData functions

Possibly related PRs

  • Use Tag as db data instead of Read #2517: The changes in the main PR involve the introduction of the nonStackBuff function and modifications to how buffs are calculated, which relates to the updates in the OptConfigDataManager that now references generatedBuildListId instead of directly handling builds.
  • Fix Chasca/Mav bugs #2589: The modifications to the damage calculations for Chasca and Mavuika in this PR may relate to the changes in how buffs and damage are processed in the main PR, particularly in the context of how bonuses are calculated and applied.

Suggested labels

SRO

Suggested reviewers

  • frzyc

Poem

🐰 In the realm of artifacts so bright,
Noblesse Oblige takes a new flight.
Buffs dance with lines that strike through,
Code weaves magic, elegant and true.
A rabbit's tale of optimization's delight! 🎉

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

github-actions bot commented Jan 6, 2025

[frontend] [Mon Jan 6 02:25:29 UTC 2025] - Deployed 73af020 to https://genshin-optimizer-prs.github.io/pr/2592/frontend (Takes 3-5 minutes after this completes to be available)

[frontend] [Thu Jan 9 22:26:47 UTC 2025] - Deployed b9526b8 to https://genshin-optimizer-prs.github.io/pr/2592/frontend (Takes 3-5 minutes after this completes to be available)

[frontend] [Thu Jan 9 23:43:16 UTC 2025] - Deployed 2383bfa to https://genshin-optimizer-prs.github.io/pr/2592/frontend (Takes 3-5 minutes after this completes to be available)

[frontend] [Thu Jan 9 23:44:14 UTC 2025] - Deployed d8613e4 to https://genshin-optimizer-prs.github.io/pr/2592/frontend (Takes 3-5 minutes after this completes to be available)

[frontend] [Fri Jan 10 02:13:48 UTC 2025] - Deployed a004e2c to https://genshin-optimizer-prs.github.io/pr/2592/frontend (Takes 3-5 minutes after this completes to be available)

[Fri Jan 10 14:15:49 UTC 2025] - Deleted deployment

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
libs/gi/sheets/src/Artifacts/NoblesseOblige/index.tsx (1)

26-26: Check naming of 'no4' in nonStackBuff.

Passing 'no4' as the buff name is presumably shorthand for “Noblesse Oblige 4-piece.” The implementation is valid, but consider adding a short comment to clarify.

+// "no4" stands for Noblesse Oblige 4-piece non-stackable buff
const [set4, set4Inactive] = nonStackBuff('no4', 'atk_', percent(0.2))
libs/gi/sheets/src/SheetUtil.tsx (1)

92-105: Implementing nonStackBuff function.

This function clearly encapsulates the logic for determining which character is the source of a non-stackable buff. The usage of subVariant: 'strike' to visually show a disabled buff is a neat addition. Ensure you add or update unit tests for any edge cases around switching the active source.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b002758 and 7efea37.

📒 Files selected for processing (6)
  • libs/gi/sheets/src/Artifacts/NoblesseOblige/index.tsx (4 hunks)
  • libs/gi/sheets/src/SheetUtil.tsx (2 hunks)
  • libs/gi/ui/src/components/FieldDisplay.tsx (1 hunks)
  • libs/gi/ui/src/util/getCalcDisplay.tsx (2 hunks)
  • libs/gi/wr/src/formula.ts (2 hunks)
  • libs/gi/wr/src/type.d.ts (2 hunks)
🔇 Additional comments (12)
libs/gi/sheets/src/Artifacts/NoblesseOblige/index.tsx (4)

21-24: Confirm the correctness of set4TallyWrite's condition.

This block assigns set4TallyWrite using greaterEqStr and equalStr(condSet4, 'on', input.charKey). Please ensure that this string-based approach aligns with the new tally logic in other parts of the code.


36-38: New “tally” property in teamBuff.

You are now storing no4: set4TallyWrite in teamBuff.tally. This helps track which character is the primary buff source. Continue maintaining this separation to ensure clarity in the overall buff system.


58-60: Including inactive node in the 4-piece effect.

Displaying both set4 and set4Inactive in the states object clarifies the active or disabled status of the buff. This is a good way to provide visual feedback on which character’s buff is in effect.


3-10: Imports for new string-based comparisons and non-stacking buff logic.

Looks good overall. Please verify that all calls to these string-based utilities (equalStr, greaterEqStr) are up-to-date everywhere in the code, ensuring no leftover numeric-based comparisons remain that should be updated.

✅ Verification successful

String and numeric comparisons are being used appropriately

The codebase shows consistent and correct usage of comparison functions:

  • Numeric comparisons (greaterEq) for constellation levels, ascension levels, and numeric values
  • String comparisons (equalStr, greaterEqStr) for element types, state checks, and character keys
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searches for references to the older numeric comparison usage "greaterEq(" that might need converting to "greaterEqStr("
rg -A 3 $'greaterEq\\('

Length of output: 67051


Script:

#!/bin/bash
# Check implementation of comparison functions
ast-grep --pattern 'export function $func($$$) { $$$ }' libs/gi/wr/src/utils.ts

# Find usage of string comparison functions
rg -A 2 'equalStr|greaterEqStr'

Length of output: 15068

libs/gi/sheets/src/SheetUtil.tsx (1)

8-14: Expanded imports for new tally-based logic.

The new NonStackBuff, tally, and unequal imports support non-stackable buff implementation. Everything seems consistent with the usage in this PR.

Also applies to: 20-21

libs/gi/wr/src/type.d.ts (2)

51-51: subVariant now supports 'strike'.

Extending InfoVariant with 'strike' is a straightforward way to conditionally mark certain states. Keep an eye out for usage in the UI to ensure the line-through styling triggers reliably for all relevant buffs.


182-182: teamBuff.tally now accepts NumNode | StrNode.

Allowing the tally to store both numeric and string nodes is an excellent improvement for scenarios involving character-based comparisons. Just confirm no code path downcasts it to numeric-only.

libs/gi/ui/src/util/getCalcDisplay.tsx (2)

16-16: Use of Typography for formula display.

Good choice to import Material-UI’s Typography to unify styling for calculations.


224-229: Conditional text-decoration for ‘strike’ variant.

Applying line-through when info.subVariant === 'strike' effectively denotes inactive or overridden buffs. This aligns with the non-stackable design discussed in the PR objectives.

Also applies to: 233-233

libs/gi/ui/src/components/FieldDisplay.tsx (1)

201-201: Conditional text decoration looks good

Using subVariant === 'strike' to apply line-through is both clear and concise. This addition appears to serve its intended purpose of displaying a strike-through effect when the buff is disabled.

libs/gi/wr/src/formula.ts (2)

49-50: Well-structured enumeration for non-stackable buffs

Defining allNonstackBuffs as a constant and deriving the NonStackBuff type from it is a clear and type-safe implementation. This ensures maintenance is straightforward if more non-stackable buffs are introduced in the future.


583-583: Appropriate addition to the tally object

Integrating allNonstackBuffs into the tally guarantees that the relevant buff data is available throughout the system. This addition appears consistent with the goal of tracking non-stackable buffs.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
libs/gi/sheets/src/SheetUtil.tsx (1)

92-105: Add JSDoc documentation for the new function.

The implementation looks great and aligns perfectly with the PR objectives! The function effectively:

  • Uses the tally system to track buff sources
  • Integrates with the team buff framework
  • Provides visual feedback for disabled buffs

Consider adding JSDoc documentation to explain the function's purpose and parameters:

+/**
+ * Creates a non-stacking buff that can only be active from one source at a time.
+ * When multiple characters provide the same buff, only one (with the smallest character key)
+ * will be active while others will be visually marked as disabled.
+ *
+ * @param buffName - Unique identifier for the buff in the tally system
+ * @param path - Path for tracking the buff's state
+ * @param buffNode - Node containing the buff's effect
+ * @returns Array containing active and disabled buff states
+ */
 export function nonStackBuff(
   buffName: NonStackBuff,
   path: string,
   buffNode: NumNode
 )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7efea37 and 52c56f9.

📒 Files selected for processing (4)
  • libs/gi/sheets/src/SheetUtil.tsx (2 hunks)
  • libs/gi/ui/src/components/FieldDisplay.tsx (2 hunks)
  • libs/gi/ui/src/util/getCalcDisplay.tsx (2 hunks)
  • libs/gi/wr/src/type.d.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • libs/gi/ui/src/util/getCalcDisplay.tsx
  • libs/gi/ui/src/components/FieldDisplay.tsx
  • libs/gi/wr/src/type.d.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint
🔇 Additional comments (1)
libs/gi/sheets/src/SheetUtil.tsx (1)

8-14: LGTM! Import changes align with the non-stacking buff implementation.

The new imports provide the necessary types and functions for implementing the tally-based non-stacking buff system.

Also applies to: 20-21

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
libs/gi/wr/src/formula.ts (1)

49-50: LGTM! Consider adding JSDoc comments.

The implementation of non-stacking buff constants is well-structured and type-safe. The array approach allows for future expansion.

Consider adding JSDoc comments to explain:

  • The purpose of allNonstackBuffs
  • What qualifies as a non-stacking buff
  • The format/naming convention for buff identifiers (e.g., 'no4')
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52c56f9 and 96b0cbb.

📒 Files selected for processing (7)
  • libs/gi/sheets/src/Artifacts/NoblesseOblige/index.tsx (4 hunks)
  • libs/gi/sheets/src/SheetUtil.tsx (2 hunks)
  • libs/gi/ui/src/util/getCalcDisplay.tsx (2 hunks)
  • libs/gi/uidata/src/uiData.ts (2 hunks)
  • libs/gi/wr/src/api.ts (3 hunks)
  • libs/gi/wr/src/formula.ts (3 hunks)
  • libs/gi/wr/src/type.d.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • libs/gi/ui/src/util/getCalcDisplay.tsx
  • libs/gi/wr/src/type.d.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint
🔇 Additional comments (14)
libs/gi/wr/src/api.ts (3)

24-24: LGTM!

The import statement is correctly placed and aligns with the PR's objective of implementing non-stacking buffs.


44-47: LGTM!

The error handling logic is correctly extended to include non-stacking paths, maintaining consistency with the existing tally path handling.


249-255: LGTM!

The base operation logic in mergeData is well-structured and maintains consistency with the existing tally path handling. The use of ternary operators improves readability.

libs/gi/uidata/src/uiData.ts (2)

32-32: LGTM!

The import statement is correctly placed and aligns with the PR's objective.


541-542: LGTM!

The non-stacking path handling in getReadNode is well-implemented and maintains consistency with the existing tally path handling.

libs/gi/sheets/src/Artifacts/NoblesseOblige/index.tsx (4)

3-10: LGTM!

The imports are well-organized and include all necessary functions for the non-stacking functionality.


21-26: LGTM!

The implementation correctly switches from numeric to string comparison and properly implements the non-stacking buff mechanism.


36-38: LGTM!

The team buff data structure is correctly extended to include the non-stacking property.


58-60: LGTM!

The UI changes correctly implement visual feedback for inactive buffs through the set4Inactive node.

libs/gi/sheets/src/SheetUtil.tsx (2)

8-14: LGTM!

The imports are well-organized and include all necessary types and functions for the non-stacking functionality.

Also applies to: 20-21


92-105: LGTM!

The nonStackBuff function is well-implemented with:

  • Clear parameter types
  • Proper handling of active and inactive states
  • Visual feedback through strikethrough formatting
  • Correct team buff context handling
libs/gi/wr/src/formula.ts (3)

592-595: LGTM! Implementation aligns with requirements.

The non-stacking buff tracking implementation correctly:

  • Uses small string comparison for source selection
  • Maintains proper namespace separation
  • Follows established patterns in the codebase

614-614: LGTM! Export maintains consistency.

The addition of nonStacking to exports is necessary and maintains alphabetical ordering.


49-50: Verify visual feedback implementation.

While the non-stacking buff implementation looks correct, please verify:

  1. How the strikethrough formatting for disabled buffs is implemented
  2. The handling of multiple buff sources (e.g., Mavuika and Citlali scenario mentioned in PR objectives)

Also applies to: 592-595

✅ Verification successful

Implementation verified successfully

The codebase correctly implements:

  • Visual feedback through strikethrough styling in UI components
  • Multiple buff source handling with proper source detection
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for UI components handling buff display
rg -l "no4.*disabled|strikethrough" --type ts --type tsx

# Search for test cases covering multiple buff sources
rg -l "test.*no4.*buff.*source" --type ts --type tsx

Length of output: 169


Script:

#!/bin/bash
# Search for UI components handling buff display and strikethrough
rg -l "strikethrough|disabled.*buff" --type ts

# Search for buff source handling implementation
rg -A 5 "no4.*buff" --type ts

# Search for test files related to buffs
rg -l "describe.*buff|test.*buff" --type ts

Length of output: 336


Script:

#!/bin/bash
# Check UI components for buff display implementation
rg -A 5 "strikethrough" libs/gi/ui/src/components/FieldDisplay.tsx
rg -A 5 "disabled.*buff|buff.*disabled" libs/gi/ui/src/components/FieldDisplay.tsx

# Check utility implementation
rg -A 5 "strikethrough" libs/gi/ui/src/util/getCalcDisplay.tsx

# Check type definitions
rg -A 5 "strikethrough|disabled.*buff" libs/gi/type.d.ts

Length of output: 929


Script:

#!/bin/bash
# Check buff calculation implementation
rg -A 10 "export (function|const) .*buff.*calc" --type ts

# Check for buff source handling
rg -A 10 "source.*buff|buff.*source" --type ts

Length of output: 1443

Copy link
Owner

@frzyc frzyc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nguyentvan7 nguyentvan7 merged commit dd6dac4 into master Jan 10, 2025
9 checks passed
@nguyentvan7 nguyentvan7 deleted the van/go/nonStack branch January 10, 2025 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Every (or almost every) buff should not stack
3 participants