From 53f599a2389c146ed12e421af25262f573dcc46b Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 31 Jan 2023 17:28:24 +0800 Subject: [PATCH] Added RemoveScript(Script) for Scripts and GameObjects --- SHADE_Managed/src/Engine/GameObject.cxx | 7 +++++++ SHADE_Managed/src/Engine/GameObject.hxx | 6 ++++++ SHADE_Managed/src/Scripts/Script.cxx | 5 +++++ SHADE_Managed/src/Scripts/Script.hxx | 6 ++++++ SHADE_Managed/src/Scripts/ScriptStore.hxx | 2 +- 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/SHADE_Managed/src/Engine/GameObject.cxx b/SHADE_Managed/src/Engine/GameObject.cxx index 0e03a643..a78576cb 100644 --- a/SHADE_Managed/src/Engine/GameObject.cxx +++ b/SHADE_Managed/src/Engine/GameObject.cxx @@ -259,6 +259,13 @@ namespace SHADE ScriptStore::RemoveScript(entity); } + void GameObject::RemoveScript(Script^ script) + { + if (!valid) + throw gcnew System::NullReferenceException(); + ScriptStore::RemoveScript(entity, script); + } + /*---------------------------------------------------------------------------------*/ /* Scene Graph Functions */ /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Engine/GameObject.hxx b/SHADE_Managed/src/Engine/GameObject.hxx index 1ebfc250..054075ac 100644 --- a/SHADE_Managed/src/Engine/GameObject.hxx +++ b/SHADE_Managed/src/Engine/GameObject.hxx @@ -259,6 +259,12 @@ namespace SHADE /// Type of Scripts to remove. generic where T : ref class, Script void RemoveScript(); + /// + /// Removes a specific script from this script's parent. + /// + /// The script to remove. + /// True if successfully removed. False otherwise. + void RemoveScript(Script^ script); /*-----------------------------------------------------------------------------*/ /* Scene Graph Functions */ diff --git a/SHADE_Managed/src/Scripts/Script.cxx b/SHADE_Managed/src/Scripts/Script.cxx index 294f4096..4a84565f 100644 --- a/SHADE_Managed/src/Scripts/Script.cxx +++ b/SHADE_Managed/src/Scripts/Script.cxx @@ -126,6 +126,11 @@ namespace SHADE ScriptStore::RemoveScript(owner.GetEntity()); } + void Script::RemoveScript(Script^ script) + { + ScriptStore::RemoveScript(owner.GetEntity(), script); + } + Script::operator bool(Script^ s) { return s != nullptr; diff --git a/SHADE_Managed/src/Scripts/Script.hxx b/SHADE_Managed/src/Scripts/Script.hxx index 8fc36544..c2906bd4 100644 --- a/SHADE_Managed/src/Scripts/Script.hxx +++ b/SHADE_Managed/src/Scripts/Script.hxx @@ -198,6 +198,12 @@ namespace SHADE /// generic where T : ref class, Script void RemoveScript(); + /// + /// Removes a specific script from this script's parent. + /// + /// The script to remove. + /// True if successfully removed. False otherwise. + void RemoveScript(Script^ script); /*-----------------------------------------------------------------------------*/ /* Operator Overloads */ diff --git a/SHADE_Managed/src/Scripts/ScriptStore.hxx b/SHADE_Managed/src/Scripts/ScriptStore.hxx index f31836d8..77924203 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.hxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.hxx @@ -203,7 +203,7 @@ namespace SHADE generic where T : ref class, Script static void RemoveScript(Entity entity); /// - /// Removes a specific script from the + /// Removes a specific script from the specified entity. /// /// The entity to remove the script from. /// The script to remove.