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

hs cost #2443

Merged
merged 4 commits into from
Dec 12, 2024
Merged

hs cost #2443

merged 4 commits into from
Dec 12, 2024

Conversation

aymericdelab
Copy link
Collaborator

@aymericdelab aymericdelab commented Dec 12, 2024

Summary by CodeRabbit

  • New Features

    • Added synchronization status tracking for resources in the Entity component.
    • Implemented a loading message for users during resource synchronization.
    • Enhanced key matching logic in the setup process.
  • Bug Fixes

    • Improved error handling during resource fetch operations.
  • Style

    • Reformatted import statements for better readability.

Copy link

vercel bot commented Dec 12, 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 Dec 12, 2024 10:54am
eternum-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 12, 2024 10:54am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
eternum-landing ⬜️ Ignored (Inspect) Visit Preview Dec 12, 2024 10:54am

Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes in the pull request involve modifications to the setup function within the client/src/dojo/setup.ts file. The primary alteration is the addition of HYPERSTRUCTURE_CONFIG_ID to the import statements and a new clause in the keys array that includes undefined. Additionally, the EntityArrival component in client/src/ui/components/entities/Entity.tsx has been updated to include a new state variable isSyncing to track synchronization status, along with error handling and user feedback during resource syncing.

Changes

File Change Summary
client/src/dojo/setup.ts Added HYPERSTRUCTURE_CONFIG_ID to imports. Introduced a new clause in the keys array including undefined. Adjusted existing clauses without changing core logic.
client/src/ui/components/entities/Entity.tsx Added isSyncing state to EntityArrival component, implemented subscription on empty entityResources, added error handling, and updated rendering logic to reflect syncing status.

Possibly related PRs

  • hyperstructure costs in dev mode #2148: This PR modifies the configuration setup related to hyperstructures, which is relevant due to the addition of HYPERSTRUCTURE_CONFIG_ID in the main PR's changes to the setup function.
  • [client] hyperstructure optimistic fixes #2273: This PR introduces DUMMY_HYPERSTRUCTURE_ENTITY_ID, which is related to the handling of hyperstructures, aligning with the changes made in the main PR regarding hyperstructure configuration.
  • fix HS costs #2303: This PR addresses hyperstructure costs, which connects to the changes in the main PR that involve HYPERSTRUCTURE_CONFIG_ID, indicating a focus on hyperstructure-related functionality.
  • Loaf opti #2439: Although the details are sparse, the title "Loaf opti" suggests optimizations that could relate to the overall handling of hyperstructures, which is a theme in the main PR.

Suggested reviewers

  • bob0005
  • ponderingdemocritus

🐰 "In the dojo where rabbits play,
The keys now dance in a new array.
With undefined joining the fun,
Matching keys is now well done!
Hooray for changes, bright and clear,
In our setup, we cheer and cheer!" 🐇


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. (Experiment)
  • @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

mentatbot bot commented Dec 12, 2024

You are out of MentatBot reviews. Your usage will refresh December 16 at 08:00 AM.

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

🧹 Outside diff range and nitpick comments (1)
client/src/dojo/setup.ts (1)

Line range hint 19-94: Consider splitting setup responsibilities

The setup function handles multiple concerns (network, components, system calls, sync). Consider:

  1. Breaking it down into smaller, focused functions
  2. Adding explicit error handling for sync operations
  3. Implementing retry logic for failed sync attempts

This would improve maintainability and reliability.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0fc5a97 and d77f845.

📒 Files selected for processing (1)
  • client/src/dojo/setup.ts (2 hunks)
🔇 Additional comments (2)
client/src/dojo/setup.ts (2)

1-5: LGTM! Import formatting improves readability

The grouped imports from @bibliothecadao/eternum enhance code organization.


52-58: Verify the impact of broader key matching

The new clause for HYPERSTRUCTURE_CONFIG_ID uses "VariableLen" pattern matching with an undefined second key. This differs from the WORLD_CONFIG_ID approach which uses two separate clauses. Please verify:

  1. Is this broader matching intentional?
  2. Could this affect which entities are synced?

Let's check for any existing patterns in the codebase:

✅ Verification successful

Let me analyze the usage patterns further to understand the consistency of key matching.


Let me try one more search to see the complete setup context:


The broader key matching is intentional and consistent with the codebase patterns

Based on the evidence from the codebase:

  1. The VariableLen pattern matching with undefined second key is consistent with how WORLD_CONFIG_ID is handled, which also uses VariableLen.
  2. The usage of getEntityIdFromKeys shows that HYPERSTRUCTURE_CONFIG_ID is queried both with and without a second parameter across the codebase, justifying the need for variable length matching.
  3. This pattern allows the sync to capture both single-key and two-key entity configurations, which aligns with the actual usage in the ConfigManager implementations.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for similar key pattern usage to understand the convention

# Look for similar pattern matching configurations
rg -A 5 "pattern_matching.*VariableLen" --type ts

# Look for HYPERSTRUCTURE_CONFIG_ID usage
rg "HYPERSTRUCTURE_CONFIG_ID" --type ts

Length of output: 4418


Script:

#!/bin/bash
# Look for getEntityIdFromKeys usage with HYPERSTRUCTURE_CONFIG_ID to understand the key patterns
rg -B 2 -A 2 "getEntityIdFromKeys.*HYPERSTRUCTURE_CONFIG_ID" --type ts

# Look for other config patterns in setup.ts
rg -A 10 "Keys: {" client/src/dojo/setup.ts

Length of output: 4577


Script:

#!/bin/bash
# Look at the complete setup.ts file to understand the key patterns
cat client/src/dojo/setup.ts

Length of output: 2395

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

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

88-90: Consider enhancing the syncing feedback

While the current implementation is functional, consider providing more detailed feedback about the synchronization process to improve user experience.

Here's a suggested enhancement:

    if (isSyncing) {
-     return <div className="text-gold/50 italic">Syncing resources...</div>;
+     return (
+       <div className="text-gold/50 italic flex items-center gap-2">
+         <div className="animate-spin">⚙️</div>
+         <span>Syncing resources for {entityName[entity.entityType]}...</span>
+       </div>
+     );
    }

Line range hint 51-104: Consider extracting synchronization logic

The component currently handles both UI rendering and data synchronization. Consider extracting the synchronization logic into a custom hook (e.g., useEntitySync) to:

  • Improve code reusability
  • Separate concerns
  • Make the component more maintainable
  • Simplify testing

Example structure:

// hooks/useEntitySync.ts
export function useEntitySync(entityId: string) {
  const [isSyncing, setIsSyncing] = useState(false);
  const dojo = useDojo();
  
  useEffect(() => {
    // Current synchronization logic
  }, [entityId]);

  return { isSyncing };
}

// EntityArrival component
const { isSyncing } = useEntitySync(arrival.entityId);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d77f845 and 56c3448.

📒 Files selected for processing (1)
  • client/src/ui/components/entities/Entity.tsx (6 hunks)
🔇 Additional comments (3)
client/src/ui/components/entities/Entity.tsx (3)

14-14: LGTM: Import addition is appropriate

The useState import is correctly added to support the new synchronization state management.


36-36: LGTM: State management implementation is clean

The isSyncing state is well-placed and appropriately initialized.


51-69: 🛠️ Refactor suggestion

Consider improving error handling and type safety

A few suggestions to enhance this implementation:

  1. Consider showing error feedback to users when synchronization fails
  2. The as any type assertion should be avoided if possible
  3. Consider memoizing the network objects to prevent unnecessary effect triggers

Here's a suggested improvement:

+ const { toriiClient, contractComponents } = dojo.network;
+ const memoizedNetwork = useMemo(() => ({
+   toriiClient,
+   contractComponents
+ }), [toriiClient, contractComponents]);

  useEffect(() => {
    if (entityResources.length === 0) {
      setIsSyncing(true);
      const fetch = async () => {
        try {
          await addToSubscription(
-           dojo.network.toriiClient,
-           dojo.network.contractComponents as any,
+           memoizedNetwork.toriiClient,
+           memoizedNetwork.contractComponents,
            arrival.entityId.toString(),
          );
        } catch (error) {
          console.error("Fetch failed", error);
+         // Show error to user
+         toast.error("Failed to sync resources. Please try again.");
        } finally {
          setIsSyncing(false);
        }
      };
      fetch();
    }
-  }, [arrival.entityId, dojo.network.toriiClient, dojo.network.contractComponents, entityResources.length]);
+  }, [arrival.entityId, memoizedNetwork, entityResources.length]);

Let's verify the type definition of contractComponents:

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

🧹 Outside diff range and nitpick comments (1)
client/src/dojo/setup.ts (1)

52-58: Consider sync performance implications

The addition of a new clause with variable length pattern matching could impact sync performance, especially with the existing 40,000 batch size. Consider:

  1. Monitoring sync performance after this change
  2. Implementing pagination or chunking if performance degrades
  3. Adding telemetry to track sync times specifically for hyperstructure entities
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 56c3448 and bc2b9f3.

📒 Files selected for processing (1)
  • client/src/dojo/setup.ts (2 hunks)
🔇 Additional comments (2)
client/src/dojo/setup.ts (2)

3-4: LGTM: Import addition is consistent and used

The new import follows the existing pattern and is properly utilized in the code.


52-58: Verify the use of "VariableLen" pattern matching

The new clause uses "VariableLen" pattern matching while other clauses use "FixedLen". This difference in matching strategy could have implications for entity synchronization.

Please verify:

  1. Is this difference intentional?
  2. Are there any security considerations for variable length matching?

Let's check for similar patterns in the codebase:

✅ Verification successful

Use of "VariableLen" pattern matching is consistent with similar config entities

Based on the codebase analysis, the use of "VariableLen" for HYPERSTRUCTURE_CONFIG_ID is intentional and follows an established pattern:

  • In WorldStructuresMenu.tsx, "VariableLen" is used for all config-related queries including other hyperstructure entries
  • In landing/src/dojo/setup.ts, similar config entities (WORLD_CONFIG_ID) also use "VariableLen"
  • "FixedLen" is primarily used for position-based queries and entity-specific lookups as seen in queries.ts

This pattern suggests that variable length matching is the intended strategy for config-related entities, allowing for flexible key structures while maintaining strict fixed-length matching for position and entity-specific queries.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other instances of VariableLen pattern matching
rg -B 5 -A 5 '"VariableLen"' --type ts

# Search for any documentation or comments about pattern matching
rg -B 5 -A 5 'pattern_matching' --type ts --type md

Length of output: 10791

@aymericdelab aymericdelab merged commit 9fc09d6 into next Dec 12, 2024
7 of 9 checks passed
@aymericdelab aymericdelab deleted the raschel-dev branch December 12, 2024 10:54
@coderabbitai coderabbitai bot mentioned this pull request Dec 12, 2024
edisontim added a commit that referenced this pull request Dec 12, 2024
* Add confirmation step to destroy building

* raise limits and remove chat (#2435)

* loading page loading itmes (#2436)

* loaf-opti

* buildings

* load

* push config

* loading

* fix for 0 donkey bridge, base manifest on chain env

* tiles

* merge

* do sync

* bank

* market

* bump

* queries

* reintroduce syncing and fetching

* sync and get happening again

* working multi bridge out step 2, fix transaction success states

* tiles

* remove logging

* memo

* world

* set loading state

* chunk

* coords

* as

* bunk

* bridge styling

* update

* update dojo version

* update dojo sync

* Fix hyperstructures

* fix

* add back chat

* a

* llint

* ✨ Add sub to all player structures

* fix(social): get name from address directly

* chore: add has not settled realm yet

* undefined if no realm found

* pretty

* fix: trade history crash

* 🐛 Fix

* config

* add realm select border animation

* hovered frag mine

* hs cost (#2443)

* hs cost

* fix deposit arrival

* update lock

* load

* Fix/army stamina (#2448)

* Fix current tick values in nextBlockTimestamp

* lint

* Remove quest UI while syncing (#2449)

* Remove quest UI while syncing

* Add quest load animation

* Raschel-dev (#2447)

* hs cost

* fix deposit arrival

* update lock

* fix hs crash

* building cost config

* fix namespace

* remove resource cost syncing

* added production

* fix costs

* add upgrade

* trigger

* remove events

* fix tile

* fixes

* remove loading

* fix: transfer view styling bug (#2451)

* Fix social tribe crash (#2450)

* fix build

* fix market

---------

Co-authored-by: Bob <[email protected]>
Co-authored-by: tedison <[email protected]>
Co-authored-by: ponderingdemocritus <[email protected]>
Co-authored-by: tedison <[email protected]>
Co-authored-by: RedBeardEth <[email protected]>
Co-authored-by: Loaf <[email protected]>
Co-authored-by: bal7hazar <[email protected]>
Co-authored-by: Nasr <[email protected]>
Co-authored-by: Larko <[email protected]>
Co-authored-by: 0x1337 <[email protected]>
Co-authored-by: Bob <[email protected]>
Co-authored-by: zabanyat.eth <[email protected]>
aymericdelab added a commit that referenced this pull request Dec 12, 2024
* Add confirmation step to destroy building

* raise limits and remove chat (#2435)

* loading page loading itmes (#2436)

* loaf-opti

* buildings

* load

* push config

* loading

* fix for 0 donkey bridge, base manifest on chain env

* tiles

* merge

* do sync

* bank

* market

* bump

* queries

* reintroduce syncing and fetching

* sync and get happening again

* working multi bridge out step 2, fix transaction success states

* tiles

* remove logging

* memo

* world

* set loading state

* chunk

* coords

* as

* bunk

* bridge styling

* update

* update dojo version

* update dojo sync

* Fix hyperstructures

* fix

* add back chat

* a

* llint

* ✨ Add sub to all player structures

* fix(social): get name from address directly

* chore: add has not settled realm yet

* undefined if no realm found

* pretty

* fix: trade history crash

* 🐛 Fix

* config

* add realm select border animation

* hovered frag mine

* hs cost (#2443)

* hs cost

* fix deposit arrival

* update lock

* load

* Fix/army stamina (#2448)

* Fix current tick values in nextBlockTimestamp

* lint

* Remove quest UI while syncing (#2449)

* Remove quest UI while syncing

* Add quest load animation

* Raschel-dev (#2447)

* hs cost

* fix deposit arrival

* update lock

* fix hs crash

* building cost config

* fix namespace

* remove resource cost syncing

* added production

* fix costs

* add upgrade

* trigger

* remove events

* fix tile

* fixes

* remove loading

* fix: transfer view styling bug (#2451)

* Fix social tribe crash (#2450)

* fix build

* fix market

* feat: optimise event messages (#2455)

* optimize events

* fix getSyncEvents composite

* small fixes

---------

Co-authored-by: Bob <[email protected]>
Co-authored-by: ponderingdemocritus <[email protected]>
Co-authored-by: RedBeardEth <[email protected]>
Co-authored-by: Loaf <[email protected]>
Co-authored-by: aymericdelab <[email protected]>
Co-authored-by: bal7hazar <[email protected]>
Co-authored-by: Nasr <[email protected]>
Co-authored-by: Larko <[email protected]>
Co-authored-by: 0x1337 <[email protected]>
Co-authored-by: raschel <[email protected]>
Co-authored-by: Bob <[email protected]>
Co-authored-by: zabanyat.eth <[email protected]>
aymericdelab added a commit that referenced this pull request Dec 12, 2024
* Add confirmation step to destroy building

* raise limits and remove chat (#2435)

* loading page loading itmes (#2436)

* loaf-opti

* buildings

* load

* push config

* loading

* fix for 0 donkey bridge, base manifest on chain env

* tiles

* merge

* do sync

* bank

* market

* bump

* queries

* reintroduce syncing and fetching

* sync and get happening again

* working multi bridge out step 2, fix transaction success states

* tiles

* remove logging

* memo

* world

* set loading state

* chunk

* coords

* as

* bunk

* bridge styling

* update

* update dojo version

* update dojo sync

* Fix hyperstructures

* fix

* add back chat

* a

* llint

* ✨ Add sub to all player structures

* fix(social): get name from address directly

* chore: add has not settled realm yet

* undefined if no realm found

* pretty

* fix: trade history crash

* 🐛 Fix

* config

* add realm select border animation

* hovered frag mine

* hs cost (#2443)

* hs cost

* fix deposit arrival

* update lock

* load

* Fix/army stamina (#2448)

* Fix current tick values in nextBlockTimestamp

* lint

* Remove quest UI while syncing (#2449)

* Remove quest UI while syncing

* Add quest load animation

* Raschel-dev (#2447)

* hs cost

* fix deposit arrival

* update lock

* fix hs crash

* building cost config

* fix namespace

* remove resource cost syncing

* added production

* fix costs

* add upgrade

* trigger

* remove events

* fix tile

* fixes

* remove loading

* fix: transfer view styling bug (#2451)

* Fix social tribe crash (#2450)

* fix build

* fix market

* add lords to controller on landing

* feat: optimise event messages (#2455)

* optimize events

* fix getSyncEvents composite

* small fixes

* 🐛 Fix mainnet torii cfg

* Fix laggy social search

* landing page + quest + inventory (#2461)

* update inventory

* more discrete quest loading

* fix landing page sync

---------

Co-authored-by: Bob <[email protected]>
Co-authored-by: tedison <[email protected]>
Co-authored-by: ponderingdemocritus <[email protected]>
Co-authored-by: tedison <[email protected]>
Co-authored-by: RedBeardEth <[email protected]>
Co-authored-by: Loaf <[email protected]>
Co-authored-by: bal7hazar <[email protected]>
Co-authored-by: Nasr <[email protected]>
Co-authored-by: Larko <[email protected]>
Co-authored-by: 0x1337 <[email protected]>
Co-authored-by: Bob <[email protected]>
Co-authored-by: zabanyat.eth <[email protected]>
@coderabbitai coderabbitai bot mentioned this pull request Dec 12, 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.

1 participant