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: readme + phaser recs example #287

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

MartianGreed
Copy link
Collaborator

@MartianGreed MartianGreed commented Oct 3, 2024

Summary by CodeRabbit

  • New Features

    • Added instructions for using the Dojo framework, including setup and migration guidance in the README.
    • Introduced asynchronous movement commands in the game scene for improved input handling.
  • Bug Fixes

    • Updated package manager commands in the Torii Bot README to reflect the switch from bun to pnpm.
  • Documentation

    • Enhanced README with detailed steps for running examples and troubleshooting migration issues.

Copy link

coderabbitai bot commented Oct 3, 2024

Walkthrough

The pull request introduces a new entry for the submodule "worlds/dojo-starter" in the .gitmodules file, duplicating the existing "dojo-starter" entry. Additionally, the README files have been updated to reflect changes in package management from bun to pnpm for the Torii Bot. Error handling in a promise chain has been simplified in main.ts, while the update method in scene-main.ts has been modified to be asynchronous. The README has also been expanded with new instructions related to the Dojo framework.

Changes

File Change Summary
.gitmodules Added a new submodule entry for "worlds/dojo-starter," duplicating the existing "dojo-starter" entry.
examples/example-nodejs-bot/README.md Updated package manager commands from bun to pnpm for installation, serving, building, and code generation.
examples/example-vanillajs-phaser-recs/src/main.ts Simplified error handling in the promise chain by using console.error directly as the catch handler.
examples/example-vanillajs-phaser-recs/src/scenes/scene-main.ts Changed update() method to async update() to support asynchronous movement commands.
readme.md Added new instructions and notes for using the Dojo framework, including setup and migration advice.

Possibly related PRs

  • fix: submodule #272: Modifies the path of the "dojo-starter" submodule in the .gitmodules file, related to the new "worlds/dojo-starter" entry.
  • feat: add kitchen sink example #281: Updates the .gitmodules file by adding a new submodule entry for "onchain-dash," similar to the changes made for "dojo-starter."

🐰 In the land of code where bunnies hop,
A new submodule joins, it won't stop!
With pnpm commands, we dance and play,
As async methods lead the way.
The README now guides with wisdom so bright,
Hooray for changes that feel just right! 🌟


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.

Copy link

@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: 3

🧹 Outside diff range and nitpick comments (3)
examples/example-nodejs-bot/README.md (1)

Line range hint 100-103: Update deployment instructions for pnpm.

The deployment section still references bun, which is inconsistent with the rest of the README that has been updated to use pnpm. Please update these instructions to use pnpm instead.

Here's a suggested update:

 Update the project settings:
 
 **Build Command:**
-`bun run build`
+`pnpm build`
 
 **Run Commands:**
-`bun run serve`
+`pnpm serve`
readme.md (1)

99-100: Approve with suggestion: Improve formatting of the migration note

This note provides valuable troubleshooting information for users who might encounter issues when migrating worlds. To improve readability, consider formatting it as a blockquote or adding emphasis. For example:

> **Note**: If you can't migrate worlds running `sozo migrate apply`, be sure to comment out `world_address` in the corresponding `worlds/${world}/dojo_dev.toml` file.

This formatting will make the note stand out more in the documentation.

examples/example-vanillajs-phaser-recs/src/scenes/scene-main.ts (1)

138-158: Ensure consistent order of camera centering and movement commands

There is inconsistency in the order of this.cameras.main.centerOn(...) and await this.dojo.systemCalls.move(...) calls across different movement directions. In the 'Up' direction, centerOn is called before the await call, whereas in other directions, it's called after. This could lead to inconsistent behavior in camera movement and player actions.

Apply this diff to standardize the order:

Option 1: Call centerOn before the movement command in all cases

// Down direction
if (null !== this.keyS && this.keyS.isDown) {
    this.followPoint.y += this.cameraSpeed;
+   this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
    await this.dojo.systemCalls.move(this.dojo.account, Direction.Down);
-   this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
    return;
}

// Left direction
if (null !== this.keyA && this.keyA.isDown) {
    this.followPoint.x -= this.cameraSpeed;
+   this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
    await this.dojo.systemCalls.move(this.dojo.account, Direction.Left);
-   this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
    return;
}

// Right direction
if (null !== this.keyD && this.keyD.isDown) {
    this.followPoint.x += this.cameraSpeed;
+   this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
    await this.dojo.systemCalls.move(
        this.dojo.account,
        Direction.Right
    );
-   this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
    return;
}

Option 2: Call centerOn after the movement command in all cases

// Up direction
if (null !== this.keyW && this.keyW.isDown) {
    this.followPoint.y -= this.cameraSpeed;
-   this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
    await this.dojo.systemCalls.move(this.dojo.account, Direction.Up);
+   this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
    return;
}

Choose the option that aligns with the intended game experience—whether the camera should move immediately with the key press or after the movement command completes.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 26b77b3 and 6eabbf4.

📒 Files selected for processing (5)
  • .gitmodules (1 hunks)
  • examples/example-nodejs-bot/README.md (2 hunks)
  • examples/example-vanillajs-phaser-recs/src/main.ts (1 hunks)
  • examples/example-vanillajs-phaser-recs/src/scenes/scene-main.ts (2 hunks)
  • readme.md (1 hunks)
🔇 Additional comments (8)
examples/example-vanillajs-phaser-recs/src/main.ts (1)

34-34: Simplified error handling looks good, but verify previous implementation's intent.

The simplified error handling is a good improvement in terms of code conciseness. It maintains the error logging functionality while adhering to the "fail fast" principle.

However, please verify that:

  1. There was no specific reason for the previous implementation's structure.
  2. The removal of the explicit undefined return in error cases doesn't affect any downstream error handling.

To ensure no critical information was lost in the simplification, let's check the git history:

✅ Verification successful

Simplified error handling verified and approved.

The change maintains error logging functionality and simplifies the code without altering its behavior.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the git history for the previous implementation of the error handling.

# Test: Show the previous implementation of the error handling.
git log -p -1 -- examples/example-vanillajs-phaser-recs/src/main.ts | grep -A 5 "\.catch"

Length of output: 193

examples/example-nodejs-bot/README.md (4)

21-21: LGTM: Package manager updated correctly.

The change from bun install to pnpm install is correct and consistent with the switch to pnpm as the package manager.


27-27: LGTM: Serve command updated correctly.

The change from bun run serve to pnpm serve is correct and consistent with the switch to pnpm. Note that pnpm allows for this shorter syntax (pnpm serve instead of pnpm run serve), which is a nice optimization.


33-33: LGTM: Build command updated correctly.

The change from bun run build --watch to pnpm build --watch is correct and consistent with the switch to pnpm. The shorter syntax is appropriately used here as well.


49-49: LGTM: Codegen command updated correctly.

The change from bun run codegen to pnpm codegen is correct and consistent with the switch to pnpm. The shorter syntax is appropriately used here as well.

readme.md (3)

98-98: LGTM: Helpful note for users

This note provides crucial information for users attempting to run the examples. It's well-placed and clearly written.


Line range hint 1-102: Overall assessment: Valuable additions to the documentation

The changes to this readme file provide more detailed and helpful instructions for users working with the Dojo project. The additions address potential issues and offer clear guidance for setting up and running examples. While some minor improvements in formatting and clarification have been suggested, the overall changes significantly enhance the documentation's usefulness.

Great job on improving the user experience!


102-102: Approve with suggestions: Clarify Torii command and address security consideration

The added Torii command is helpful for users setting up their environment. However, consider the following suggestions:

  1. Clarify if the world address is an example or a fixed value. If it's an example, you might want to use a placeholder like <world_address> instead.

  2. The --allowed-origins "*" flag allows requests from any origin, which could pose security risks in production environments. Consider adding a note about this, such as:

    > **Security Note**: The `--allowed-origins "*"` flag is used here for development purposes. In production environments, specify the allowed origins explicitly to enhance security.

These clarifications will help users understand the command better and be aware of potential security considerations.

To verify if the world address is used consistently across the documentation, you can run the following script:

✅ Verification successful

Verification Successful: Torii Command Usage Consistent

  • The world address 0xb4079627ebab1cd3cf9fd075dda1ad2454a7a448bf659591f259efa2519b18 is consistently used in the Torii command within readme.md.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for occurrences of the world address in the documentation

# Test: Search for the specific world address
rg --type md '0xb4079627ebab1cd3cf9fd075dda1ad2454a7a448bf659591f259efa2519b18'

Length of output: 190

Comment on lines +10 to +12
[submodule "worlds/dojo-starter"]
path = worlds/dojo-starter
url = https://github.com/dojoengine/dojo-starter
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove duplicate submodule entries

The newly added submodule entry for "worlds/dojo-starter" (lines 10-12) is a duplicate of the existing entry (lines 1-3). Additionally, there's a duplicate entry for "onchain-dash" (lines 7-9). Duplicate entries in the .gitmodules file can lead to confusion and potential issues with Git submodule management.

To resolve this, please remove the duplicate entries. Here's the suggested change:

[submodule "dojo-starter"]
	path = worlds/dojo-starter
	url = https://github.com/dojoengine/dojo-starter
[submodule "onchain-dash"]
	path = worlds/onchain-dash
	url = https://github.com/MartianGreed/onchain-dash
-[submodule "worlds/onchain-dash"]
-	path = worlds/onchain-dash
-	url = https://github.com/MartianGreed/onchain-dash
-[submodule "worlds/dojo-starter"]
-	path = worlds/dojo-starter
-	url = https://github.com/dojoengine/dojo-starter

This change will maintain the correct submodule configurations without redundancy.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[submodule "worlds/dojo-starter"]
path = worlds/dojo-starter
url = https://github.com/dojoengine/dojo-starter
[submodule "dojo-starter"]
path = worlds/dojo-starter
url = https://github.com/dojoengine/dojo-starter
[submodule "onchain-dash"]
path = worlds/onchain-dash
url = https://github.com/MartianGreed/onchain-dash

@@ -135,25 +135,28 @@ export default class SceneMain extends Scene {
if (null !== this.keyW && this.keyW.isDown) {
this.followPoint.y -= this.cameraSpeed;
this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
this.dojo.systemCalls.move(this.dojo.account, Direction.Up);
await this.dojo.systemCalls.move(this.dojo.account, Direction.Up);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for asynchronous movement commands

When calling await this.dojo.systemCalls.move(...), any errors thrown by the promise will not be caught, potentially causing unhandled exceptions. To ensure application stability, wrap the await calls in try-catch blocks to handle possible errors gracefully.

Apply this diff to add error handling:

// Up direction
if (null !== this.keyW && this.keyW.isDown) {
    this.followPoint.y -= this.cameraSpeed;
    this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
-   await this.dojo.systemCalls.move(this.dojo.account, Direction.Up);
+   try {
+       await this.dojo.systemCalls.move(this.dojo.account, Direction.Up);
+   } catch (error) {
+       console.error('Failed to move Up:', error);
+   }
    return;
}

// Down direction
if (null !== this.keyS && this.keyS.isDown) {
    this.followPoint.y += this.cameraSpeed;
    this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
-   await this.dojo.systemCalls.move(this.dojo.account, Direction.Down);
+   try {
+       await this.dojo.systemCalls.move(this.dojo.account, Direction.Down);
+   } catch (error) {
+       console.error('Failed to move Down:', error);
+   }
    return;
}

// Left direction
if (null !== this.keyA && this.keyA.isDown) {
    this.followPoint.x -= this.cameraSpeed;
    this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
-   await this.dojo.systemCalls.move(this.dojo.account, Direction.Left);
+   try {
+       await this.dojo.systemCalls.move(this.dojo.account, Direction.Left);
+   } catch (error) {
+       console.error('Failed to move Left:', error);
+   }
    return;
}

// Right direction
if (null !== this.keyD && this.keyD.isDown) {
    this.followPoint.x += this.cameraSpeed;
    this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
-   await this.dojo.systemCalls.move(
-       this.dojo.account,
-       Direction.Right
-   );
+   try {
+       await this.dojo.systemCalls.move(
+           this.dojo.account,
+           Direction.Right
+       );
+   } catch (error) {
+       console.error('Failed to move Right:', error);
+   }
    return;
}

This ensures that any errors during the movement calls are handled appropriately, preventing potential crashes.

Also applies to: 143-143, 149-149, 155-158

@@ -85,7 +85,7 @@
return chunk;
}

update() {
async update() {
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Avoid making the update() method asynchronous in Phaser scenes

Making the update() method asynchronous in Phaser can lead to unexpected behavior and performance issues. The Phaser game loop expects update() to be a synchronous function called on each frame. Introducing await inside this method may cause frame drops or delays. It's recommended to keep update() synchronous and handle asynchronous operations differently.

Apply this diff to remove the async keyword and adjust the await calls:

-        async update() {
+        update() {

In each movement case, remove the await keyword:

if (null !== this.keyW && this.keyW.isDown) {
    this.followPoint.y -= this.cameraSpeed;
    this.cameras.main.centerOn(this.followPoint.x, this.followPoint.y);
-   await this.dojo.systemCalls.move(this.dojo.account, Direction.Up);
+   this.dojo.systemCalls.move(this.dojo.account, Direction.Up);
    return;
}

Consider handling the promises returned by this.dojo.systemCalls.move without awaiting them inside the update() method, or by using event-driven approaches to manage asynchronous behavior.

Committable suggestion was skipped due to low confidence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant