diff --git a/Editor/src/ComponentsPanel/NetScriptPanel.cpp b/Editor/src/ComponentsPanel/NetScriptPanel.cpp index 87e6ee27..af8f504f 100644 --- a/Editor/src/ComponentsPanel/NetScriptPanel.cpp +++ b/Editor/src/ComponentsPanel/NetScriptPanel.cpp @@ -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(); } } diff --git a/Nuake/src/Scene/Entities/Entity.cpp b/Nuake/src/Scene/Entities/Entity.cpp index b221ac63..58a6c83f 100644 --- a/Nuake/src/Scene/Entities/Entity.cpp +++ b/Nuake/src/Scene/Entities/Entity.cpp @@ -24,6 +24,11 @@ namespace Nuake { void Entity::AddChild(Entity ent) { + if(!IsValid()) + { + return; + } + if ((int)m_EntityHandle != ent.GetHandle()) { ent.GetComponent().HasParent = true; diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index 410d4996..b9d8eb69 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -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. diff --git a/Nuake/src/Scripting/ScriptingEngineNet.cpp b/Nuake/src/Scripting/ScriptingEngineNet.cpp index 08274286..14f954c5 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.cpp +++ b/Nuake/src/Scripting/ScriptingEngineNet.cpp @@ -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(varName).id; break; } } @@ -353,28 +359,31 @@ namespace Nuake } else if (exposedVarUserValue.Type == NetScriptExposedVarType::Entity) { - int entityId = std::any_cast(exposedVarUserValue.Value); - Entity scriptEntity = entity.GetScene()->GetEntityByID(entityId); - if (scriptEntity.IsValid()) + if (exposedVarUserValue.Value.has_value()) { - if (HasEntityScriptInstance(scriptEntity)) + int entityId = std::any_cast(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(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(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(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(exposedVarUserValue.Name, newEntity); + Logger::Log("Invalid entity exposed variable set", ".net", CRITICAL); } } - else - { - Logger::Log("Invalid entity exposed variable set", ".net", CRITICAL); - } } else { diff --git a/NuakeNet/src/Entity.cs b/NuakeNet/src/Entity.cs index 8c50abb3..e3120a63 100644 --- a/NuakeNet/src/Entity.cs +++ b/NuakeNet/src/Entity.cs @@ -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);