mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Added relative path entity fetching
This commit is contained in:
@@ -123,12 +123,89 @@ namespace Nuake
|
||||
}
|
||||
}
|
||||
|
||||
return Entity();
|
||||
Entity currentEntity;
|
||||
uint32_t currentSplitIndex = 1;
|
||||
while (currentSplitIndex < splits.size())
|
||||
{
|
||||
// Look at root entities first
|
||||
if (currentSplitIndex == 1)
|
||||
{
|
||||
for (auto& rootEntity : rootEntities)
|
||||
{
|
||||
if (!rootEntity.IsValid())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::string& name = rootEntity.GetComponent<NameComponent>().Name;
|
||||
if (name == splits[currentSplitIndex])
|
||||
{
|
||||
currentEntity = rootEntity;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Then look through child of root entity
|
||||
for (auto& child : currentEntity.GetComponent<ParentComponent>().Children)
|
||||
{
|
||||
if (!child.IsValid())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (child.GetComponent<NameComponent>().Name == splits[currentSplitIndex])
|
||||
{
|
||||
currentEntity = child;
|
||||
}
|
||||
}
|
||||
|
||||
currentSplitIndex++;
|
||||
}
|
||||
|
||||
return currentEntity;
|
||||
}
|
||||
|
||||
Entity Scene::GetRelativeEntityFromPath(Entity entity, const std::string& path)
|
||||
{
|
||||
return Entity();
|
||||
Entity currentEntity = entity;
|
||||
|
||||
auto splits = String::Split(path, '/');
|
||||
uint32_t currentSplitIndex = 0;
|
||||
while (currentSplitIndex < splits.size())
|
||||
{
|
||||
const std::string& currentSplit = splits[currentSplitIndex];
|
||||
|
||||
if (currentSplit == ".")
|
||||
{
|
||||
currentSplitIndex++;
|
||||
continue; // ignore
|
||||
}
|
||||
|
||||
if (currentSplit == "..") // Go up a level
|
||||
{
|
||||
auto& parentComponent = currentEntity.GetComponent<ParentComponent>();
|
||||
if (parentComponent.HasParent)
|
||||
{
|
||||
currentEntity = parentComponent.Parent;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto& child : currentEntity.GetComponent<ParentComponent>().Children)
|
||||
{
|
||||
auto& nameComponent = child.GetComponent<NameComponent>();
|
||||
if (nameComponent.Name == currentSplit)
|
||||
{
|
||||
currentEntity = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentSplitIndex++;
|
||||
}
|
||||
|
||||
return currentEntity;
|
||||
}
|
||||
|
||||
bool Scene::OnInit()
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Nuake {
|
||||
virtual const std::string GetModuleName() const = 0;
|
||||
virtual void RegisterMethods() = 0;
|
||||
|
||||
MethodMap GetMethods() const { return m_Methods; }
|
||||
const MethodMap& GetMethods() const { return m_Methods; }
|
||||
|
||||
protected:
|
||||
void RegisterMethod(const std::string& name, void* methodPtr)
|
||||
|
||||
@@ -152,8 +152,6 @@ namespace Nuake {
|
||||
|
||||
int EntityGetEntity(int handle, Coral::String input)
|
||||
{
|
||||
std::string path = input;
|
||||
|
||||
Ref<Scene> scene = Engine::GetCurrentScene();
|
||||
if (String::BeginsWith(input, "/"))
|
||||
{
|
||||
|
||||
@@ -124,13 +124,13 @@ namespace Nuake.Net
|
||||
return null;
|
||||
}
|
||||
|
||||
public Entity? GetEntity<T>(string path) where T : Entity
|
||||
public T? GetEntity<T>(string path) where T : Entity
|
||||
{
|
||||
Entity entityInstance;
|
||||
unsafe
|
||||
{
|
||||
int entityHandle = EntityGetEntityIcall(ECSHandle, path );
|
||||
|
||||
|
||||
bool hasInstance = EntityHasManagedInstanceIcall(entityHandle);
|
||||
if (hasInstance)
|
||||
{
|
||||
@@ -142,7 +142,7 @@ namespace Nuake.Net
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return entityInstance as T;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user