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

V1 #1125

Merged
merged 47 commits into from
Aug 1, 2024
Merged

V1 #1125

merged 47 commits into from
Aug 1, 2024

Conversation

credence0x
Copy link
Collaborator

@credence0x credence0x commented Jul 23, 2024

PR Type

Enhancement, Bug fix, Tests


Description

  • Added delete_army method and related functionality to the EternumProvider and system calls.
  • Updated setCombatConfig and set_troop_config to include new parameters.
  • Added new global configuration constants.
  • Implemented ArmyQuantityTracker and updated various combat models and traits to custom versions.
  • Added army_delete function to ICombatContract and implemented logic for deleting armies.
  • Updated building models and traits to custom versions.
  • Refactored various configuration systems to use custom implementations and updated function signatures.
  • Refactored resource transfer system tests for clarity and updated test setup and assertions.
  • Fixed bug in health deduction logic in combat models.

Changes walkthrough 📝

Relevant files
Enhancement
10 files
index.ts
Add delete army method and update troop config                     

sdk/packages/eternum/src/provider/index.ts

  • Added delete_army method to EternumProvider.
  • Updated set_troop_config method to include new parameters.
  • +14/-0   
    index.ts
    Update setCombatConfig with new parameters                             

    sdk/packages/eternum/src/config/index.ts

    • Updated setCombatConfig to include new parameters.
    +4/-0     
    createSystemCalls.ts
    Add delete army function to system calls                                 

    client/src/dojo/createSystemCalls.ts

    • Added delete_army function to system calls.
    +5/-0     
    provider.ts
    Add ArmyDeleteProps interface and update SetTroopConfigProps

    sdk/packages/eternum/src/types/provider.ts

  • Added ArmyDeleteProps interface.
  • Added new properties to SetTroopConfigProps.
  • +6/-0     
    global.ts
    Add new global configuration constants                                     

    sdk/packages/eternum/src/constants/global.ts

    • Added new global configuration constants.
    +2/-0     
    combat.cairo
    Add ArmyQuantityTracker and update combat models                 

    contracts/src/models/combat.cairo

  • Added ArmyQuantityTracker implementation.
  • Updated various traits and implementations to custom versions.
  • Fixed bug in health deduction logic.
  • Added debug and partial equality derivations to structs.
  • +128/-228
    contracts.cairo
    Add army delete function and update combat system               

    contracts/src/systems/combat/contracts.cairo

  • Added army_delete function to ICombatContract.
  • Updated army_create and army_buy_troops functions.
  • Implemented logic for deleting armies.
  • +214/-159
    buildings.cairo
    Update building models and traits                                               

    contracts/src/models/buildings.cairo

  • Updated building models and traits to custom versions.
  • Added debug and introspect derivations to enums.
  • +64/-159
    contracts.cairo
    Update configuration systems to custom implementations     

    contracts/src/systems/config/contracts.cairo

  • Updated various configuration systems to custom implementations.
  • Refactored function signatures for consistency.
  • +53/-132
    quantity.cairo
    Add QuantityTrackerType and update Quantity implementation

    contracts/src/models/quantity.cairo

  • Added QuantityTrackerType module.
  • Updated Quantity implementation to custom version.
  • +4/-1     
    Configuration changes
    2 files
    deploy.sh
    Update deployment script for new version                                 

    scripts/deploy.sh

    • Updated deployment script to use new version.
    +2/-2     
    contracts.sh
    Update block time in katana command                                           

    scripts/contracts.sh

    • Updated block time in katana command.
    +1/-1     
    Tests
    1 files
    resource_transfer_system_tests.cairo
    Refactor resource transfer system tests                                   

    contracts/src/systems/resources/tests/resource_transfer_system_tests.cairo

  • Refactored resource transfer system tests for clarity.
  • Updated test setup and assertions.
  • +28/-96 
    Additional files (token-limit)
    71 files
    pnpm-lock.yaml
    ...                                                                                                           

    pnpm-lock.yaml

    ...

    +1/-17741
    liquidity.cairo
    ...                                                                                                           

    contracts/src/systems/bank/tests/liquidity.cairo

    ...

    +45/-93 
    battle_leave_test.cairo
    ...                                                                                                           

    contracts/src/systems/combat/tests/battle_leave_test.cairo

    ...

    +317/-0 
    travel_systems_tests.cairo
    ...                                                                                                           

    contracts/src/systems/transport/tests/travel_systems_tests.cairo

    ...

    +31/-127
    battle_start_test.cairo
    ...                                                                                                           

    contracts/src/systems/combat/tests/battle_start_test.cairo

    ...

    +270/-0 
    swap.cairo
    ...                                                                                                           

    contracts/src/systems/bank/tests/swap.cairo

    ...

    +37/-61 
    manifest.json
    ...                                                                                                           

    contracts/manifests/dev/manifest.json

    ...

    +64/-26 
    tests.cairo
    ...                                                                                                           

    contracts/src/systems/hyperstructure/tests.cairo

    ...

    +30/-103
    resources.cairo
    ...                                                                                                           

    contracts/src/models/resources.cairo

    ...

    +27/-39 
    contracts.cairo
    ...                                                                                                           

    contracts/src/systems/resources/contracts.cairo

    ...

    +30/-94 
    contracts.cairo
    ...                                                                                                           

    contracts/src/systems/hyperstructure/contracts.cairo

    ...

    +30/-81 
    army_create_test.cairo
    ...                                                                                                           

    contracts/src/systems/combat/tests/army_create_test.cairo

    ...

    +177/-0 
    tests.cairo
    ...                                                                                                           

    contracts/src/systems/guild/tests.cairo

    ...

    +19/-40 
    travel_systems.cairo
    ...                                                                                                           

    contracts/src/systems/transport/contracts/travel_systems.cairo

    ...

    +23/-53 
    contracts.cairo
    ...                                                                                                           

    contracts/src/systems/map/contracts.cairo

    ...

    +22/-42 
    manifest.toml
    ...                                                                                                           

    contracts/manifests/dev/manifest.toml

    ...

    +19/-9   
    trade_systems.cairo
    ...                                                                                                           

    contracts/src/systems/trade/contracts/trade_systems.cairo

    ...

    +19/-50 
    army_buy_test.cairo
    ...                                                                                                           

    contracts/src/systems/combat/tests/army_buy_test.cairo

    ...

    +133/-0 
    production.cairo
    ...                                                                                                           

    contracts/src/models/production.cairo

    ...

    +16/-38 
    contracts.cairo
    ...                                                                                                           

    contracts/src/systems/guild/contracts.cairo

    ...

    +18/-51 
    swap.cairo
    ...                                                                                                           

    contracts/src/systems/bank/contracts/swap.cairo

    ...

    +14/-38 
    world.cairo
    ...                                                                                                           

    contracts/src/utils/testing/world.cairo

    ...

    +84/-6   
    level.cairo
    ...                                                                                                           

    contracts/src/models/level.cairo

    ...

    +14/-26 
    config.cairo
    ...                                                                                                           

    contracts/src/utils/testing/config.cairo

    ...

    +18/-28 
    manifest.json
    ...                                                                                                           

    contracts/manifests/prod/manifest.json

    ...

    +17/-17 
    accept_order.cairo
    ...                                                                                                           

    contracts/src/systems/trade/tests/trade_systems_tests/accept_order.cairo

    ...

    +15/-40 
    resource_approval_system_tests.cairo
    ...                                                                                                           

    contracts/src/systems/resources/tests/resource_approval_system_tests.cairo

    ...

    +18/-68 
    market.cairo
    ...                                                                                                           

    contracts/src/models/bank/market.cairo

    ...

    +14/-38 
    liquidity.cairo
    ...                                                                                                           

    contracts/src/systems/bank/contracts/liquidity.cairo

    ...

    +12/-34 
    tests.cairo
    ...                                                                                                           

    contracts/src/systems/map/tests.cairo

    ...

    +12/-30 
    create_order.cairo
    ...                                                                                                           

    contracts/src/systems/trade/tests/trade_systems_tests/create_order.cairo

    ...

    +13/-29 
    bank.cairo
    ...                                                                                                           

    contracts/src/systems/bank/contracts/bank.cairo

    ...

    +10/-35 
    cancel_order.cairo
    ...                                                                                                           

    contracts/src/systems/trade/tests/trade_systems_tests/cancel_order.cairo

    ...

    +12/-36 
    tests.cairo
    ...                                                                                                           

    contracts/src/systems/combat/tests.cairo

    ...

    +4/-103 
    donkey_systems.cairo
    ...                                                                                                           

    contracts/src/systems/transport/contracts/donkey_systems.cairo

    ...

    +15/-24 
    config.cairo
    ...                                                                                                           

    contracts/src/models/config.cairo

    ...

    +17/-16 
    position.cairo
    ...                                                                                                           

    contracts/src/models/position.cairo

    ...

    +10/-17 
    contracts.cairo
    ...                                                                                                           

    contracts/src/systems/realm/contracts.cairo

    ...

    +10/-25 
    road_systems_tests.cairo
    ...                                                                                                           

    contracts/src/systems/transport/tests/road_systems_tests.cairo

    ...

    +10/-27 
    realm_leveling_tests.cairo
    ...                                                                                                           

    contracts/src/systems/leveling/tests/realm_leveling_tests.cairo

    ...

    +7/-19   
    tests.cairo
    ...                                                                                                           

    contracts/src/systems/realm/tests.cairo

    ...

    +8/-22   
    contracts.cairo
    ...                                                                                                           

    contracts/src/systems/leveling/contracts.cairo

    ...

    +9/-17   
    systems.cairo
    ...                                                                                                           

    contracts/src/utils/testing/systems.cairo

    ...

    +8/-19   
    stamina.cairo
    ...                                                                                                           

    contracts/src/models/stamina.cairo

    ...

    +7/-13   
    Scarb.toml
    ...                                                                                                           

    contracts/Scarb.toml

    ...

    +7/-3     
    internal_leveling_tests.cairo
    ...                                                                                                           

    contracts/src/systems/leveling/tests/internal_leveling_tests.cairo

    ...

    +6/-19   
    road_systems.cairo
    ...                                                                                                           

    contracts/src/systems/transport/contracts/road_systems.cairo

    ...

    +7/-18   
    contracts.cairo
    ...                                                                                                           

    contracts/src/systems/buildings/contracts.cairo

    ...

    +8/-12   
    road.cairo
    ...                                                                                                           

    contracts/src/models/road.cairo

    ...

    +5/-7     
    general.cairo
    ...                                                                                                           

    contracts/src/utils/testing/general.cairo

    ...

    +19/-6   
    bank.cairo
    ...                                                                                                           

    contracts/src/systems/dev/contracts/bank.cairo

    ...

    +3/-10   
    random.cairo
    ...                                                                                                           

    contracts/src/utils/random.cairo

    ...

    +3/-10   
    test-contracts.yml
    ...                                                                                                           

    .github/workflows/test-contracts.yml

    ...

    +3/-7     
    owner.cairo
    ...                                                                                                           

    contracts/src/models/owner.cairo

    ...

    +4/-4     
    hyperstructure_config_tests.cairo
    ...                                                                                                           

    contracts/src/systems/config/tests/hyperstructure_config_tests.cairo

    ...

    +3/-5     
    constants.cairo
    ...                                                                                                           

    contracts/src/constants.cairo

    ...

    +1/-4     
    resource.cairo
    ...                                                                                                           

    contracts/src/systems/dev/contracts/resource.cairo

    ...

    +2/-2     
    vrgda.cairo
    ...                                                                                                           

    contracts/src/utils/vrgda.cairo

    ...

    +2/-4     
    math.cairo
    ...                                                                                                           

    contracts/src/utils/math.cairo

    ...

    +2/-6     
    structure.cairo
    ...                                                                                                           

    contracts/src/models/structure.cairo

    ...

    +3/-3     
    movable.cairo
    ...                                                                                                           

    contracts/src/models/movable.cairo

    ...

    +2/-2     
    realm.cairo
    ...                                                                                                           

    contracts/src/models/realm.cairo

    ...

    +3/-5     
    guild.cairo
    ...                                                                                                           

    contracts/src/models/guild.cairo

    ...

    +2/-2     
    contracts.mdx
    ...                                                                                                           

    eternum-docs/docs/pages/development/contracts.mdx

    ...

    +3/-3     
    weight.cairo
    ...                                                                                                           

    contracts/src/models/weight.cairo

    ...

    +2/-2     
    capacity.cairo
    ...                                                                                                           

    contracts/src/models/capacity.cairo

    ...

    +2/-2     
    contracts.cairo
    ...                                                                                                           

    contracts/src/systems/name/contracts.cairo

    ...

    +1/-1     
    population.cairo
    ...                                                                                                           

    contracts/src/models/population.cairo

    ...

    +1/-1     
    order.cairo
    ...                                                                                                           

    contracts/src/models/order.cairo

    ...

    +1/-1     
    .tool-versions
    ...                                                                                                           

    .tool-versions

    ...

    +1/-1     
    system_models.json
    ...                                                                                                           

    contracts/scripts/system_models.json

    ...

    +1/-0     

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

    Copy link

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 No relevant tests
    🔒 Security concerns

    No specific security vulnerabilities such as SQL injections, XSS, CSRF, etc., are introduced in this PR. However, the lack of validation in the delete_army functions could lead to unauthorized or unintended deletions, which is a security concern in terms of data integrity and application stability.

    ⚡ Key issues to review

    Possible Bug
    The delete_army method in EternumProvider does not check if the army is a defensive army or if it is alive before deletion. This could lead to unintended behavior where important armies could be deleted or armies could be deleted while still active.

    Security Concern
    The army_delete function in ICombatContract does not perform checks to ensure that the army is not a defensive army and is actually dead before allowing deletion. This could lead to potential misuse where armies could be deleted incorrectly.

    Incomplete Implementation
    The delete_army function in CombatContractImpl does not handle the cleanup of all related entities and states associated with the army, such as removing the army's resources, updating related counters, or cleaning up any pending operations that involve the army.

    Copy link

    github-actions bot commented Jul 23, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Add error handling to the delete_army method

    Consider adding error handling for the delete_army method to manage exceptions or
    failed transactions gracefully.

    sdk/packages/eternum/src/provider/index.ts [483-491]

     public async delete_army(props: SystemProps.ArmyDeleteProps) {
         const { army_id, signer } = props;
    -    return await this.executeAndCheckTransaction(signer, {
    -        contractAddress: getContractByName(this.manifest, "combat_systems"),
    -        entrypoint: "army_delete",
    -        calldata: [army_id],
    -    });
    +    try {
    +        return await this.executeAndCheckTransaction(signer, {
    +            contractAddress: getContractByName(this.manifest, "combat_systems"),
    +            entrypoint: "army_delete",
    +            calldata: [army_id],
    +        });
    +    } catch (error) {
    +        console.error('Failed to delete army:', error);
    +        throw error;
    +    }
     }
     
    Suggestion importance[1-10]: 9

    Why: Adding error handling is crucial for managing exceptions or failed transactions gracefully, which improves the robustness and reliability of the method.

    9
    Ensure consistent use of the new trait implementation in method calls

    Refactor the method calls to use the new trait implementation consistently across
    all method invocations.

    contracts/src/models/bank/market.cairo [98-100]

    -let lords_cost = Self::get_output_price(
    +let lords_cost = MarketCustomImpl::get_output_price(
         lp_fee_num, lp_fee_denom, desired_resource_amount, *self.lords_amount, *self.resource_amount
     );
     
    Suggestion importance[1-10]: 7

    Why: Ensuring consistent use of the new trait implementation is a good practice and can prevent potential confusion or errors in the future.

    7
    Ensure the new configuration fields are properly validated and do not conflict with existing settings

    Review and possibly refactor the addition of the army_free_per_structure and
    army_extra_per_building fields to ensure they align with the system's overall
    configuration and do not introduce redundancy or conflicts with existing
    configurations.

    contracts/manifests/dev/manifest.json [2842-2848]

     {
       "name": "army_free_per_structure",
    -  "type": "core::integer::u8"
    +  "type": "core::integer::u8",
    +  "validation": "check_value_range(army_free_per_structure, 0, 10)"
     },
     {
       "name": "army_extra_per_building",
    -  "type": "core::integer::u8"
    +  "type": "core::integer::u8",
    +  "validation": "check_value_range(army_extra_per_building, 0, 5)"
     }
     
    Suggestion importance[1-10]: 6

    Why: Adding validation for the new fields army_free_per_structure and army_extra_per_building is a good practice to ensure data integrity and avoid conflicts. However, the specific validation logic may need further refinement.

    6
    Verify and potentially adjust the order of new array elements to maintain logical consistency

    Consider maintaining the order of elements in the array to ensure consistent data
    handling and potentially prevent issues related to data processing order.

    contracts/scripts/system_models.json [186]

    -"QuantityTracker",
    +"QuantityTracker",  # Ensure this new element's position is intentional and does not disrupt existing order-dependent logic.
     
    Suggestion importance[1-10]: 6

    Why: While maintaining the order of elements is a good practice, the suggestion does not address a critical issue and is more of a precautionary measure.

    6
    Possible bug
    Add validation for non-zero denominators to prevent runtime errors

    Ensure that the input parameters are validated for non-zero values before performing
    calculations to prevent division by zero errors.

    contracts/src/models/bank/market.cairo [58]

    +assert(fee_rate_denom != 0, 'fee_rate_denom must be > zero');
     let input_amount_after_fee = (input_amount * (fee_rate_denom - fee_rate_num)) / fee_rate_denom;
     
    Suggestion importance[1-10]: 9

    Why: Adding validation for non-zero denominators is crucial to prevent runtime errors, which can lead to application crashes or unexpected behavior.

    9
    Add error handling for data retrieval to prevent runtime failures

    Implement error handling for the get! macro to manage cases where the requested data
    might not be available in the world state, which could lead to runtime errors.

    contracts/src/models/buildings.cairo [177]

    -let production_config: ProductionConfig = get!(world, produced_resource_type, ProductionConfig);
    +let production_config: ProductionConfig = try_get!(world, produced_resource_type, ProductionConfig)?;
     
    Suggestion importance[1-10]: 8

    Why: Implementing error handling for the get! macro is crucial for preventing runtime errors when the requested data is unavailable, enhancing the overall stability of the code.

    8
    Add a safe method to handle potential null or default tick configurations

    Replace the direct use of TickImpl::get_default_tick_config with a method that
    checks for null or default values to prevent runtime errors when the configuration
    is not set.

    contracts/src/models/buildings.cairo [157]

    -let tick = TickImpl::get_default_tick_config(world);
    +let tick = safe_get_default_tick_config(world);
     
    Suggestion importance[1-10]: 7

    Why: This suggestion improves robustness by preventing potential runtime errors due to null or default values, but it requires the implementation of the safe_get_default_tick_config method, which is not trivial.

    7
    Maintainability
    Simplify the array initialization with repeated values

    Consider using a loop or a more concise method to initialize the array with repeated
    values to improve readability and maintainability.

    contracts/src/constants.cairo [245]

    -return array![1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].span();
    +return [1; 30].span();  # Assuming Cairo supports this syntax or similar for array initialization
     
    Suggestion importance[1-10]: 8

    Why: The suggestion improves code readability and maintainability by using a more concise method for array initialization, assuming the syntax is supported by Cairo.

    8
    Rename variables to maintain consistent camelCase naming conventions

    Ensure consistency in naming conventions by renaming army_free_per_structure and
    army_extra_per_military_building to match the camelCase format used in other parts
    of the code.

    sdk/packages/eternum/src/config/index.ts [167-168]

    -army_free_per_structure: army_free_per_structure,
    -army_extra_per_military_building: army_extra_per_military_building,
    +armyFreePerStructure: army_free_per_structure,
    +armyExtraPerMilitaryBuilding: army_extra_per_military_building,
     
    Suggestion importance[1-10]: 7

    Why: Ensuring consistency in naming conventions improves code readability and maintainability, although it is a minor change.

    7
    Refactor repetitive resource handling code into a separate function for better clarity

    Refactor the loop for handling resource consumption to a separate function to
    improve code readability and maintainability.

    contracts/src/models/buildings.cairo [179-196]

    -loop {
    -    if count == production_config.input_count {
    -        break;
    -    }
    -    let production_input: ProductionInput = get!(world, (produced_resource_type, count), ProductionInput);
    -    let (input_resource_type, input_resource_amount) = (
    -        production_input.input_resource_type, production_input.input_resource_amount
    -    );
    -    let mut input_resource: Resource = ResourceCustomImpl::get(
    -        world, (self.outer_entity_id, input_resource_type)
    -    );
    -    let mut input_production: Production = get!(
    -        world, (self.outer_entity_id, input_resource_type), Production
    -    );
    -    input_production.increase_consumption_rate(ref input_resource, @tick, input_resource_amount);
    -    count += 1;
    -    input_resource.save(world);
    -    set!(world, (input_production));
    -}
    +handle_resource_consumption(world, production_config, produced_resource_type, self.outer_entity_id, @tick);
     
    Suggestion importance[1-10]: 6

    Why: Refactoring the loop into a separate function improves code readability and maintainability, but it does not address any critical issues.

    6
    Robustness
    Add fallback values for new configuration properties to ensure robustness

    Consider adding a default value or a fallback mechanism for new configuration
    properties armyFreePerStructure and armyExtraPerMilitaryBuilding to handle cases
    where they might not be set.

    sdk/packages/eternum/src/constants/global.ts [67-68]

    -armyFreePerStructure: 3,
    -armyExtraPerMilitaryBuilding: 2,
    +armyFreePerStructure: EternumGlobalConfig.troop.armyFreePerStructure || 3,
    +armyExtraPerMilitaryBuilding: EternumGlobalConfig.troop.armyExtraPerMilitaryBuilding || 2,
     
    Suggestion importance[1-10]: 8

    Why: Adding default values or fallback mechanisms for new configuration properties ensures that the system remains robust even if these properties are not set.

    8
    Possible issue
    Update the class_hash and original_class_hash to unique values to ensure correct deployment tracking

    Ensure that the class_hash and original_class_hash values are unique and correctly
    represent the new deployment to avoid conflicts or incorrect linkage in the
    contract's deployment history.

    contracts/manifests/dev/manifest.json [1979-1980]

    -"class_hash": "0x5e7fa715b0a5f674e5de150580bc2e5ee77f82d5d6f8501a091c261b7680cfb",
    -"original_class_hash": "0x5e7fa715b0a5f674e5de150580bc2e5ee77f82d5d6f8501a091c261b7680cfb",
    +"class_hash": "0x[new_unique_hash]",
    +"original_class_hash": "0x[previous_unique_hash]",
     
    Suggestion importance[1-10]: 8

    Why: Ensuring that class_hash and original_class_hash values are unique is crucial for avoiding conflicts and maintaining accurate deployment records. This suggestion addresses a potential issue in the PR.

    8
    Enhancement
    Implement validation checks for army_id in the army_delete function to ensure robust error handling

    Add error handling or validation checks for the new army_delete function to ensure
    that the input army_id is valid and exists before performing deletion operations.

    contracts/manifests/dev/manifest.json [2116-2127]

     {
       "type": "function",
       "name": "army_delete",
       "inputs": [
         {
           "name": "army_id",
           "type": "core::integer::u128"
         }
       ],
       "outputs": [],
    -  "state_mutability": "external"
    +  "state_mutability": "external",
    +  "preconditions": [
    +    "validate_army_id_exists(army_id)"
    +  ]
     }
     
    Suggestion importance[1-10]: 7

    Why: Adding validation checks for army_id in the army_delete function improves robustness and error handling, although the exact implementation may vary. This suggestion enhances the functionality.

    7
    Use a constant array for directions to improve readability and maintainability

    Use a constant for the direction values in get_bonus_from method to avoid magic
    numbers and improve code readability.

    contracts/src/models/buildings.cairo [326-331]

    -let mut bonus_percent = self.get_bonus_from(building_coord.neighbor(Direction::East), world);
    -bonus_percent += self.get_bonus_from(building_coord.neighbor(Direction::NorthEast), world);
    -bonus_percent += self.get_bonus_from(building_coord.neighbor(Direction::NorthWest), world);
    -bonus_percent += self.get_bonus_from(building_coord.neighbor(Direction::West), world);
    -bonus_percent += self.get_bonus_from(building_coord.neighbor(Direction::SouthWest), world);
    -bonus_percent += self.get_bonus_from(building_coord.neighbor(Direction::SouthEast), world);
    +let directions = [Direction::East, Direction::NorthEast, Direction::NorthWest, Direction::West, Direction::SouthWest, Direction::SouthEast];
    +let mut bonus_percent = 0;
    +for direction in directions.iter() {
    +    bonus_percent += self.get_bonus_from(building_coord.neighbor(*direction), world);
    +}
     
    Suggestion importance[1-10]: 5

    Why: Using a constant array for directions enhances code readability and maintainability, but the improvement is relatively minor and does not address any functional issues.

    5
    Documentation
    Add documentation for the ArmyDeleteProps interface

    Add type documentation for the new ArmyDeleteProps interface to clarify the purpose
    and usage of its properties.

    sdk/packages/eternum/src/types/provider.ts [271-273]

    +/**
    + * Properties required to delete an army.
    + * @param army_id The identifier of the army to be deleted.
    + */
     export interface ArmyDeleteProps extends SystemSigner {
         army_id: num.BigNumberish;
     }
     
    Suggestion importance[1-10]: 6

    Why: Adding type documentation helps clarify the purpose and usage of properties, which is beneficial for future developers, though it is not critical.

    6

    * Clean legacy code + remove unused exports
    
    * add knip command
    
    * more cleaning
    
    * prettier
    
    * Cleanup + add knip CI
    
    * fix build
    
    * fix knip
    
    * rebase main
    
    * prettier
    
    * fix knip ci
    
    * resolve comments
    * Change to V1 + add type aliases for entity ids
    
    * Make elements clickable under right and left navigation modules buttons + fix z-index of quests, guilds and leaderboard
    
    * scarb fmt
    
    * Change bonus_percent to u32 instead of u128
    
    * Address minor PR comments
    
    * prettier
    
    * knip
    @edisontim edisontim merged commit 47e99b2 into main Aug 1, 2024
    20 of 21 checks passed
    @edisontim edisontim deleted the v1 branch August 1, 2024 12:14
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    4 participants