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

fix: resource prod cap #1834

Merged
merged 2 commits into from
Oct 14, 2024
Merged

fix: resource prod cap #1834

merged 2 commits into from
Oct 14, 2024

Conversation

edisontim
Copy link
Collaborator

@edisontim edisontim commented Oct 14, 2024

Closes #1819

Summary by CodeRabbit

  • New Features

    • Enhanced balance display logic to prevent updates when inputs are consumed without outputs.
    • Improved clarity in the rendering of net rates, now only shown during active production with a positive balance.
  • Bug Fixes

    • Adjusted balance update conditions for better accuracy in resource management.
  • Refactor

    • Simplified the useStructures hook by optimizing component dependencies and imports for improved code clarity.

Copy link

vercel bot commented Oct 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eternum ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 14, 2024 3:48pm

Copy link
Contributor

coderabbitai bot commented Oct 14, 2024

Walkthrough

The pull request introduces several modifications across multiple files, primarily focusing on the useStructures hook and its related functions. Key changes include the removal of specific destructured components to simplify dependencies, the direct import of the getEntityName function, and adjustments to the balance calculation logic in the ResourceChip component. Additionally, logging messages in the EternumConfig class have been clarified. Overall, the changes aim to optimize code clarity while maintaining existing functionality.

Changes

File Path Change Summary
client/src/hooks/helpers/useStructures.tsx Removed EntityName and Realm from useStructures hook; updated getEntityName usage in getStructureByEntityId.
client/src/ui/components/resources/ResourceChip.tsx Modified balance calculation logic to prevent updates when inputs are consumed without outputs; adjusted net rate rendering.
sdk/packages/eternum/src/config/index.ts Updated logging messages in setupGlobals function for clarity; no functional changes made.

Assessment against linked issues

Objective Addressed Explanation
Prevent infinite production of Alchemical Silver (#1819) Changes do not address backend production logic.

Possibly related PRs

  • Raschel/dev #1818: The changes in the useStructureEntityId hook relate to the useStructures hook in the main PR, as both involve modifications to how structure-related data is accessed and managed.
  • Entity names #1830: The updates to the useStructures hook in the main PR are directly related to the changes in the useStructures function in this PR, which also involves renaming and refactoring structure-related utility functions.

Suggested reviewers

  • ponderingdemocritus
  • aymericdelab

Poem

🐰 In the code where structures play,
A hop and a skip, we clear the way.
With balance and rates, we make it bright,
Simplifying hooks, a coder's delight!
So let’s celebrate with a joyful cheer,
For clarity gained, let’s give a big ear! 🎉


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 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

Failed to generate code suggestions for PR

Copy link
Contributor

@mentatbot mentatbot bot left a comment

Choose a reason for hiding this comment

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

The changes in this PR appear to address the issue of fixing the resource production cap. The modifications in ResourceChip.tsx improve the logic for updating the display balance and showing production rates, considering cases where inputs are depleted or production has stopped. The optimization in useStructures.tsx by moving getEntityName outside the function is good for performance. The minor correction in the console log message in index.ts improves clarity. Overall, these changes seem appropriate and aligned with the PR's goal. Consider adding comments to explain the new conditions in ResourceChip.tsx for better code readability, and ensure that moving getEntityName in useStructures.tsx doesn't affect its functionality. It might also be beneficial to add unit tests to verify the new behavior of ResourceChip, especially the conditions for displaying production rates and updating balances.

Thanks for using MentatBot. Give comments a 👍 or 👎 to help me improve!

@@ -80,7 +80,7 @@ export const ResourceChip = ({

const interval = setInterval(() => {
setDisplayBalance((prevDisplayBalance) => {
if (Math.abs(netRate) > 0) {
if (Math.abs(netRate) > 0 && !isConsumingInputsWithoutOutput) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Good addition of the !isConsumingInputsWithoutOutput check. Consider adding a comment explaining the purpose of this condition for better code readability.

@@ -137,7 +137,7 @@
: ""}
</div>

{netRate && !reachedMaxCap ? (
{netRate && !reachedMaxCap && !isConsumingInputsWithoutOutput && displayBalance > 0 ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

The additional checks !isConsumingInputsWithoutOutput && displayBalance > 0 are good improvements. Consider adding a comment explaining why these conditions are necessary for displaying the production rate.

},
} = useDojo();

const { getAliveArmy } = getArmyByEntityId();
const { getEntityName } = useEntitiesUtils();
Copy link
Contributor

Choose a reason for hiding this comment

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

Good optimization moving getEntityName outside of getStructureByEntityId. Ensure this doesn't affect its functionality if it was relying on any local variables.

Copy link
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (2)
client/src/ui/components/resources/ResourceChip.tsx (2)

Line range hint 140-173: Approval: Improved display logic and user feedback

These changes significantly improve the user interface by:

  1. Ensuring the net rate is only displayed when production is active and there's a positive balance.
  2. Adding a warning icon with informative tooltips when production has stopped.

These enhancements align well with the PR objective by providing clearer feedback on resource production status, particularly when resources are depleted or max capacity is reached.

For consistency, consider using template literals for the className in the warning icon div:

-className="self-center px-2 col-span-3 mx-auto"
+className={`self-center px-2 col-span-3 mx-auto ${isConsumingInputsWithoutOutput || reachedMaxCap ? 'cursor-help' : ''}`}

This change would make the cursor change to a help icon when hovering over the warning, consistent with the presence of a tooltip.


Line range hint 1-173: Summary: Effective solution to infinite resource production issue

The changes in this file successfully address the core issue described in the PR objectives:

  1. The balance update logic now prevents infinite production when inputs are depleted.
  2. The UI provides clear feedback on production status, including warnings when production has stopped due to depleted inputs or reached max capacity.

These modifications not only fix the bug but also improve the overall user experience by providing more accurate and informative resource production information.

To further improve the robustness of the solution, consider implementing server-side checks to ensure that resource production is always contingent on available inputs. This would provide an additional layer of protection against similar issues in the future.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d3305ce and 460e3cd.

📒 Files selected for processing (3)
  • client/src/hooks/helpers/useStructures.tsx (1 hunks)
  • client/src/ui/components/resources/ResourceChip.tsx (2 hunks)
  • sdk/packages/eternum/src/config/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • sdk/packages/eternum/src/config/index.ts
🧰 Additional context used
🔇 Additional comments (2)
client/src/ui/components/resources/ResourceChip.tsx (1)

83-86: Approval: Prevents updating balance when inputs are depleted

This change effectively addresses the issue of infinite resource production by preventing balance updates when inputs are being consumed without producing output. It aligns well with the PR objective of fixing the bug that allowed Alchemical Silver to be produced without the necessary resources.

client/src/hooks/helpers/useStructures.tsx (1)

Line range hint 1-280: Clarify the relationship between these changes and the PR objectives.

While the changes in this file improve code clarity and optimize imports, it's not immediately clear how they address the issue of infinite production of Alchemical Silver without the required resources (Twilight Quartz and Adamantine) as mentioned in the PR objectives.

Could you please clarify:

  1. How do these changes in the useStructures hook contribute to fixing the production cap issue?
  2. Are there other files or components that handle the actual resource production logic?
  3. Is this part of a larger refactoring effort that indirectly contributes to fixing the production cap issue?

This information would help reviewers better understand the context and impact of these changes in relation to the stated objectives of the PR.

@@ -162,11 +162,12 @@ export const useStructures = () => {
const {
account: { account },
setup: {
components: { Structure, EntityOwner, Owner, Protector, EntityName, Realm, Position, AddressName },
components: { Structure, EntityOwner, Owner, Protector, Position, AddressName },
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

EntityName and Realm Still Present After Intended Removal

The useStructures.tsx file still includes EntityName and Realm in the destructured components. Please remove these to simplify dependencies as intended.

  • Line 165:
    components: { Structure, EntityOwner, Owner, Protector, EntityName, Realm },
  • Additional Instances:
    import { getRealm } from "@/ui/utils/realms";
    const { getEntityName } = useEntitiesUtils();
    const name = getEntityName(structure.entity_id);
🔗 Analysis chain

LGTM! Verify impact on other parts of the codebase.

The removal of EntityName and Realm from the destructured components simplifies the dependencies in the useStructures hook, which is a good practice. This change, along with the direct import of getEntityName, aligns with the goal of optimizing code clarity.

However, these changes don't seem to directly address the issue of infinite production of Alchemical Silver mentioned in the PR objectives.

To ensure this change doesn't have unintended consequences, please run the following script to check for any remaining usages of EntityName and Realm in this file:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usages of EntityName and Realm in the file

# Test: Search for EntityName and Realm usage
rg --type typescript 'EntityName|Realm' client/src/hooks/helpers/useStructures.tsx

Length of output: 119


Script:

#!/bin/bash
# Description: Check for any remaining usages of EntityName and Realm in the file

# Test: Search for EntityName and Realm usage
rg --type ts 'EntityName|Realm' client/src/hooks/helpers/useStructures.tsx

Length of output: 964

@aymericdelab aymericdelab merged commit ff164f6 into main Oct 14, 2024
9 checks passed
@aymericdelab aymericdelab deleted the fix/resource-prod-cap branch October 14, 2024 16:04
This was referenced Nov 4, 2024
@coderabbitai coderabbitai bot mentioned this pull request Nov 15, 2024
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.

Infinite production of Alchemical Silver
2 participants