From 5e3472c2563ab5d0170123a7415766b3c6bbe15a Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Thu, 5 Sep 2024 00:52:55 -0400 Subject: [PATCH] Fixed Coral crash with base type classes, temp fix for logs crash + added light color param to C# api --- Editor/src/Commands/Commands/Commands.cpp | 6 ++++++ Editor/src/Windows/EditorInterface.cpp | 8 ++++---- Nuake/src/Scripting/NetModules/SceneNetAPI.cpp | 13 +++++++++++++ Nuake/src/Scripting/ScriptingEngineNet.cpp | 3 ++- NuakeNet/src/Components.cs | 12 ++++++++++-- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Editor/src/Commands/Commands/Commands.cpp b/Editor/src/Commands/Commands/Commands.cpp index a180c88d..e50d9ba9 100644 --- a/Editor/src/Commands/Commands/Commands.cpp +++ b/Editor/src/Commands/Commands/Commands.cpp @@ -42,6 +42,12 @@ namespace NuakeEditor { const std::string& cleanProjectName = String::Sanitize(mProject->Name); const std::string& gameConfigFolderPath = mProject->TrenchbroomPath + "/../games/" + cleanProjectName + "/"; + + if (!FileSystem::DirectoryExists(gameConfigFolderPath)) + { + FileSystem::MakeDirectory(gameConfigFolderPath); + } + const std::string& gameConfigFilePath = gameConfigFolderPath + "GameConfig.cfg"; FileSystem::BeginWriteFile(gameConfigFilePath, true); diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 72f3f22e..9dd0d15d 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -3055,10 +3055,10 @@ namespace Nuake { DrawMenuBars(); int i = 0; - if (Logger::GetLogCount() > 0 && Logger::GetLogs()[Logger::GetLogCount() - 1].type == COMPILATION) - { - SetStatusMessage(std::string(ICON_FA_EXCLAMATION_TRIANGLE) + " An unhandled exception occured in your script. See logs for more details.", Color(1.0f, 0.1f, 0.1f, 1.0f)); - } + //if (Logger::GetLogCount() > 0 && Logger::GetLogs()[Logger::GetLogCount() - 1].type == COMPILATION) + //{ + // SetStatusMessage(std::string(ICON_FA_EXCLAMATION_TRIANGLE) + " An unhandled exception occured in your script. See logs for more details.", Color(1.0f, 0.1f, 0.1f, 1.0f)); + //} DrawStatusBar(); diff --git a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp index f8c88661..a4fc8535 100644 --- a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp +++ b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp @@ -334,6 +334,17 @@ namespace Nuake { Logger::Log("Set light intensity with id: " + std::to_string(intensity)); } + void LightSetColor(int entityId, float r, float g, float b) + { + Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() }; + + if (entity.IsValid() && entity.HasComponent()) + { + auto& component = entity.GetComponent(); + component.Color = Color(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f); + } + } + Coral::Array CameraGetDirection(int entityId) { Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() }; @@ -557,6 +568,7 @@ namespace Nuake { // Lights RegisterMethod("LightComponent.GetLightIntensityIcall", &LightGetIntensity); RegisterMethod("LightComponent.SetLightIntensityIcall", &LightSetIntensity); + RegisterMethod("LightComponent.SetLightColorIcall", &LightSetColor); // Camera RegisterMethod("CameraComponent.GetDirectionIcall", &CameraGetDirection); @@ -568,6 +580,7 @@ namespace Nuake { RegisterMethod("CharacterControllerComponent.IsOnGroundIcall", &IsOnGround); RegisterMethod("CharacterControllerComponent.GetGroundVelocityIcall", &GetGroundVelocity); RegisterMethod("CharacterControllerComponent.GetGroundNormalIcall", &GetGroundNormal); + // Skinned RegisterMethod("SkinnedModelComponent.PlayIcall", &Play); diff --git a/Nuake/src/Scripting/ScriptingEngineNet.cpp b/Nuake/src/Scripting/ScriptingEngineNet.cpp index 2203bf9b..d7586e9c 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.cpp +++ b/Nuake/src/Scripting/ScriptingEngineNet.cpp @@ -311,6 +311,7 @@ namespace Nuake m_GameAssembly = m_LoadContext.LoadAssembly(absoluteAssemblyPath); m_PrefabType = m_GameAssembly.GetType("Nuake.Net.Prefab"); + auto entityScriptType = m_GameAssembly.GetType("Nuake.Net.Entity"); auto& exposedFieldAttributeType = m_GameAssembly.GetType("Nuake.Net.ExposedAttribute"); auto& brushScriptAttributeType = m_GameAssembly.GetType("Nuake.Net.BrushScript"); auto& pointScriptAttributeType = m_GameAssembly.GetType("Nuake.Net.PointScript"); @@ -343,7 +344,7 @@ namespace Nuake } } - if (type->GetBaseType()) + if (type->IsSubclassOf(entityScriptType)) { const std::string baseTypeName = std::string(type->GetBaseType().GetFullName()); if (baseTypeName != "Nuake.Net.Entity") diff --git a/NuakeNet/src/Components.cs b/NuakeNet/src/Components.cs index 3962381d..147fea1a 100644 --- a/NuakeNet/src/Components.cs +++ b/NuakeNet/src/Components.cs @@ -115,7 +115,7 @@ namespace Nuake.Net { internal static unsafe delegate* GetLightIntensityIcall; internal static unsafe delegate* SetLightIntensityIcall; - + internal static unsafe delegate* SetLightColorIcall; public enum LightType { Directional, @@ -148,7 +148,15 @@ namespace Nuake.Net } } - public Color Color { get; set; } + public Color Color + { + get { return Color; } + set + { + unsafe { SetLightColorIcall(EntityID, (float)value.R, (float)value.G, (float)value.B); } + } + } + public bool CastShadows { get; set; } public bool Volumetric { get; set; } public bool SyncWithSky { get; set; }