Added Exposed var reset button

This commit is contained in:
Antoine Pilote
2024-08-15 19:44:17 -04:00
parent 901ebcf902
commit 04926476d7
5 changed files with 52 additions and 22 deletions

View File

@@ -224,7 +224,11 @@ void NetScriptPanel::Draw(Nuake::Entity entity)
auto entity = Nuake::Engine::GetCurrentScene()->GetEntityByID(entityId);
bool invalid = !entity.IsValid();
std::string buttonLabel;
if (invalid)
if (entityId == -1)
{
buttonLabel = "No Entity";
}
else if (invalid)
{
buttonLabel = "Invalid Entity";
}
@@ -245,9 +249,18 @@ void NetScriptPanel::Draw(Nuake::Entity entity)
}
ImGui::EndDragDropTarget();
}
}
ImGui::TableNextColumn();
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0));
std::string resetLabel = std::string(ICON_FA_UNDO) + "##Reset" + field.Name;
if (ImGui::Button(resetLabel.c_str()))
{
field.Value = field.DefaultValue;
}
ImGui::PopStyleColor();
}
}

View File

@@ -24,6 +24,11 @@ namespace Nuake
{
void Entity::AddChild(Entity ent)
{
if(!IsValid())
{
return;
}
if ((int)m_EntityHandle != ent.GetHandle())
{
ent.GetComponent<ParentComponent>().HasParent = true;

View File

@@ -571,7 +571,11 @@ namespace Nuake
auto entity = Entity{ e, this };
auto parentEntity = GetEntityByID(parentComponent.ParentID);
parentEntity.AddChild(entity);
if (entity.IsValid())
{
parentEntity.AddChild(entity);
}
}
// This will turn the deserialized entity ids into actual Entities.

View File

@@ -24,6 +24,12 @@ void ExceptionCallback(std::string_view InMessage)
Nuake::Logger::Log(message, ".net", Nuake::COMPILATION);
}
void MessageCallback(std::string_view message, Coral::MessageLevel level)
{
Nuake::Logger::Log(std::string(message), ".net", Nuake::VERBOSE);
}
namespace Nuake
{
ScriptingEngineNet::ScriptingEngineNet()
@@ -33,7 +39,8 @@ namespace Nuake
Coral::HostSettings settings =
{
.CoralDirectory = "",
.ExceptionCallback = ExceptionCallback
.MessageCallback = MessageCallback,
.ExceptionCallback = ExceptionCallback,
};
m_HostInstance = new Coral::HostInstance();
@@ -334,7 +341,6 @@ namespace Nuake
int32_t handle;
};
//exposedVar.Value = classInstance.GetFieldValue<EntityWrapper>(varName).id;
break;
}
}
@@ -353,28 +359,31 @@ namespace Nuake
}
else if (exposedVarUserValue.Type == NetScriptExposedVarType::Entity)
{
int entityId = std::any_cast<int>(exposedVarUserValue.Value);
Entity scriptEntity = entity.GetScene()->GetEntityByID(entityId);
if (scriptEntity.IsValid())
if (exposedVarUserValue.Value.has_value())
{
if (HasEntityScriptInstance(scriptEntity))
int entityId = std::any_cast<int>(exposedVarUserValue.Value);
Entity scriptEntity = entity.GetScene()->GetEntityByID(entityId);
if (scriptEntity.IsValid())
{
// In the case the entity has a script & instance, we pass that.
// This gives access to the objects scripts.
auto scriptInstance = GetEntityScript(scriptEntity);
classInstance.SetFieldValue<Coral::ManagedObject>(exposedVarUserValue.Name, scriptInstance);
if (HasEntityScriptInstance(scriptEntity))
{
// In the case the entity has a script & instance, we pass that.
// This gives access to the objects scripts.
auto scriptInstance = GetEntityScript(scriptEntity);
classInstance.SetFieldValue<Coral::ManagedObject>(exposedVarUserValue.Name, scriptInstance);
}
else
{
// In the case where the entity doesnt have an instance, we create one
auto newEntity = m_BaseEntityType.CreateInstance(scriptEntity.GetHandle());
classInstance.SetFieldValue<Coral::ManagedObject>(exposedVarUserValue.Name, newEntity);
}
}
else
{
// In the case where the entity doesnt have an instance, we create one
auto newEntity = m_BaseEntityType.CreateInstance(scriptEntity.GetHandle());
classInstance.SetFieldValue<Coral::ManagedObject>(exposedVarUserValue.Name, newEntity);
Logger::Log("Invalid entity exposed variable set", ".net", CRITICAL);
}
}
else
{
Logger::Log("Invalid entity exposed variable set", ".net", CRITICAL);
}
}
else
{

View File

@@ -188,13 +188,12 @@ namespace Nuake.Net
public static implicit operator bool(Entity entity)
{
bool isValid = false;
if(object.ReferenceEquals(entity, null))
if (object.ReferenceEquals(entity, null))
{
return false;
}
bool isValid;
unsafe
{
isValid = EntityIsValidIcall(entity.ECSHandle);