Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Resources/Engine/Lua/Scene/Actor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ function Actor:GetGUID() end
---@return Actor[]
function Actor:GetChildren() end

--- Finds a child actor by name
---@param name string
---@param recursive boolean
---@return Actor|nil
function Actor:FindChild(name, recursive) end

--- Returns the parent (or nil) of this actor
---@return Actor|nil
function Actor:GetParent() end
Expand Down
7 changes: 7 additions & 0 deletions Sources/OvCore/include/OvCore/ECS/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ namespace OvCore::ECS
*/
std::vector<Actor*>& GetChildren();

/**
* Finds a child actor by name
* @param p_name
* @param p_recursive
*/
Actor* FindChild(const std::string& p_name, bool p_recursive) const;

/**
* Mark the Actor as "Destroyed". A "Destroyed" actor will be removed from the scene by the scene itself
*/
Expand Down
24 changes: 24 additions & 0 deletions Sources/OvCore/src/OvCore/ECS/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,30 @@ std::vector<OvCore::ECS::Actor*>& OvCore::ECS::Actor::GetChildren()
return m_children;
}

OvCore::ECS::Actor* OvCore::ECS::Actor::FindChild(const std::string& p_name, bool p_recursive) const
{
for (auto child : m_children)
{
if (child->GetName() == p_name)
{
return child;
}
}

if (p_recursive)
{
for (auto child : m_children)
{
if (auto found = child->FindChild(p_name, true); found)
{
return found;
}
}
}

return nullptr;
}

void OvCore::ECS::Actor::MarkAsDestroy()
{
m_destroyed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void BindLuaActor(sol::state& p_luaState)
"SetName", &Actor::SetName,
"GetTag", &Actor::GetTag,
"GetChildren", &Actor::GetChildren,
"FindChild", &Actor::FindChild,
"SetTag", &Actor::SetTag,
"GetID", &Actor::GetID,
"GetGUID", [](Actor& p_actor) { return std::format("{:016X}", p_actor.GetGUID()); },
Expand Down
Loading