Added bool operator and isvalid function to .Net API

This commit is contained in:
Antoine Pilote
2024-08-15 19:18:26 -04:00
parent ead6ff6645
commit 901ebcf902
3 changed files with 33 additions and 4 deletions

View File

@@ -210,19 +210,23 @@ void NetScriptPanel::Draw(Nuake::Entity entity)
if (field.Type == Nuake::NetScriptExposedVarType::Entity)
{
if (!field.Value.has_value())
if (!field.Value.has_value() && field.DefaultValue.has_value())
{
field.Value = field.DefaultValue;
}
int entityId = -1;
if (field.Value.has_value())
{
entityId = std::any_cast<int>(field.Value);
}
int entityId = std::any_cast<int>(field.Value);
auto entity = Nuake::Engine::GetCurrentScene()->GetEntityByID(entityId);
bool invalid = !entity.IsValid();
std::string buttonLabel;
if (invalid)
{
buttonLabel = "Invalid Entity*";
buttonLabel = "Invalid Entity";
}
else
{

View File

@@ -200,6 +200,12 @@ namespace Nuake {
entity.GetComponent<NameComponent>().Name = newEntityName;
}
bool EntityIsValid(int handle)
{
Entity entity = { (entt::entity)(handle), Engine::GetCurrentScene().get() };
return entity.IsValid();
}
void TransformSetPosition(int entityId, float x, float y, float z)
{
Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() };
@@ -361,6 +367,7 @@ namespace Nuake {
RegisterMethod("Entity.EntityGetEntityIcall", &EntityGetEntity);
RegisterMethod("Entity.EntityGetNameIcall", &EntityGetName);
RegisterMethod("Entity.EntitySetNameIcall", &EntitySetName);
RegisterMethod("Entity.EntityIsValidIcall", &EntityIsValid);
// Scene
RegisterMethod("Scene.GetEntityIcall", &GetEntity);

View File

@@ -26,6 +26,7 @@ namespace Nuake.Net
internal static unsafe delegate*<int, NativeString, int> EntityGetEntityIcall;
internal static unsafe delegate*<int, NativeString> EntityGetNameIcall;
internal static unsafe delegate*<int, NativeString, void> EntitySetNameIcall;
internal static unsafe delegate*<int, bool> EntityIsValidIcall;
public enum ComponentTypes
{
@@ -56,7 +57,7 @@ namespace Nuake.Net
public int ID { get; set; }
public int ECSHandle { get; set; }
public int ECSHandle { get; set; } = -1;
public string Name
{
@@ -184,5 +185,22 @@ namespace Nuake.Net
return entityInstance as T;
}
public static implicit operator bool(Entity entity)
{
bool isValid = false;
if(object.ReferenceEquals(entity, null))
{
return false;
}
unsafe
{
isValid = EntityIsValidIcall(entity.ECSHandle);
}
return isValid;
}
}
}