diff --git a/src/core/composable_component/mainEditor/composable_component/inspector/utils/InspectorRemoveComponentUtils.re b/src/core/composable_component/mainEditor/composable_component/inspector/utils/InspectorRemoveComponentUtils.re index dc4cbe363..f82a7aeb0 100755 --- a/src/core/composable_component/mainEditor/composable_component/inspector/utils/InspectorRemoveComponentUtils.re +++ b/src/core/composable_component/mainEditor/composable_component/inspector/utils/InspectorRemoveComponentUtils.re @@ -22,7 +22,7 @@ let _removeCameraGroup = (currentSceneTreeNode, (editorState, engineState)) => ), ); -let _removeArcballCameraControllerGroup = +let _removeArcballCameraController = (currentSceneTreeNode, (editorState, engineState)) => { let arcballCameraController = engineState @@ -37,6 +37,17 @@ let _removeArcballCameraControllerGroup = ); }; +let _removeScript = (currentSceneTreeNode, (editorState, engineState)) => { + let script = + engineState + |> GameObjectComponentEngineService.unsafeGetScriptComponent( + currentSceneTreeNode, + ); + + (editorState, engineState) + |> GameObjectLogicService.disposeScript(currentSceneTreeNode, script); +}; + let removeComponentByType = (type_, currentSceneTreeNode, (editorState, engineState)) => switch (type_) { @@ -76,10 +87,11 @@ let removeComponentByType = | CameraGroup => _removeCameraGroup(currentSceneTreeNode, (editorState, engineState)) | ArcballCameraController => - _removeArcballCameraControllerGroup( + _removeArcballCameraController( currentSceneTreeNode, (editorState, engineState), ) + | Script => _removeScript(currentSceneTreeNode, (editorState, engineState)) | _ => ConsoleUtils.error( LogUtils.buildErrorMessage( diff --git a/src/service/stateTuple/logic/GameObjectLogicService.re b/src/service/stateTuple/logic/GameObjectLogicService.re index 811fdda6a..e926d95c1 100755 --- a/src/service/stateTuple/logic/GameObjectLogicService.re +++ b/src/service/stateTuple/logic/GameObjectLogicService.re @@ -201,6 +201,19 @@ let disposeArcballCameraController = ), ); +let disposeScript = (gameObject, component, (editorState, engineState)) => ( + editorState + |> InspectorEditorService.removeComponentTypeToMap( + gameObject, + InspectorComponentType.Script, + ), + GameObjectComponentEngineService.disposeScriptComponent( + gameObject, + component, + engineState, + ), +); + let isCurrentSceneTreeNodeSceneGameObject = ((editorState, engineState)) => switch (editorState |> SceneTreeEditorService.getCurrentSceneTreeNode) { | None => false diff --git a/test/integration/inspector/atom_component/addableComponent/__snapshots__/addableComponent_removeComponent_test.js.snap b/test/integration/inspector/atom_component/addableComponent/__snapshots__/addableComponent_removeComponent_test.js.snap index b9780d376..fe6b72bcc 100755 --- a/test/integration/inspector/atom_component/addableComponent/__snapshots__/addableComponent_removeComponent_test.js.snap +++ b/test/integration/inspector/atom_component/addableComponent/__snapshots__/addableComponent_removeComponent_test.js.snap @@ -1955,3 +1955,713 @@ exports[`AddableComponent remove component test remove directionLight gameObject `; + +exports[`AddableComponent remove component test remove script component test snapshot test remove script component, should remove from inspector 1`] = ` +
+
+
+
+
+ + Name + +
+
+ +
+
+
+
+
+
+ +
+
+ Transform +
+
+
+
+
+ Position +
+
+
+
+ X +
+
+ +
+
+
+
+ Y +
+
+ +
+
+
+
+ Z +
+
+ +
+
+
+
+
+
+ Rotation +
+
+
+
+ X +
+
+ +
+
+
+
+ Y +
+
+ +
+
+
+
+ Z +
+
+ +
+
+
+
+
+
+ Scale +
+
+
+
+ X +
+
+ +
+
+
+
+ Y +
+
+ +
+
+
+
+ Z +
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+ Render Group +
+
+ +
+
+
+
+
+ Mesh Render +
+
+
+
+
+
+ + Draw Mode + +
+
+ +
+
+
+
+
+
+
+ Material +
+
+
+
+
+
+ Material +
+
+
+
+ Wonder-Default-Light-Material +
+
+ +
+
+
+
+
+
+
+ + Type + +
+
+ +
+
+
+
+
+
+ Diffuse Color +
+
+
+
+ +
+
+
+
+
+ Diffuse Map +
+
+
+
+
+ +
+
+
+
+ Shininess +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ Geometry +
+
+ +
+
+
+
+
+ Geometry +
+
+
+
+ Wonder-Default-Cube +
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+`; diff --git a/test/integration/inspector/atom_component/addableComponent/addableComponent_removeComponent_test.re b/test/integration/inspector/atom_component/addableComponent/addableComponent_removeComponent_test.re index 8677fc1db..c38410c27 100755 --- a/test/integration/inspector/atom_component/addableComponent/addableComponent_removeComponent_test.re +++ b/test/integration/inspector/atom_component/addableComponent/addableComponent_removeComponent_test.re @@ -288,6 +288,57 @@ let _ = }); }); + describe("test remove script component", () => { + beforeEach(() => { + MainEditorSceneTool.createDefaultScene( + sandbox, + MainEditorSceneTool.setFirstCubeToBeCurrentSceneTreeNode, + ); + + CurrentSelectSourceEditorService.setCurrentSelectSource( + SceneTreeWidgetService.getWidget(), + ) + |> StateLogicService.getAndSetEditorState; + + MainEditorInspectorAddComponentTool.addScriptComponent(); + }); + + describe("test snapshot", () => { + test("test remove script component, should remove from inspector", () => { + MainEditorInspectorRemoveComponentTool.removeScriptComponent(); + + BuildComponentTool.buildInspectorComponent( + TestTool.buildEmptyAppState(), + InspectorTool.buildFakeAllShowComponentConfig(), + ) + |> ReactTestTool.createSnapshotAndMatch; + }); + + describe("test logic", () => { + test( + "test if not remove script component, current gameObject should has it", + () => + GameObjectComponentEngineService.hasScriptComponent( + GameObjectTool.unsafeGetCurrentSceneTreeNode(), + ) + |> StateLogicService.getEngineStateToGetData + |> expect == true + ); + test( + "test click remove script component, current gameObject shouldn't has it", + () => { + MainEditorInspectorRemoveComponentTool.removeScriptComponent(); + + GameObjectComponentEngineService.hasScriptComponent( + GameObjectTool.unsafeGetCurrentSceneTreeNode(), + ) + |> StateLogicService.getEngineStateToGetData + |> expect == false; + }); + }); + }); + }); + describe("deal with specific case", () => { beforeEach(() => MainEditorSceneTool.createDefaultScene( diff --git a/test/integration/inspector/atom_component/addableComponent/tool/MainEditorInspectorRemoveComponentTool.re b/test/integration/inspector/atom_component/addableComponent/tool/MainEditorInspectorRemoveComponentTool.re index 4233630db..3c122d13d 100755 --- a/test/integration/inspector/atom_component/addableComponent/tool/MainEditorInspectorRemoveComponentTool.re +++ b/test/integration/inspector/atom_component/addableComponent/tool/MainEditorInspectorRemoveComponentTool.re @@ -68,4 +68,17 @@ let removeArcballCameraControllerComponent = (uiState, dispatchFunc), gameObject, InspectorComponentType.ArcballCameraController, + ); + +let removeScriptComponent = + ( + ~uiState=TestTool.buildEmptyAppState(), + ~dispatchFunc=TestTool.getDispatch(), + ~gameObject=GameObjectTool.unsafeGetCurrentSceneTreeNode(), + (), + ) => + _removeComponent( + (uiState, dispatchFunc), + gameObject, + InspectorComponentType.Script, ); \ No newline at end of file