소스 검색

Merge pull request #368 from AtomicGameEngine/JME-ATOMIC-352

Add recursive option to node.getJSComponent
JoshEngebretson 10 년 전
부모
커밋
907306e30a
2개의 변경된 파일8개의 추가작업 그리고 3개의 파일을 삭제
  1. 2 2
      Script/Packages/Atomic/Scene.json
  2. 6 1
      Source/AtomicJS/Javascript/JSScene.cpp

+ 2 - 2
Script/Packages/Atomic/Scene.json

@@ -41,7 +41,7 @@
 			"getComponents(componentType?:string, recursive?:boolean):Component[];",
 			"getChildAtIndex(index:number):Node;",
 			"createJSComponent(name:string, args?:{});",
-			"getJSComponent(name:string):JSComponent;",
+			"getJSComponent(name:string, recursive?:boolean):JSComponent;",
 			"createChildPrefab(childName:string, prefabPath:string):Node;",
 			"loadPrefab(prefabPath:string):boolean;"
 		],
@@ -58,7 +58,7 @@
 			"function getComponents(?componentType:String, ?recursive:Bool):Array<Component>;",
 			"function getChildAtIndex(index:UInt):Node;",
 			"function createJSComponent(name:String, ?args:Dynamic):JSComponent;",
-			"function getJSComponent(name:String):JSComponent;",
+			"function getJSComponent(name:String, ?recursive:Bool):JSComponent;",
 			"function createChildPrefab(childName:String, prefabPath:String):Node;",
 			"function loadPrefab(prefabPath:String):Bool;"
 		],

+ 6 - 1
Source/AtomicJS/Javascript/JSScene.cpp

@@ -80,11 +80,16 @@ static int Node_GetJSComponent(duk_context* ctx)
 {
     String path = duk_require_string(ctx, 0);
 
+    bool recursive = false;
+    if (duk_get_top(ctx) == 2)
+        if (duk_get_boolean(ctx, 1))
+            recursive = true;
+
     duk_push_this(ctx);
     Node* node = js_to_class_instance<Node>(ctx, -1, 0);
 
     PODVector<JSComponent*> components;
-    node->GetComponents<JSComponent>(components, true);
+    node->GetComponents<JSComponent>(components, recursive);
 
     for (unsigned i = 0; i < components.Size(); i++)
     {