BibliothecaDAO / eternum

onchain eternal game
https://alpha-eternum.realms.world
MIT License
46 stars 34 forks source link

Feat/combat raschel #926

Closed aymericdelab closed 3 months ago

aymericdelab commented 3 months ago

PR Type

enhancement, bug fix


Description


Changes walkthrough πŸ“

Relevant files
Enhancement
useArmies.tsx
Add function to fetch armies by battle ID.                             

client/src/hooks/helpers/useArmies.tsx
  • Added getArmiesByBattleId function to fetch armies by battle ID.
  • Utilized various components and account information in the new
    function.
  • +42/-0   
    types.ts
    Update BattleViewInfo type for multiple attackers and defenders.

    client/src/hooks/store/types.ts
  • Updated BattleViewInfo type to include attackers and defenders arrays.

  • +2/-2     
    useUIStore.tsx
    Modify setBattleView for multiple attackers and defenders.

    client/src/hooks/store/useUIStore.tsx
  • Modified setBattleView to handle multiple attackers and defenders.
  • +4/-4     
    StructureCard.tsx
    Update setBattleView call in StructureCard component.       

    client/src/ui/components/hyperstructures/StructureCard.tsx
  • Updated setBattleView call to use new attackers and defenders
    structure.
  • +2/-2     
    Battle.tsx
    Update setBattleView call in Battle component.                     

    client/src/ui/components/military/Battle.tsx
  • Updated setBattleView call to use new attackers and defenders
    structure.
  • +2/-2     
    Battles.tsx
    Clean up and pass selectedBattle to BattleLabel.                 

    client/src/ui/components/models/buildings/worldmap/Battles.tsx
  • Removed console log for selectedBattle.
  • Passed selectedBattle to BattleLabel component.
  • +1/-5     
    BattleLabel.tsx
    Implement battle view logic in BattleLabel component.       

    client/src/ui/components/worldmap/armies/BattleLabel.tsx
  • Imported getArmiesByBattleId and other necessary hooks.
  • Implemented logic to filter and set battle view for attackers and
    defenders.
  • +23/-14 
    BattleView.tsx
    Update getArmiesAndStructure for new battle view structure.

    client/src/ui/modules/military/battle-view/BattleView.tsx
  • Updated getArmiesAndStructure to handle new attackers and defenders
    structure.
  • +6/-6     

    πŸ’‘ PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    vercel[bot] commented 3 months ago

    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 Jun 13, 2024 3:27pm
    github-actions[bot] commented 3 months ago

    PR Reviewer Guide πŸ”

    ⏱️ Estimated effort to review [1-5] 3
    πŸ§ͺ Relevant tests No
    πŸ”’ Security concerns No
    ⚑ Key issues to review Possible Bug:
    The `getArmiesByBattleId` function in `useArmies.tsx` does not handle the case where `armiesEntityIds` is empty or null. This could lead to runtime errors when trying to format armies with an undefined or null input.
    Data Handling Concern:
    The `getArmiesByBattleId` function uses a destructuring approach to extract a large number of components and account information, which might not be efficient or necessary for all calls. Consider optimizing this to only extract needed data.
    Consistency Issue:
    The `BattleView` component's logic for handling different types of defenders (Army vs. Structure) seems to be inconsistent and could lead to errors if not handled properly.
    github-actions[bot] commented 3 months ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Add optional chaining to safely access properties ___ **Use optional chaining to safely access properties of potentially undefined objects to
    prevent runtime errors.** [client/src/hooks/helpers/useArmies.tsx [232-249]](https://github.com/BibliothecaDAO/eternum/pull/926/files#diff-6d68c14fbe3262def9a16f121115d2006c7c34bf942b3e5d8ed7c076d2b89027R232-R249) ```diff const armiesEntityIds = runQuery([HasValue(Army, { battle_id })]); return formatArmies( - Array.from(armiesEntityIds), - account.address, + Array.from(armiesEntityIds ?? []), + account?.address, Army, Protectee, EntityName, Health, Quantity, Movable, Capacity, ArrivalTime, Position, EntityOwner, Owner, Realm, Stamina, ); ```
    Suggestion importance[1-10]: 9 Why: Adding optional chaining is a significant improvement as it prevents potential runtime errors when accessing properties of possibly undefined objects. This enhances the robustness of the code.
    9
    Maintainability
    Simplify object destructuring for better readability ___ **Consider destructuring the components object directly in the function parameter to
    simplify the code and improve readability.** [client/src/hooks/helpers/useArmies.tsx [210-230]](https://github.com/BibliothecaDAO/eternum/pull/926/files#diff-6d68c14fbe3262def9a16f121115d2006c7c34bf942b3e5d8ed7c076d2b89027R210-R230) ```diff const { - setup: { - components: { - Position, - EntityOwner, - Owner, - Health, - Quantity, - Movable, - Capacity, - ArrivalTime, - Realm, - Army, - Protectee, - EntityName, - Stamina, - }, - }, + setup: { components }, account: { account }, } = useDojo(); +const { + Position, + EntityOwner, + Owner, + Health, + Quantity, + Movable, + Capacity, + ArrivalTime, + Realm, + Army, + Protectee, + EntityName, + Stamina, +} = components; ```
    Suggestion importance[1-10]: 7 Why: This suggestion improves code readability and maintainability by simplifying the destructuring process. However, it does not address any critical issues or bugs.
    7
    Standardize the order of union types for consistency ___ **Ensure consistent ordering of the types in the union for defenders to maintain uniformity
    across different parts of the codebase.** [client/src/hooks/store/useUIStore.tsx [199]](https://github.com/BibliothecaDAO/eternum/pull/926/files#diff-6be3d49574f69bf63b036da26eaba9e59f4ccca6b393ee685ca020398c8465c5R199-R199) ```diff -defenders: { type: CombatTarget; entities: FullStructure | ArmyInfo[] }; +defenders: { type: CombatTarget; entities: ArmyInfo[] | FullStructure }; ```
    Suggestion importance[1-10]: 6 Why: Standardizing the order of union types improves code consistency and readability. However, this change is minor and does not impact functionality or fix any bugs.
    6