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/various #2740

Merged
merged 9 commits into from
Mar 10, 2025
Merged

Fix/various #2740

merged 9 commits into from
Mar 10, 2025

Conversation

bob0005
Copy link
Collaborator

@bob0005 bob0005 commented Mar 10, 2025

Closes #2211
Closes #2520
Fix add troops

Summary by CodeRabbit

  • New Features

    • Introduced a new interactive map icon that streamlines navigation.
    • Added a conditional resource linking button now available for connected users.
  • Bug Fixes

    • Corrected owner information display in army management.
  • Refactor

    • Streamlined army details to display accurate owner information and improved troop addition logic.
    • Enhanced the chat interface, enabling dynamic visibility of event feeds.
    • Simplified arrival time displays.
    • Adjusted specific building resource requirements for improved balance.
    • Improved import organization for better code clarity.
    • Refined address retrieval and name decoding processes for enhanced performance.

Copy link

vercel bot commented Mar 10, 2025

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 Mar 10, 2025 5:45pm
eternum-docs ❌ Failed (Inspect) Mar 10, 2025 5:45pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
eternum-landing ⬜️ Ignored (Inspect) Visit Preview Mar 10, 2025 5:45pm

Copy link
Contributor

coderabbitai bot commented Mar 10, 2025

Walkthrough

The pull request updates multiple parts of the application. In the military module, the ArmyChip component now passes the owner entity via army.entity_owner_id instead of army.entityId, and ArmyManagementCard computes a new homeDirection for troop management. The ViewOnMapIcon component has been relocated, and its old references removed. Additional changes include updates in the chat and navigation modules with adjustments to component rendering, modifications to utility functions for time formatting and precision handling, and resource cost updates in building configurations.

Changes

File(s) Change Summary
client/apps/game/.../military/army-chip.tsx, client/apps/game/.../military/army-management-card.tsx Updated ArmyChip to pass army.entity_owner_id to ArmyManagementCard; ArmyManagementCard now computes homeDirection and removes ViewOnMapIcon component.
client/apps/game/.../view-on-map-icon.tsx, client/apps/game/.../trading/market-header.tsx, client/apps/game/.../navigation/top-left-navigation.tsx, client/apps/game/.../social/player-id.tsx, client/apps/game/.../world-structures/world-structures-menu.tsx Introduced new ViewOnMapIcon component in a new location; updated import paths across several modules.
client/apps/game/.../modules/chat/chat.tsx, client/apps/game/.../modules/navigation/left-navigation-module.tsx, client/apps/game/.../modules/navigation/right-navigation-module.tsx, client/apps/game/.../modules/navigation/secondary-menu-items.tsx, client/apps/game/.../modules/stream/event-stream.tsx Added hideChat prop to EventStream; removed its rendering in left navigation; eliminated external trade link in right navigation; added a new conditional button in SecondaryMenuItems; adjusted EventStream layout logic.
client/apps/game/.../utils/utils.ts Simplified formatArrivalTime function to display only hours and minutes, removing day/month extraction and countdown logic.
packages/core/.../managers/army-manager.ts, packages/core/.../utils/army.ts, packages/core/.../utils/utils.ts Updated ArmyManager’s addTroopsToExplorer to accept a dynamic homeDirection and apply precision adjustments; added isArmyAdjacentToStructure in army utils; modified divideByPrecision to use Math.floor.
client/update-policies.js, config/environments/utils/building.ts Removed redundant import of entire fs module; increased Ignium cost from 750 to 750,000.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant AC as ArmyChip
    participant AMC as ArmyManagementCard
    participant AM as ArmyManager

    U->>AC: Initiates troop action
    AC->>AMC: Pass updated owner entity and event
    AMC->>AMC: Compute homeDirection using position data
    AMC->>AM: Call addTroopsToExplorer with homeDirection & troop count
    AM->>AM: Adjust troop count via multiplyByPrecision
    AM-->>AMC: Return update result
Loading
sequenceDiagram
    participant U as User
    participant VIcon as ViewOnMapIcon
    participant UI as UI Store

    U->>VIcon: Mouse enters icon (if tooltip allowed)
    VIcon->>UI: Set tooltip "View on Map"
    U->>VIcon: Clicks icon
    VIcon->>UI: Clear tooltip
    VIcon->>Map: Navigate to map view with position prop
Loading

Possibly related PRs

Poem

I'm a coding rabbit, hopping through the lines,
Army orders updated, with new directions that shine.
Map icons now leap to a brand new home,
Chat and navigation paths perfectly roam.
In the code garden, each change is a delight—
Hop on, dear coder, let’s celebrate tonight! 🐇

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

 ERR_PNPM_OPTIONAL_DEPS_REQUIRE_PROD_DEPS  Optional dependencies cannot be installed without production dependencies


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7a71b37 and 5cb570f.

📒 Files selected for processing (4)
  • client/apps/game/src/ui/modules/stream/event-details.tsx (4 hunks)
  • client/apps/game/src/ui/modules/stream/event-stream.tsx (5 hunks)
  • client/apps/game/src/ui/modules/world-structures/world-structures-menu.tsx (2 hunks)
  • packages/core/src/utils/entities.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • client/apps/game/src/ui/modules/world-structures/world-structures-menu.tsx
  • client/apps/game/src/ui/modules/stream/event-stream.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test-season-pass
🔇 Additional comments (5)
packages/core/src/utils/entities.ts (4)

100-100: Improved address name decoding

The update ensures that address names are properly decoded using shortString.decodeShortString before being returned, which is the correct way to handle short string data.


104-104: Updated function reference

The code now uses getAddressFromStructureEntity instead of getAddressFromEntity, which aligns with the refactored function implementation below.


108-108: Consistent short string decoding

The update ensures consistent decoding of address names using shortString.decodeShortString throughout the codebase.


111-116:

❓ Verification inconclusive

Simplified owner retrieval logic

This new function replaces the previous getAddressFromEntity with a more straightforward implementation that directly retrieves the owner from the Structure component. This simplification improves code clarity and maintenance.

Please verify that there are no cases where the owner needs to be retrieved from ExplorerTroops as this implementation only checks the Structure component.


🏁 Script executed:

#!/bin/bash
# Search for any references to the old getAddressFromEntity function in the codebase
echo "Searching for references to getAddressFromEntity that might still exist:"
rg "getAddressFromEntity" --type=ts --type=tsx

Length of output: 229


Below is a revised review comment. Because the original search encountered an error with the "tsx" file type, please re-run the attached script to verify that no owner retrieval from ExplorerTroops (or lingering calls to getAddressFromEntity) remain in both .ts and .tsx files.


Simplified owner retrieval logic – please verify additional cases

The new function correctly simplifies owner retrieval by obtaining the owner directly from the Structure component and replacing the old getAddressFromEntity. However, we need to confirm that there aren’t use cases requiring retrieval from ExplorerTroops (especially in .tsx files) that might have been missed due to file type handling issues in the initial search.

Please run the following script to check for any references:

#!/bin/bash
echo "Searching for references to getAddressFromEntity in .ts and .tsx files:"
rg --type-add 'tsx:*.tsx' "getAddressFromEntity" --type ts --type tsx

echo "Searching for ExplorerTroops references that might indicate owner retrieval in .ts and .tsx files:"
rg --type-add 'tsx:*.tsx' "ExplorerTroops" --type ts --type tsx

Once you’ve manually verified that these searches return no unintended references, we can be confident that no additional owner retrieval (via ExplorerTroops) is needed.

client/apps/game/src/ui/modules/stream/event-details.tsx (1)

17-17: Updated function parameter naming for clarity

The parameter name has been consistently updated from getAddressFromEntity to getAddressFromStructureEntity across all event types. This change aligns with the updated function name in the utils/entities.ts file and better reflects what the function does - retrieving an address specifically from a structure entity.

Also applies to: 57-58, 69-70, 81-82

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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

@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)
client/apps/game/src/ui/modules/navigation/secondary-menu-items.tsx (1)

120-135: Consider UI/UX improvements for the bridge functionality.

The implementation for the "Bridge Lords & Resources" button looks good functionally, but there are a few points to consider:

  1. The absolute positioning (absolute top-12 right-0) may cause layout issues if the parent container's position isn't set appropriately.
  2. The pattern of wrapping a button inside an anchor tag is not conventional and could be confusing from a usability perspective.

Consider refactoring to either:

- <a
-   className="text-brown cursor-pointer text-lg w-full"
-   href={`https://empire.realms.world/trade`}
-   target="_blank"
-   rel="noopener noreferrer"
- >
-   <Button variant="secondary" className="w-full">
-     <div className="flex items-center gap-2">
-       <ResourceIcon resource="Lords" size="xs" />
-       Bridge Lords & Resources
-     </div>
-   </Button>
-   </a>

+ <Button 
+   variant="secondary" 
+   className="w-full"
+   onClick={() => window.open("https://empire.realms.world/trade", "_blank", "noopener,noreferrer")}
+ >
+   <div className="flex items-center gap-2">
+     <ResourceIcon resource="Lords" size="xs" />
+     Bridge Lords & Resources
+   </div>
+ </Button>

Or if the anchor tag is preferred for SEO or other reasons:

- <a
-   className="text-brown cursor-pointer text-lg w-full"
-   href={`https://empire.realms.world/trade`}
-   target="_blank"
-   rel="noopener noreferrer"
- >
-   <Button variant="secondary" className="w-full">
-     <div className="flex items-center gap-2">
-       <ResourceIcon resource="Lords" size="xs" />
-       Bridge Lords & Resources
-     </div>
-   </Button>
-   </a>

+ <a
+   className="text-brown cursor-pointer text-lg w-full no-underline" 
+   href="https://empire.realms.world/trade"
+   target="_blank"
+   rel="noopener noreferrer"
+   style={{ display: 'block' }}
+ >
+   <div className="flex items-center gap-2 p-2 bg-secondary rounded">
+     <ResourceIcon resource="Lords" size="xs" />
+     Bridge Lords & Resources
+   </div>
+ </a>
client/apps/game/src/ui/elements/view-on-map-icon.tsx (1)

1-41: Well-structured component extracted into its own file.

The ViewOnMapIcon component has been properly extracted into its own file, improving code organization and reusability across the application.

However, there's a potential naming issue with the imported SVG component:

-import { ReactComponent as Map } from "@/assets/icons/common/world.svg";
+import { ReactComponent as WorldIcon } from "@/assets/icons/common/world.svg";

And then update the usage:

-    <Map
+    <WorldIcon

Renaming the imported SVG component from Map to something like WorldIcon would avoid shadowing the global Map object, which is a built-in JavaScript constructor.

🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: Do not shadow the global "Map" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8455532 and 1acd95e.

📒 Files selected for processing (18)
  • client/apps/game/src/ui/components/military/army-chip.tsx (2 hunks)
  • client/apps/game/src/ui/components/military/army-management-card.tsx (3 hunks)
  • client/apps/game/src/ui/components/trading/market-header.tsx (1 hunks)
  • client/apps/game/src/ui/elements/view-on-map-icon.tsx (1 hunks)
  • client/apps/game/src/ui/modules/chat/chat.tsx (2 hunks)
  • client/apps/game/src/ui/modules/navigation/left-navigation-module.tsx (0 hunks)
  • client/apps/game/src/ui/modules/navigation/right-navigation-module.tsx (0 hunks)
  • client/apps/game/src/ui/modules/navigation/secondary-menu-items.tsx (3 hunks)
  • client/apps/game/src/ui/modules/navigation/top-left-navigation.tsx (1 hunks)
  • client/apps/game/src/ui/modules/social/player-id.tsx (1 hunks)
  • client/apps/game/src/ui/modules/stream/event-stream.tsx (4 hunks)
  • client/apps/game/src/ui/modules/world-structures/world-structures-menu.tsx (1 hunks)
  • client/apps/game/src/ui/utils/utils.ts (1 hunks)
  • client/update-policies.js (0 hunks)
  • config/environments/utils/building.ts (1 hunks)
  • packages/core/src/managers/army-manager.ts (1 hunks)
  • packages/core/src/utils/army.ts (2 hunks)
  • packages/core/src/utils/utils.ts (1 hunks)
💤 Files with no reviewable changes (3)
  • client/apps/game/src/ui/modules/navigation/right-navigation-module.tsx
  • client/apps/game/src/ui/modules/navigation/left-navigation-module.tsx
  • client/update-policies.js
🧰 Additional context used
🪛 Biome (1.9.4)
client/apps/game/src/ui/elements/view-on-map-icon.tsx

[error] 1-1: Do not shadow the global "Map" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

🔇 Additional comments (25)
client/apps/game/src/ui/modules/navigation/secondary-menu-items.tsx (2)

8-10: New imports added for UI enhancement.

The new imports for Button, ResourceIcon, and useAccount are appropriate for the functionality being added.

Also applies to: 17-17


32-32: Good use of React hook for connection status.

Using the useAccount hook to determine if a user is connected is a clean implementation that follows React best practices.

config/environments/utils/building.ts (1)

197-197:

❓ Verification inconclusive

Verify game balance impact of the significant resource cost increase

The cost of Ignium has been increased from 750 to 750,000 wheat, which represents a 1000x increase. This is a substantial change that will significantly impact resource economics and game balance.


🏁 Script executed:

#!/bin/bash
# Check if this resource cost change is consistently applied elsewhere in the codebase
# and if there are any other changes to Ignium costs or production rates

echo "Checking for other Ignium cost references:"
rg "Ignium.*amount:" --type ts -A 1 -B 1

echo "Checking for any Ignium production or balance references:"
rg "Ignium.*production|Ignium.*balance" --type ts

Length of output: 1705


Action Required: Confirm Consistency and Impact on Game Economy

The updated Ignium cost in config/environments/utils/building.ts shows an increase from 750 to 750,000 wheat—a 1000x jump. However, related Ignium values in config/environments/utils/resource.ts (e.g., amounts like 4.2, 1, 5,000) are still significantly lower. Please verify that:

  • The increased cost in the building configuration is deliberate and balanced against production/usage rates defined elsewhere.
  • There is no unintended mismatch between the building cost and the resource definitions that could disrupt the game's economy.
client/apps/game/src/ui/modules/social/player-id.tsx (1)

7-7: Import path updated following component relocation

The import path for ViewOnMapIcon has been updated to reflect its new location in the elements directory. This change is part of a larger refactoring that centralizes the ViewOnMapIcon component.

packages/core/src/utils/utils.ts (1)

118-118:

❓ Verification inconclusive

Improved precision handling with explicit floor operation

The divideByPrecision function now explicitly floors the result of the division, ensuring consistent integer outputs. This change prevents potential rounding issues when dealing with resource values.


🏁 Script executed:

#!/bin/bash
# Find all usages of divideByPrecision to verify the impact of this change

echo "Checking all usages of divideByPrecision:"
rg "divideByPrecision\(" --type ts -A 1 -B 1

echo "Checking if there are any places where non-integer values from this function might cause issues:"
rg "divideByPrecision.*(?:\.|-\>)(toFixed|toPrecision|decimal|float|fraction)" --type ts

Length of output: 31779


Precision Handling Update – Manual Verification Recommended

The changes in packages/core/src/utils/utils.ts now explicitly floor the result by returning Math.floor(value / RESOURCE_PRECISION), ensuring that all outputs from the divideByPrecision function are integers. This modification minimizes rounding issues when handling resource values.

A broad search across the codebase confirms that many files use divideByPrecision, so it’s advised to manually verify that none of these usages rely on fractional precision. Note that our automated check for potential non-integer downstream assumptions encountered a regex error. To further validate, please run or review the following corrected search command:

#!/bin/bash
echo "Re-running search for potential non-integer issues from divideByPrecision:"
rg "divideByPrecision.*(\\.|->)(toFixed|toPrecision|decimal|float|fraction)" --type ts

Once the output is verified, please confirm that no part of the system expects a floating-point value from this utility function.

client/apps/game/src/ui/modules/world-structures/world-structures-menu.tsx (1)

8-8: Import path updated following component relocation

The import path for ViewOnMapIcon has been updated to reference its new location in the elements directory, consistent with the same change in other files.

client/apps/game/src/ui/modules/navigation/top-left-navigation.tsx (1)

11-11: Updated import path for ViewOnMapIcon.

The import path for the ViewOnMapIcon component has been updated to the new location in @/ui/elements/view-on-map-icon. This change aligns with the component's relocation as part of code reorganization.

client/apps/game/src/ui/components/trading/market-header.tsx (1)

6-6: Updated import path for ViewOnMapIcon.

The import path for the ViewOnMapIcon component has been updated to the new location in @/ui/elements/view-on-map-icon. This change maintains consistency with other files that use this component.

client/apps/game/src/ui/components/military/army-chip.tsx (2)

7-8: Improved import organization for clearer dependencies.

The imports have been organized more clearly, separating the ViewOnMapIcon import from the ArmyManagementCard import. This improves code readability and better reflects the actual component dependencies.

Also applies to: 13-13


92-92: Fixed entity owner reference in ArmyManagementCard.

Updated the owner_entity prop to use army.entity_owner_id instead of army.entityId, which correctly identifies the army's owner entity. This fixes an issue related to troop management functionality.

packages/core/src/utils/army.ts (2)

43-43: Improved the home detection logic.

The code now uses a more flexible approach to determine if an army is at its home structure, checking for adjacency rather than exact position matching.


155-162: Good addition of the adjacency checking function.

This new utility function correctly determines if an army is adjacent to a structure by checking if the army's position matches any of the structure's neighboring hexes. This approach is more intuitive from a gameplay perspective and properly encapsulates this logic for reuse.

client/apps/game/src/ui/modules/stream/event-stream.tsx (4)

3-3: Import path updated for ViewOnMapIcon.

The import path has been updated to reflect the component's new location.


13-13: Added hideChat prop to component signature.

The EventStream component now accepts a hideChat boolean prop, allowing for conditional rendering based on chat visibility state.


93-94: Implemented conditional visibility for outer container.

The outermost div now properly applies visibility classes based on the hideChat prop.


119-121: Added conditional visibility and height adjustment for event list.

The event list container now adjusts its height and visibility based on the hideChat prop, ensuring proper layout responsiveness.

client/apps/game/src/ui/modules/chat/chat.tsx (2)

145-145: Added hideChat prop to EventStream component.

The hideChat state is now correctly passed to the EventStream component, connecting the Chat component's state to the EventStream's visibility.


309-309: Fixed class formatting in Messages component.

Minor formatting improvement by removing an extra space before the text-xs class.

client/apps/game/src/ui/utils/utils.ts (1)

232-232:

❓ Verification inconclusive

Simplified time formatting.

The formatArrivalTime function has been simplified to only return the time in HH:MM format, removing additional contextual information like day, month, and time remaining.

Verify that this simplification doesn't negatively impact any UI components that might depend on the additional information previously provided:


🏁 Script executed:

#!/bin/bash
# Search for usages of formatArrivalTime to ensure the simplified output is sufficient
rg -A 2 -B 2 "formatArrivalTime" --type tsx --type ts

Length of output: 81


Action: Re-verify UI Component Dependencies on Arrival Time Format

The updated formatArrivalTime function now returns only an HH:MM-formatted string. Please ensure that no UI component relies on the previously provided additional details (day, month, time remaining). The initial search using ripgrep with the tsx file type flag returned an error. To help with manual verification, please run the following updated shell script command to search across both TypeScript and TSX files:

#!/bin/bash
# Include tsx type explicitly and search for usages of formatArrivalTime
rg -A 2 -B 2 --type-add 'tsx:*.tsx' -t tsx -t ts "formatArrivalTime"

If any usages are found that expect extra information, update them accordingly.

packages/core/src/managers/army-manager.ts (3)

114-114: Good improvement to precision handling

Adding multiplyByPrecision to the troop count ensures consistent precision handling when updating explorer troops, which aligns with how the contract functions are called.


117-117: Consistent precision handling

Similar to the explorer troops update, adding multiplyByPrecision here ensures guard troops are updated with the proper precision, maintaining consistency across the codebase.


128-128:

❓ Verification inconclusive

Enhanced flexibility with homeDirection parameter

The addition of the homeDirection parameter replaces what was likely a hardcoded value (0), providing more flexibility and correctness when adding troops to an explorer army.

To verify this change addresses issue #2520:

Also applies to: 134-135


🏁 Script executed:

#!/bin/bash
# Check if there were any other locations using hardcoded direction values
rg -A 3 -B 3 "home_direction: 0" --type typescript

Length of output: 87


Verification Update: Enhanced Flexibility with homeDirection Parameter

The change in packages/core/src/managers/army-manager.ts at line 128 replaces a previously hardcoded direction value (0) with a configurable homeDirection parameter. This update improves flexibility and correctness when assembling explorer armies, and similar adjustments appear to have been applied around lines 134–135.

To ensure no other instances of a hardcoded direction remain, please run the following verification command, which now correctly targets TypeScript files:

#!/bin/bash
# Check for remaining instances of a hardcoded home_direction value in TypeScript files
rg -A 3 -B 3 "home_direction: 0" --type ts
client/apps/game/src/ui/components/military/army-management-card.tsx (3)

78-84: Good implementation for calculating homeDirection

The new code properly calculates the direction between the army's current position and its structure's base coordinates. This is crucial for correctly placing troops when reinforcing armies at home.


88-96: Improved troop addition logic

The updated condition now requires both army.isHome AND a valid homeDirection before troops can be added. This prevents potential issues where troops might be added incorrectly, and the homeDirection is now correctly passed to the addTroopsToExplorer method.


301-302: Improved display of army position

The conditional rendering now clearly indicates if the army is at base, on the map, or in an unknown location. The integration with ViewOnMapIcon provides a good user experience for locating armies.

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

🧹 Nitpick comments (1)
client/apps/game/src/ui/modules/navigation/secondary-menu-items.tsx (1)

120-133: Consider layout positioning and accessibility improvements.

The bridge button functionality looks good, but there are a few potential improvements to consider:

  1. The absolute positioning combined with fixed offset values (top-12 right-0) might cause layout issues if the parent container's dimensions change. Consider using a more flexible positioning approach.

  2. The button lacks explicit accessibility attributes like aria-label which would help screen reader users understand its purpose.

  3. The button's background color (bg-brown/90) appears to be semi-transparent, which might affect text contrast and readability depending on what's behind it.

{isConnected && (
-  <div className="absolute top-12 right-0 bg-brown/90 mx-2">
+  <div className="absolute top-12 right-0 bg-brown mx-2 z-10 rounded shadow">
    <Button
      variant="secondary"
      className="w-full"
+     aria-label="Bridge Lords and Resources to external platform"
      onClick={() => window.open("https://empire.realms.world/trade", "_blank", "noopener,noreferrer")}
    >
      <div className="flex items-center gap-2">
        <ResourceIcon resource="Lords" size="xs" />
        Bridge Lords & Resources
      </div>
    </Button>
  </div>
)}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1acd95e and 7a71b37.

📒 Files selected for processing (3)
  • client/apps/game/src/hooks/context/policies.ts (21 hunks)
  • client/apps/game/src/ui/elements/view-on-map-icon.tsx (1 hunks)
  • client/apps/game/src/ui/modules/navigation/secondary-menu-items.tsx (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • client/apps/game/src/hooks/context/policies.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/apps/game/src/ui/elements/view-on-map-icon.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test-season-pass
🔇 Additional comments (2)
client/apps/game/src/ui/modules/navigation/secondary-menu-items.tsx (2)

8-17: Clean import organization.

The newly added imports are appropriately placed in the import section and correctly align with the components being used later in the code.


32-32: Proper hook usage.

The useAccount hook is correctly implemented to retrieve the connection status, which is then used to conditionally render the bridge button.

@bob0005 bob0005 merged commit 07df2cf into next Mar 10, 2025
9 of 16 checks passed
@bob0005 bob0005 deleted the fix/various branch March 10, 2025 17:53
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.

Bridge lords and resources button should always be on screen [client] cat & event stream height
2 participants