Collision callback now returns native instance if possible

This commit is contained in:
Antoine Pilote
2024-04-18 23:09:56 -04:00
parent 41c07bf6d8
commit c981b45cac
3 changed files with 68 additions and 6 deletions

View File

@@ -39,7 +39,7 @@ namespace Nuake {
return scene->GetEntity(entityName).GetHandle();
}
Coral::ManagedObject GetEntityScript(Coral::String entityName)
Coral::ManagedObject GetEntityScriptFromName(Coral::String entityName)
{
auto scene = Engine::GetCurrentScene();
if (!scene->EntityExists(entityName))
@@ -57,6 +57,24 @@ namespace Nuake {
}
}
Coral::ManagedObject GetEntityScriptFromHandle(int entityHandle)
{
auto scene = Engine::GetCurrentScene();
Entity entity = { (entt::entity)(entityHandle), scene.get()};
if (!entity.IsValid())
{
return Coral::ManagedObject(); // Error code: entity not found.
}
auto& scriptingEngine = ScriptingEngineNet::Get();
if (scriptingEngine.HasEntityScriptInstance(entity))
{
auto instance = scriptingEngine.GetEntityScript(entity);
return instance;
}
}
static enum ComponentTypes
{
Unknown = -1,
@@ -121,6 +139,17 @@ namespace Nuake {
}
}
bool EntityHasManagedInstance(int handle)
{
Entity entity = { (entt::entity)(handle), Engine::GetCurrentScene().get() };
if (!entity.IsValid())
{
return false;
}
return ScriptingEngineNet::Get().HasEntityScriptInstance(entity);
}
void TransformSetPosition(int entityId, float x, float y, float z)
{
Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() };
@@ -247,8 +276,10 @@ namespace Nuake {
void Nuake::SceneNetAPI::RegisterMethods()
{
RegisterMethod("Entity.EntityHasComponentIcall", &EntityHasComponent);
RegisterMethod("Entity.EntityHasManagedInstanceIcall", &EntityHasManagedInstance);
RegisterMethod("Scene.GetEntityIcall", &GetEntity);
RegisterMethod("Scene.GetEntityScriptIcall", &GetEntityScript);
RegisterMethod("Scene.GetEntityScriptFromNameIcall", &GetEntityScriptFromName);
RegisterMethod("Scene.GetEntityScriptFromHandleIcall", &GetEntityScriptFromHandle);
// Components
RegisterMethod("TransformComponent.SetPositionIcall", &TransformSetPosition);