Skip to content

Query Sellable Tiles - #273

Merged
AngeloTadeucci merged 4 commits into
masterfrom
tiles
Oct 2, 2024
Merged

Query Sellable Tiles#273
AngeloTadeucci merged 4 commits into
masterfrom
tiles

Conversation

@AngeloTadeucci

@AngeloTadeucci AngeloTadeucci commented Oct 2, 2024

Copy link
Copy Markdown
Collaborator

This pull request introduces new functionality for handling salable tiles in the game field and includes several code improvements and refactorings. The most important changes are the addition of a new FieldSalableTile entity, updates to the FieldAccelerationStructure class to support this new entity, and the addition of a debug command for querying salable tiles.

New Functionality:

  • Added FieldSalableTile entity to represent salable tiles in the game field. (Maple2.Model/Metadata/FieldEntity/FieldEntity.cs)
  • Updated FieldAccelerationStructure class to handle FieldSalableTile entities, including methods to query and write these entities. (Maple2.Model/Game/Field/FieldAccelerationStructure.cs) [1] [2] [3]

Code Improvements:

  • Added a new debug command DebugQuerySalableTileCommand to query salable tiles in the game field. (Maple2.Server.Game/Commands/DebugCommand.cs) [1] [2]

Refactorings:

  • Updated FieldEntityType enum to include SalableTile. (Maple2.Model/Metadata/FieldEntity/FieldEntity.cs)
  • Refactored entity parsing logic to include FieldSalableTile in ParseMapEntities method. (Maple2.File.Ingest/Mapper/MapDataMapper.cs)

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced support for FieldSellableTile entities, enhancing entity parsing and querying capabilities.
    • Added new methods for querying sellable tiles within specified bounds and centers.
    • Implemented a new command for debugging sellable tiles, allowing developers to query and display tile information in the game world.
  • Bug Fixes

    • Improved consistency in formatting for enum declarations.
  • Documentation

    • Refined documentation comments for clarity without altering content meaning.

@coderabbitai

coderabbitai Bot commented Oct 2, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The changes involve modifications across several classes to enhance entity handling and querying capabilities in the Maple2 game framework. The MapDataMapper class has been updated to support a new entity type, FieldSellableTile, in its parsing logic. The FieldAccelerationStructure class has introduced new querying methods for sellable tiles and updated serialization methods. The FieldEntity class now includes a new enum member and a record for FieldSellableTile. Lastly, a new debug command allows querying sellable tiles based on player position.

Changes

File Path Change Summary
Maple2.File.Ingest/Mapper/MapDataMapper.cs Reorganized using directives; added handling for IMS2CubeProp in ParseMapEntities method.
Maple2.Model/Game/Field/FieldAccelerationStructure.cs Added methods QuerySellableTiles and QuerySellableTilesCenter; updated WriteTo and ReadEntity methods for FieldSellableTile.
Maple2.Model/Metadata/FieldEntity/FieldEntity.cs Updated FieldEntityType enum to include SellableTile; added FieldSellableTile record type.
Maple2.Server.Game/Commands/DebugCommand.cs Introduced DebugQuerySellableTileCommand to query nearby sellable tiles based on player position.

Poem

In the fields where tiles do play,
New sellable friends join the fray.
With queries sharp and bounds so bright,
We hop and skip in pure delight!
Debugging now, we find our way,
In Maple2, we dance and sway! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (5)
Maple2.Model/Metadata/FieldEntity/FieldEntity.cs (1)

88-95: LGTM: New FieldSalableTile record added.

The addition of the FieldSalableTile record aligns well with the PR objectives for managing salable tiles. The inheritance from FieldEntity and the constructor pattern maintain consistency with other entity types.

Consider adding a brief XML comment to explain the purpose and usage of the SalableGroup property. For example:

/// <summary>
/// Gets or sets the group identifier for the salable tile.
/// Tiles with the same SalableGroup are considered part of the same salable unit.
/// </summary>
public int SalableGroup { get; init; }
Maple2.File.Ingest/Mapper/MapDataMapper.cs (1)

148-161: Implementation for salable tiles looks good, with some suggestions for improvement.

The new code segment correctly handles IMS2CubeProp entities and creates FieldSalableTile instances as required. However, consider the following suggestions:

  1. The bounding box size is currently hardcoded. Consider parameterizing this or deriving it from the cube properties for more flexibility.
  2. Verify that placeable.Position is the correct position for the FieldSalableTile. Depending on your game's coordinate system, you might need to adjust this (e.g., centering the tile or aligning it with the grid).

Here's a potential refactor to address these points:

 if (entity is IMS2CubeProp cube && cube.CubeSalableGroup != 0) {
-    entityBounds.Min = -new Vector3(75, 75, 0);
-    entityBounds.Max = new Vector3(75, 75, 150);
+    Vector3 tileSize = GetTileSizeFromCube(cube); // New method to determine tile size
+    entityBounds.Min = -new Vector3(tileSize.X / 2, tileSize.Y / 2, 0);
+    entityBounds.Max = new Vector3(tileSize.X / 2, tileSize.Y / 2, tileSize.Z);
+    Vector3 adjustedPosition = AdjustTilePosition(placeable.Position, tileSize); // New method to adjust position
     fieldEntity = new FieldSalableTile(
         Id: entityId,
-        Position: placeable.Position,
+        Position: adjustedPosition,
         Rotation: placeable.Rotation,
         Scale: placeable.Scale,
         Bounds: entityBounds,
         SalableGroup: cube.CubeSalableGroup
     );
     break;
 }

This refactor introduces two new methods: GetTileSizeFromCube and AdjustTilePosition. You'll need to implement these based on your game's specific requirements.

Maple2.Server.Game/Commands/DebugCommand.cs (3)

287-289: Clarify argument descriptions to reflect actual search range

The descriptions for the x, y, and z arguments state "How far along the axis to search from the player," but in the query, these values are multiplied by 2, effectively doubling the search range. Consider updating the argument descriptions to accurately reflect the actual search dimensions.


299-305: Provide user feedback when map data is unavailable

Currently, if the map metadata or map data is not found, the command returns silently without informing the user. Adding error messages will improve user experience by providing feedback when the required data is unavailable.

Apply this diff to add error messages:

if (!session.Field.MapMetadata.TryGet(session.Field.MapId, out MapMetadata? map)) {
+    ctx.Console.Error.WriteLine("Map metadata not found.");
    return;
}

if (!mapDataStorage.TryGet(map.XBlock, out FieldAccelerationStructure? mapData)) {
+    ctx.Console.Error.WriteLine("Map data not found in storage.");
    return;
}

314-317: Use consistent variable naming for clarity

Consider renaming the variable toCell to cell for consistency with other parts of the code and to enhance readability.

Apply this diff to rename the variable:

- Vector3S toCell = FieldAccelerationStructure.PointToCell(position);

...

- ctx.Console.Out.WriteLine($"SalableGroupId {salableTile.SalableGroup} found at {position.X} {position.Y} {position.Z} in cell {toCell.X} {toCell.Y} {toCell.Z}");
+ Vector3S cell = FieldAccelerationStructure.PointToCell(position);

...

+ ctx.Console.Out.WriteLine($"SalableGroupId {salableTile.SalableGroup} found at {position.X} {position.Y} {position.Z} in cell {cell.X} {cell.Y} {cell.Z}");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 926102f and 42fe0af.

📒 Files selected for processing (4)
  • Maple2.File.Ingest/Mapper/MapDataMapper.cs (2 hunks)
  • Maple2.Model/Game/Field/FieldAccelerationStructure.cs (7 hunks)
  • Maple2.Model/Metadata/FieldEntity/FieldEntity.cs (3 hunks)
  • Maple2.Server.Game/Commands/DebugCommand.cs (2 hunks)
🔇 Additional comments (10)
Maple2.Model/Metadata/FieldEntity/FieldEntity.cs (2)

1-2: LGTM: Minor change in using statement order.

The reordering of the using statements is a minor stylistic change that doesn't affect functionality. While it may align with certain coding standards, it has minimal impact on the code.


13-14: LGTM: New SalableTile enum value added.

The addition of SalableTile to the FieldEntityType enum aligns with the PR objectives for managing salable tiles. The placement after Cell maintains a logical order.

To ensure this change doesn't break existing code, please run the following script to check for potential impacts on switch statements or other enum usages:

✅ Verification successful

Verified: The SalableTile enum value is appropriately handled in existing switch statements within FieldAccelerationStructure.cs, ensuring no conflicts or issues are introduced.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential impacts of the new enum value on existing code.

# Test: Search for switch statements or direct enum value comparisons
rg --type csharp -e "switch.*FieldEntityType" -e "case.*FieldEntityType" -e "FieldEntityType\.\w+"

Length of output: 1679

Maple2.File.Ingest/Mapper/MapDataMapper.cs (1)

Line range hint 1-379: Overall, the changes align well with the PR objectives.

The implementation of salable tile handling is a good addition to the ParseMapEntities method. It integrates smoothly with the existing code structure and doesn't introduce any apparent issues to the overall functionality of the MapDataMapper class.

To further improve the code:

  1. Consider adding unit tests for the new IMS2CubeProp handling logic to ensure its correctness and prevent regressions.
  2. Update the class or method documentation to reflect the new capability of handling salable tiles.
Maple2.Server.Game/Commands/DebugCommand.cs (1)

153-153: New command added successfully

The DebugQuerySalableTileCommand has been correctly added to DebugQueryCommand.

Maple2.Model/Game/Field/FieldAccelerationStructure.cs (6)

8-9: Necessary namespaces imported for FieldSalableTile

The addition of using Maple2.Model.Metadata; and using Maple2.Model.Metadata.FieldEntity; is appropriate to support the new FieldSalableTile entity.


21-21: Consistent use of trailing commas in enum definitions

Adding a trailing comma after the last enumeration member in FieldEntityMembers improves code maintainability and simplifies future additions.


180-182: Enhanced readability with pattern matching in QueryFluids

Using property pattern matching { IsSurface: true, IsShallow: false } in the type check for FieldFluidEntity enhances the readability and conciseness of the code.


695-696: FieldSalableTile correctly associated with FieldEntityType.SalableTile

This addition ensures that FieldSalableTile entities are properly serialized with the correct entity type in the WriteTo method.


768-770: Proper serialization of SalableGroup for FieldSalableTile

The SalableGroup property is correctly written in the WriteTo method, ensuring that FieldSalableTile entities include necessary data during serialization.


946-953: Correct deserialization of FieldSalableTile entities

In the ReadEntity method, FieldSalableTile entities are properly deserialized, including the SalableGroup property, ensuring consistency with the serialization logic.

Comment thread Maple2.Server.Game/Commands/DebugCommand.cs
Comment thread Maple2.Server.Game/Commands/DebugCommand.cs
Comment thread Maple2.Model/Game/Field/FieldAccelerationStructure.cs Outdated
Comment thread Maple2.File.Ingest/Mapper/MapDataMapper.cs Outdated
Comment thread Maple2.Model/Metadata/FieldEntity/FieldEntity.cs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 42fe0af and c60732f.

📒 Files selected for processing (4)
  • Maple2.File.Ingest/Mapper/MapDataMapper.cs (2 hunks)
  • Maple2.Model/Game/Field/FieldAccelerationStructure.cs (7 hunks)
  • Maple2.Model/Metadata/FieldEntity/FieldEntity.cs (3 hunks)
  • Maple2.Server.Game/Commands/DebugCommand.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • Maple2.File.Ingest/Mapper/MapDataMapper.cs
  • Maple2.Model/Game/Field/FieldAccelerationStructure.cs
  • Maple2.Model/Metadata/FieldEntity/FieldEntity.cs
🔇 Additional comments (2)
Maple2.Server.Game/Commands/DebugCommand.cs (2)

153-153: LGTM: New command added correctly

The DebugQuerySellableTileCommand is correctly added to the DebugQueryCommand class, following the existing pattern for other query commands.


279-320: LGTM: Implementation consistent with other query commands

The DebugQuerySellableTileCommand is well-implemented and follows the structure of other query commands. It correctly uses the mapDataStorage to query sellable tiles and outputs the results in a consistent format.

Comment thread Maple2.Server.Game/Commands/DebugCommand.cs
Comment thread Maple2.Server.Game/Commands/DebugCommand.cs
@AngeloTadeucci AngeloTadeucci changed the title Query Salable Tiles Query Sellable Tiles Oct 2, 2024
@AngeloTadeucci
AngeloTadeucci merged commit 4b2d521 into master Oct 2, 2024
@AngeloTadeucci
AngeloTadeucci deleted the tiles branch October 4, 2024 17:19
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.

3 participants