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

Release 0.9.3 #18

Merged
merged 1 commit into from
Nov 13, 2024
Merged

Release 0.9.3 #18

merged 1 commit into from
Nov 13, 2024

Conversation

CoderGamester
Copy link
Owner

@CoderGamester CoderGamester commented Nov 13, 2024

New

  • Added new ITaskWaitState.WaitingFor(Func) method to allow TaskWaitStates to hold on UniTask type calls

Fixed

  • Added UniTask to the package to allow the Statechart run on WebGL

Summary by CodeRabbit

  • New Feature: Added support for UniTask in the game's statechart system, allowing for asynchronous operations and improved performance.
  • Bug Fix: Fixed a null reference issue in the TaskWaitState class when using UniTask, ensuring smooth transitions between states.
  • Test: Added a new test method to verify the functionality of UniTask waiting in the statechart system.
  • Documentation: Updated the CHANGELOG.md file to reflect the changes made, including the addition of the WaitingFor method and UniTask support for WebGL.
  • Chore: Added necessary references and namespaces for UniTask usage in the project and testing environment.

Summary by CodeRabbit

Release Notes for Version 0.9.3

  • New Features

    • Introduced support for UniTask in the ITaskWaitState interface, allowing for enhanced asynchronous operations.
    • Added a new method WaitingFor(Func<UniTask>) for improved flexibility in handling tasks.
  • Improvements

    • Updated exception handling for better visibility in the Unity console.
    • Enhanced state management with new methods and improved performance using UniTask.
  • Bug Fixes

    • Various bug fixes related to state execution and transitions have been implemented.
  • Documentation

    • Updated changelog to reflect changes and improvements across versions.

- Added new *ITaskWaitState.WaitingFor(Func<UniTask>)* method to allow *TaskWaitStates* to hold on *UniTask* type calls

**Fixed**
- Added *UniTask* to the package to allow the *Statechart* run on WebGL
Copy link

coderabbitai bot commented Nov 13, 2024

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

The changes include the addition of a new method ITaskWaitState.WaitingFor(Func<UniTask>) in version 0.9.3 of the changelog, which allows for UniTask type calls in TaskWaitStates. The package now supports UniTask for WebGL compatibility. Updates were made to exception handling in previous versions, and the Runtime/GameLovers.Statechart.asmdef file has been modified to include a rootNamespace and a reference to a GUID. The TaskWaitState class was updated to handle asynchronous operations using UniTask, and corresponding tests were added to validate this functionality.

Changes

File Change Summary
CHANGELOG.md Updated for version 0.9.3 with new method ITaskWaitState.WaitingFor(Func<UniTask>) and inclusion of UniTask. Previous versions modified for exception handling.
Runtime/GameLovers.Statechart.asmdef Added rootNamespace as an empty string and updated references to include "GUID:f51ebe6a0ceec4240a699833d6309b23".
Runtime/IState.cs Added method overload WaitingFor(Func<UniTask>) in ITaskWaitState interface; existing WaitingFor(Func<Task>) remains unchanged.
Runtime/Internal/TaskWaitState.cs Changed _taskAwaitAction field to Func<UniTask>. Added overloads for WaitingFor method. Updated InnerTaskAwait to return UniTask.
Tests/Editor/GameLovers.Statechart.Editor.Tests.asmdef Added rootNamespace and reference to UniTask in the assembly definition.
Tests/Editor/StatechartTaskWaitTest.cs Added tests for UniTask functionality, including UniTaskWait_EventTrigger_DoesNothing, and new private methods for handling UniTask.
package.json Updated version to 0.9.3, changed Unity version requirement to 2022.3, and added dependency on com.cysharp.unitask version 2.5.10.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Statechart
    participant TaskWaitState
    participant UniTask

    User->>Statechart: Trigger Event
    Statechart->>TaskWaitState: Call WaitingFor(Func<UniTask>)
    TaskWaitState->>UniTask: Execute Async Operation
    UniTask-->>TaskWaitState: Return Result
    TaskWaitState-->>Statechart: Notify Completion
    Statechart-->>User: Event Handling Complete
Loading

🐰 In the meadow, where bunnies play,
A new method hops in, hip-hip-hooray!
With UniTask joining the fun,
Asynchronous tasks now easily run.
Statecharts dance, transitions flow,
In the world of code, watch them glow! 🌟


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

github-actions bot commented Nov 13, 2024

Image description CodeRabbit

Walkthrough

The changes include the addition of a new method ITaskWaitState.WaitingFor(Func<UniTask>) and the inclusion of UniTask in the package for WebGL support. The changes are made to multiple files, including IState.cs, TaskWaitState.cs, GameLovers.Statechart.Editor.Tests.asmdef, and StatechartTaskWaitTest.cs. The modifications allow for UniTask type calls and enhance the testing environment with UniTask support.

Changes

File Summary
CHANGELOG.md Added a new method ITaskWaitState.WaitingFor(Func<UniTask>) and included UniTask in the package for WebGL support.
Runtime/GameLovers.Statechart.asmdef Added a new reference to "GUID:f51ebe6a0ceec4240a699833d6309b23" in the "GameLovers.Statechart" project.
Runtime/IState.cs Added a new method WaitingFor(Func<UniTask> taskAwaitAction) to the ITaskWaitState interface, allowing TaskWaitStates to hold on UniTask type calls. Also, included using Cysharp.Threading.Tasks; for UniTask usage.
Runtime/Internal/TaskWaitState.cs Introduced a new method WaitingFor(Func<UniTask> taskAwaitAction) in the TaskWaitState class, allowing for UniTask type calls. The method handles null references and returns a transition object. Additionally, the InnerTaskAwait method now returns UniTask instead of Task.
Tests/Editor/GameLovers.Statechart.Editor.Tests.asmdef Added "UniTask" reference to the project, with a new root namespace.
Tests/Editor/StatechartTaskWaitTest.cs Introduced a new method UniTaskWait_EventTrigger_DoesNothing() to test UniTask waiting functionality. It adds UniTask support to the codebase for WebGL compatibility. Additionally, it includes changes to support UniTask in the testing environment.

"UniTask arrives, a new addition,
Bringing WebGL support with precision.
Interfaces and classes now embrace,
The power of UniTask in every case.
Testing environment enhanced anew,
With UniTask's capabilities shining through."


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 7995e0b and fab1cf8 commits.
Files selected (6)
  • CHANGELOG.md (8)
  • Runtime/GameLovers.Statechart.asmdef (1)
  • Runtime/IState.cs (2)
  • Runtime/Internal/TaskWaitState.cs (4)
  • Tests/Editor/GameLovers.Statechart.Editor.Tests.asmdef (1)
  • Tests/Editor/StatechartTaskWaitTest.cs (5)
Files ignored due to filter (1)
  • package.json
Files skipped from review due to trivial changes (1)
  • Tests/Editor/GameLovers.Statechart.Editor.Tests.asmdef
Review comments generated (6)
  • Review: 5
  • LGTM: 1

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +3 to 6
using Cysharp.Threading.Tasks;
using GameLovers.StatechartMachine;
using NSubstitute;
using NUnit.Framework;

Choose a reason for hiding this comment

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

Image description CodeRabbit

The using statements have been modified.

- using System.Collections;
+ using Cysharp.Threading.Tasks;

Comment on lines +81 to +107
[Test]
public async Task UniTaskWait_EventTrigger_DoesNothing()
{
var statechart = new Statechart(SetupUniTaskWaitState);

statechart.Run();

_caller.Received().OnTransitionCall(0);
_caller.DidNotReceive().OnTransitionCall(1);
_caller.DidNotReceive().OnTransitionCall(2);
_caller.Received().InitialOnExitCall(0);
_caller.Received().StateOnEnterCall(0);
_caller.DidNotReceive().StateOnExitCall(0);
_caller.DidNotReceive().FinalOnEnterCall(0);

statechart.Trigger(_event);

_blocker = false;

await YieldWaitUniTask();

_caller.Received().OnTransitionCall(1);
_caller.DidNotReceive().OnTransitionCall(2);
_caller.Received().StateOnExitCall(0);
_caller.Received().FinalOnEnterCall(0);
}

Choose a reason for hiding this comment

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

Image description CodeRabbit

A new test method UniTaskWait_EventTrigger_DoesNothing() has been added to test UniTask waiting functionality.

[Test]
public async Task UniTaskWait_EventTrigger_DoesNothing()
{
    var statechart = new Statechart(SetupUniTaskWaitState);

    statechart.Run();

    _caller.Received().OnTransitionCall(0);
    _caller.DidNotReceive().OnTransitionCall(1);
    _caller.DidNotReceive().OnTransitionCall(2);
    _caller.Received().InitialOnExitCall(0);
    _caller.Received().StateOnEnterCall(0);
    _caller.DidNotReceive().StateOnExitCall(0);
    _caller.DidNotReceive().FinalOnEnterCall(0);

    statechart.Trigger(_event);

    _blocker = false;

    await YieldWaitUniTask();

    _caller.Received().OnTransitionCall(1);
    _caller.DidNotReceive().OnTransitionCall(2);
    _caller.Received().StateOnExitCall(0);
    _caller.Received().FinalOnEnterCall(0);
}

Comment on lines +151 to +161

private async UniTask UniTaskWaitAction()
{
while (_blocker)
{
await UniTask.Yield();
}

_done = true;
}

Choose a reason for hiding this comment

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

Image description CodeRabbit

A new private method UniTaskWaitAction() has been added to handle UniTask waiting.

private async UniTask UniTaskWaitAction()
{
    while (_blocker)
    {
        await UniTask.Yield();
    }

    _done = true;
}

Comment on lines +172 to +180
private async UniTask YieldWaitUniTask()
{
while (!_done)
{
await UniTask.Yield();
}

await UniTask.Yield();
}

Choose a reason for hiding this comment

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

Image description CodeRabbit

The YieldWaitTask() method has been replaced with YieldWaitUniTask() method to use UniTask instead of Task.

private async UniTask YieldWaitUniTask()
{
    while (!_done)
    {
        await UniTask.Yield();
    }

    await UniTask.Yield();
}

Comment on lines +205 to +213
private void SetupUniTaskWaitState(IStateFactory factory)
{
var waiting = factory.TaskWait("Task Wait");
var final = SetupSimpleFlow(factory, waiting);

waiting.OnEnter(() => _caller.StateOnEnterCall(0));
waiting.WaitingFor(UniTaskWaitAction).OnTransition(() => _caller.OnTransitionCall(1)).Target(final);
waiting.OnExit(() => _caller.StateOnExitCall(0));
}

Choose a reason for hiding this comment

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

Image description CodeRabbit

The SetupUniTaskWaitState() method has been added to set up the statechart for UniTask waiting.

private void SetupUniTaskWaitState(IStateFactory factory)
{
    var waiting = factory.TaskWait("Task Wait");
    var final = SetupSimpleFlow(factory, waiting);

    waiting.OnEnter(() => _caller.StateOnEnterCall(0));
    waiting.WaitingFor(UniTaskWaitAction).OnTransition(() => _caller.OnTransitionCall(1)).Target(final);
    waiting.OnExit(() => _caller.StateOnExitCall(0));
}

Overall, the changes seem fine. However, there are a few suggestions to improve the code:

  1. Consistency: Ensure consistent ordering of using statements. It's recommended to group them by namespace and separate them with a blank line.
  2. Naming: Consider using more descriptive names for variables and methods to improve code readability.
  3. Error Handling: Add appropriate error handling mechanisms, such as try-catch blocks, to handle exceptions that may occur during asynchronous operations.

Let me know if you have any questions or need further assistance!

@CoderGamester CoderGamester merged commit 270e13f into master Nov 13, 2024
1 check passed
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