FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(Relationship): implement TryGetChildComponents and TryGetParentComponent utilities by EthanCharpentier667 · Pull Request #611 · EngineSquared/EngineSquared · GitHub

feat(Relationship): implement TryGetChildComponents and TryGetParentComponent utilities - #611

Merged
Miou-zora merged 6 commits into
EngineSquared:mainfrom
EthanCharpentier667:access-component-in-parent-child
Jun 1, 2026
Merged

feat(Relationship): implement TryGetChildComponents and TryGetParentComponent utilities#611
Miou-zora merged 6 commits into
EngineSquared:mainfrom
EthanCharpentier667:access-component-in-parent-child

Conversation

EthanCharpentier667 commented May 27, 2026
edited by coderabbitai Bot
Loading

Copy link
Copy Markdown
Contributor

Pull Request

Description

Related Issues (Optional, put "None" if there are no related issues)

Fixes #609
Relates to #609

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Project related stuff

Changes Made

List of the main changes in this PR:

  • Change 1
  • Change 2
  • Change 3

Testing (Optional, put "None" if you didn't have to test anything)

  • Unit tests pass (xmake build Relationship && xmake run Relationship)
  • Code follows the project's style guidelines (xmake format)
  • Manual testing performed (working exemple are in src/plugin/relationship/examples/RelationshipUsage/src/main.cpp)

Test Environment

  • OS: [macOS]
  • Compiler: [Clang]

Documentation

  • I have added/updated comments in the code
  • IDK if documentation changes are required (doxygen made but did not run xmake build_documentation)

Checklist (Don't delete any options)

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Time Spent (Optional, put "None" if you don't know)

1 hour (including understanding the fork and creating the pull request): 30 minutes of actual coding

Screenshots/Videos (Optional, put "None" if it's not relevant)

None

Breaking Changes (Optional, Put "None" if there are no breaking changes)

None

Additional Notes (Optional, Put "None" if there are no additional notes)

None

Summary by CodeRabbit

  • New Features

    • Utilities to collect components from child entities and to attempt retrieving a specific component from a parent entity.
  • Examples

    • Example updated to demonstrate listing descendant components and resolving a parent's component when available, with error logging when not found.
  • Tests

    • Added tests covering child-component discovery, parent-component lookup, and failure cases when components or relationships are absent.

coderabbitai Bot commented May 27, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info ⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fb06fae3-9458-480c-94b3-c1704f856344

📥 Commits

Reviewing files that changed from the base of the PR and between 50d9542 and 8ebf66f.

📒 Files selected for processing (3)
  • src/plugin/relationship/examples/RelationshipUsage/src/main.cpp
  • src/plugin/relationship/src/utils/Utils.hpp
  • src/plugin/relationship/tests/Relationship.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/plugin/relationship/tests/Relationship.cpp

📝 Walkthrough

Walkthrough

Adds header-only templates GetChildComponents<TComponent>(Engine::Entity parent) to collect matching child component references and TryGetParentComponent<TComponent>(Engine::Entity child) to fetch a parent's component pointer; updates unit tests and an example usage to exercise these utilities.

Changes

Relationship component access utilities

Layer / File(s) Summary
Template utilities for parent/child component access
src/plugin/relationship/src/utils/Utils.hpp
Documents ForEachChild and adds GetChildComponents<TComponent>(Engine::Entity parent) -> std::vector<std::reference_wrapper<TComponent>> and TryGetParentComponent<TComponent>(Engine::Entity child) -> TComponent*.
Unit tests for utilities
src/plugin/relationship/tests/Relationship.cpp
Adds a local TestComponent and tests covering GetChildComponents<TestComponent> (matching children only, empty cases) and TryGetParentComponent<TestComponent> (parent present, no parent, parent lacks component).
Example runtime usage
src/plugin/relationship/examples/RelationshipUsage/src/main.cpp
Calls GetChildComponents<TestComponent>(parent) and logs an error or the first child's value; calls TryGetParentComponent<NameComponent>(child4) and logs the parent name or an error.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • Divengerss

"Hi, I'm a rabbit, quick and spry,
I hop through nodes and look up high.
I fetch a child and peek at a parent,
Paws on code, my nose grows grander.
Tests pass — I twitch, then sigh."

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title claims to implement 'TryGetChildComponents' but the actual changes implement 'GetChildComponents', which is a different API. The title is misleading. Update the title to reflect the actual implementations: 'feat(Relationship): implement GetChildComponents and TryGetParentComponent utilities' or use the correct function names.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR successfully implements utilities to retrieve components from parent and child entities as requested in #609, providing built-in functions for both parent and child component access.
Out of Scope Changes check ✅ Passed All changes are directly related to the objectives in #609: implementing parent/child component utilities, adding tests, and updating usage examples. No out-of-scope changes detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches 🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/plugin/relationship/tests/Relationship.cpp (1)

204-221: ⚡ Quick win

Add nullopt-path assertions for TryGetParentComponent.

This test only validates the happy path. Please add cases for “child has no parent” and “parent exists but lacks TestComponent” to lock in the API contract.

✅ Suggested additions
 TEST(Relationship, try_get_parent_component)
 {
     Engine::Core core;
@@
     auto parentComponent = Relationship::Utils::TryGetParentComponent<TestComponent>(child);
 
     ASSERT_TRUE(parentComponent.has_value());
     ASSERT_EQ(parentComponent->value, 42);
+
+    auto orphan = core.CreateEntity();
+    orphan.AddComponent<Relationship::Component::Relationship>();
+    ASSERT_EQ(Relationship::Utils::TryGetParentComponent<TestComponent>(orphan), std::nullopt);
+
+    auto parentWithoutTest = core.CreateEntity();
+    auto childWithoutParentTest = core.CreateEntity();
+    parentWithoutTest.AddComponent<Relationship::Component::Relationship>();
+    childWithoutParentTest.AddComponent<Relationship::Component::Relationship>();
+    Relationship::Utils::SetChildOf(childWithoutParentTest, parentWithoutTest);
+    ASSERT_EQ(Relationship::Utils::TryGetParentComponent<TestComponent>(childWithoutParentTest), std::nullopt);
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/plugin/relationship/tests/Relationship.cpp` around lines 204 - 221, Add
two negative-path assertions to the Relationship.try_get_parent_component test:
(1) create a child entity without calling Relationship::Utils::SetChildOf and
assert
Relationship::Utils::TryGetParentComponent<TestComponent>(child).has_value() is
false; (2) create a child and parent, attach
Relationship::Component::Relationship to both and call
Relationship::Utils::SetChildOf(child, parent) but do not add TestComponent to
parent, then assert TryGetParentComponent<TestComponent>(child).has_value() is
false—use the same entities and helpers (SetChildOf, TryGetParentComponent,
TestComponent) used in the existing test to validate the nullopt paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/plugin/relationship/src/utils/Utils.hpp`:
- Around line 67-70: Forward-declare the ForEachChild function before the
TryGetChildComponents template so the template can find it during instantiation;
add a declaration matching the actual signature used (e.g., a function taking
Engine::Entity and a callable/lambda) above the TryGetChildComponents
definition, then keep the full ForEachChild definition later in the header so
TryGetChildComponents can call it without lookup/instantiation issues.

---

Nitpick comments:
In `@src/plugin/relationship/tests/Relationship.cpp`:
- Around line 204-221: Add two negative-path assertions to the
Relationship.try_get_parent_component test: (1) create a child entity without
calling Relationship::Utils::SetChildOf and assert
Relationship::Utils::TryGetParentComponent<TestComponent>(child).has_value() is
false; (2) create a child and parent, attach
Relationship::Component::Relationship to both and call
Relationship::Utils::SetChildOf(child, parent) but do not add TestComponent to
parent, then assert TryGetParentComponent<TestComponent>(child).has_value() is
false—use the same entities and helpers (SetChildOf, TryGetParentComponent,
TestComponent) used in the existing test to validate the nullopt paths.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info ⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6b41502f-ef21-4b37-9d36-ac60f070e72e

📥 Commits

Reviewing files that changed from the base of the PR and between c7a6de6 and 0766e3b.

📒 Files selected for processing (3)
  • src/plugin/relationship/examples/RelationshipUsage/src/main.cpp
  • src/plugin/relationship/src/utils/Utils.hpp
  • src/plugin/relationship/tests/Relationship.cpp

…nent to return pointers and ajust tests accordingly

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

EthanCharpentier667 changed the title feat(Relationship): implement TryGetChildComponents and TryGetParentComponent utilities with tests feat(Relationship): implement TryGetChildComponents and TryGetParentComponent utilities May 28, 2026
Comment on lines +103 to +106
if (childComponent)
{
childComponents.emplace_back(childComponent);
}

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This if is maybe useless as TryGet... function return something incertains which should (by name) be checked after calling it

…onents who return references of found components

sonarqubecloud Bot commented Jun 1, 2026

Copy link
Copy Markdown

Miou-zora merged commit b03ec53 into EngineSquared:main Jun 1, 2026
18 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

[FEATURE] Access component/s of parent or child

2 participants


Back | FazBrowse Home | New Git URL