From b04565c9dcb557766f2b5be4095d0141df620265 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Mon, 31 Oct 2022 15:07:10 +0800 Subject: [PATCH] Added implementation for scripts and component functions for scripts --- SHADE_Managed/src/Components/Component.cxx | 5 ++++ SHADE_Managed/src/Components/Component.hxx | 9 ++++++++ SHADE_Managed/src/Scripts/Script.cxx | 27 +++++++++++----------- SHADE_Managed/src/Scripts/Script.hxx | 9 ++++++++ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/SHADE_Managed/src/Components/Component.cxx b/SHADE_Managed/src/Components/Component.cxx index a6afc5cc..7f56fad3 100644 --- a/SHADE_Managed/src/Components/Component.cxx +++ b/SHADE_Managed/src/Components/Component.cxx @@ -67,6 +67,11 @@ namespace SHADE ScriptStore::RemoveScript(owner.GetEntity()); } + BaseComponent::operator bool(BaseComponent^ c) + { + return c != nullptr; + } + /*---------------------------------------------------------------------------------*/ /* Constructors */ /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Components/Component.hxx b/SHADE_Managed/src/Components/Component.hxx index 670e4e21..5ffa3952 100644 --- a/SHADE_Managed/src/Components/Component.hxx +++ b/SHADE_Managed/src/Components/Component.hxx @@ -101,6 +101,15 @@ namespace SHADE generic where T : ref class, Script void RemoveScript(); + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a component is null. + /// + /// Component to check. + static operator bool(BaseComponent^ c); + protected: /*-----------------------------------------------------------------------------*/ /* Constructors */ diff --git a/SHADE_Managed/src/Scripts/Script.cxx b/SHADE_Managed/src/Scripts/Script.cxx index ecd27325..d4004e03 100644 --- a/SHADE_Managed/src/Scripts/Script.cxx +++ b/SHADE_Managed/src/Scripts/Script.cxx @@ -18,6 +18,8 @@ of DigiPen Institute of Technology is prohibited. #include "Script.hxx" // Project Headers #include "Utility/Debug.hxx" +#include "ScriptStore.hxx" +#include "Engine/ECS.hxx" namespace SHADE { @@ -49,8 +51,7 @@ namespace SHADE generic void Script::RemoveComponent() { - throw gcnew System::NotImplementedException; - //ECS::RemoveComponent(owner.GetNativeEntity()); + owner.RemoveComponent(); } /*---------------------------------------------------------------------------------*/ @@ -59,37 +60,37 @@ namespace SHADE generic T Script::AddScript() { - throw gcnew System::NotImplementedException; - //return ScriptStore::AddScript(owner.GetEntity()); + return ScriptStore::AddScript(owner.GetEntity()); } generic T Script::GetScript() { - throw gcnew System::NotImplementedException; - //return ScriptStore::GetScript(owner.GetEntity()); + return ScriptStore::GetScript(owner.GetEntity()); } generic T Script::GetScriptInChildren() { - throw gcnew System::NotImplementedException; - //return ScriptStore::GetScriptInChildren(owner.GetEntity()); + return ScriptStore::GetScriptInChildren(owner.GetEntity()); } generic System::Collections::Generic::IEnumerable^ Script::GetScripts() { - throw gcnew System::NotImplementedException; - //return ScriptStore::GetScripts(owner.GetEntity()); + return ScriptStore::GetScripts(owner.GetEntity()); } generic void Script::RemoveScript() { - throw gcnew System::NotImplementedException; - //ScriptStore::RemoveScript(owner.GetEntity()); + ScriptStore::RemoveScript(owner.GetEntity()); } - + + Script::operator bool(Script^ s) + { + return s != nullptr; + } + /*---------------------------------------------------------------------------------*/ /* "All-time" Lifecycle Functions */ /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Scripts/Script.hxx b/SHADE_Managed/src/Scripts/Script.hxx index cef9f4cd..bd336726 100644 --- a/SHADE_Managed/src/Scripts/Script.hxx +++ b/SHADE_Managed/src/Scripts/Script.hxx @@ -153,6 +153,15 @@ namespace SHADE generic where T : ref class, Script void RemoveScript(); + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a component is null. + /// + /// Component to check. + static operator bool(Script^ s); + internal: /*-----------------------------------------------------------------------------*/ /* "All-Time" Lifecycle Functions */