Some fixes with coral

This commit is contained in:
antopilo
2025-01-17 17:59:17 -05:00
parent 6b53ab6f8f
commit ab534fe929
3 changed files with 15 additions and 9 deletions

View File

@@ -43,12 +43,12 @@ namespace Nuake {
return scene->GetEntity(entityName).GetHandle();
}
Coral::ManagedObject* GetEntityScriptFromName(Coral::String entityName)
void GetEntityScriptFromName(Coral::String entityName, Coral::ManagedObject* outInstance)
{
auto scene = Engine::GetCurrentScene();
if (!scene->EntityExists(std::string(entityName)))
{
return nullptr; // Error code: entity not found.
// Error code: entity not found.
}
Entity entity = scene->GetEntity(entityName);
@@ -57,9 +57,9 @@ namespace Nuake {
if (scriptingEngine.HasEntityScriptInstance(entity))
{
auto instance = scriptingEngine.GetEntityScript(entity);
return instance;
outInstance->m_Handle = instance->m_Handle;
outInstance->m_Type = instance->m_Type;
}
}
Coral::ManagedObject* GetEntityScriptFromHandle(int entityHandle)

View File

@@ -660,7 +660,7 @@ namespace Nuake
}
}
entityToManagedObjects.emplace(entity.GetID(), classInstance);
// Override with user values set in the editor.
for (auto& exposedVarUserValue : component.ExposedVar)
@@ -726,6 +726,8 @@ namespace Nuake
classInstance.SetFieldValue(exposedVarUserValue.Name, exposedVarUserValue.Value);
}
}
entityToManagedObjects.emplace(entity.GetID(), std::move(classInstance));
}
Coral::ManagedObject* ScriptingEngineNet::GetEntityScript(const Entity& entity)

View File

@@ -7,16 +7,20 @@ namespace Nuake.Net
public class Scene
{
internal static unsafe delegate*<NativeString, int> GetEntityIcall;
internal static unsafe delegate*<NativeString, NativeInstance<Entity>> GetEntityScriptFromNameIcall;
internal static unsafe delegate*<NativeString, NativeInstance<object>*, void> GetEntityScriptFromNameIcall;
internal static unsafe delegate*<int, NativeInstance<Entity>> GetEntityScriptFromHandleIcall;
internal static unsafe delegate*<NativeString, int> InstancePrefabIcall;
public static T? GetEntity<T>(string entityName) where T : class
{
NativeInstance<Entity> handle;
unsafe { handle = GetEntityScriptFromNameIcall(entityName); }
NativeInstance<object> handle;
Entity? entity = handle.Get();
// This doesnt :(
unsafe { GetEntityScriptFromNameIcall(entityName, &handle); }
object? entity = handle.Get();
Engine.Log("Fetched entityL: " + entity);
if (entity != null && entity is T)
{
return entity as T;