Ver código fonte

added ContextShared.filterChildren to intercept make() recursively

Nicolas Cannasse 4 anos atrás
pai
commit
943253380e

+ 7 - 0
hrt/prefab/ContextShared.hx

@@ -14,6 +14,12 @@ class ContextShared {
 	public var currentPath : String;
 	public var editorDisplay : Bool;
 
+	/**
+		When make() is called on prefab, it will call filterChildren on
+		each child with current context and only make() it if returns true.
+	 **/
+	public var filterChildren : Context -> Prefab -> Bool;
+
 	/**
 		If is a reference to another prefab file, this is the parent prefab.
 		See refContexts for children.
@@ -102,6 +108,7 @@ class ContextShared {
 		sh.parent = { shared : this, prefab : prefab };
 		sh.cache = cache;
 		sh.shaderCache = shaderCache;
+		sh.filterChildren = filterChildren;
 		// own bakedData
 		// own refsContext
 		return sh;

+ 6 - 1
hrt/prefab/Prefab.hx

@@ -237,10 +237,15 @@ class Prefab {
 		}
 		ctx = makeInstance(ctx);
 		for( c in children )
-			c.make(ctx);
+			if( filterChildren(ctx, c) )
+				c.make(ctx);
 		return ctx;
 	}
 
+	function filterChildren( ctx : Context, p : Prefab ) {
+		return ctx.shared.filterChildren == null || ctx.shared.filterChildren(ctx, p);
+	}
+
 	/**
 	 	If the prefab `props` represent CDB data, returns the sheet name of it, or null.
 	 **/

+ 7 - 4
hrt/prefab/Reference.hx

@@ -87,7 +87,8 @@ class Reference extends Object3D {
 			ctx = super.makeInstance(ctx);
 			var prevShared = ctx.shared;
 			ctx.shared = ctx.shared.cloneRef(this, refpath.substr(1));
-			p.make(ctx);
+			if( filterChildren(ctx, p) )
+				p.make(ctx);
 			ctx.shared = prevShared;
 
 			#if editor
@@ -106,9 +107,11 @@ class Reference extends Object3D {
 		else {
 			ctx = ctx.clone(this);
 			ctx.isSceneReference = true;
-			var refCtx = p.make(ctx);
-			ctx.local3d = refCtx.local3d;
-			updateInstance(ctx);
+			if( filterChildren(ctx,p) ) {
+				var refCtx = p.make(ctx);
+				ctx.local3d = refCtx.local3d;
+				updateInstance(ctx);
+			}
 		}
 
 		return ctx;

+ 2 - 0
hrt/prefab/fx/Emitter.hx

@@ -1068,6 +1068,8 @@ class Emitter extends Object3D {
 	function refreshChildren(ctx: Context) {
 		// Don't make all children, which are used to setup particles
 		for( c in children ) {
+			if( !filterChildren(ctx,c) )
+				continue;
 			var shader = Std.downcast(c, hrt.prefab.Shader);
 			if( shader != null )
 				shader.make(ctx);

+ 3 - 2
hrt/prefab/fx/FX.hx

@@ -399,9 +399,10 @@ class FX extends BaseFX {
 		#else
 		var root = getFXRoot(ctx, this);
 		if(root != null){
-			for( c in root.children ){
+			for( c in root.children ) {
 				var co = Std.downcast(c , Constraint);
-				if(co == null) c.make(ctx);
+				if( co == null && filterChildren(ctx,c) )
+					c.make(ctx);
 			}
 		}
 		else

+ 6 - 8
hrt/prefab/fx/FX2D.hx

@@ -137,7 +137,7 @@ class FX2DAnimation extends h2d.Object {
 					em.setTime(time);
 			}
 		}
-		
+
 		Event.updateEvents(events, time, prevTime);
 
 		this.prevTime = localTime;
@@ -253,13 +253,11 @@ class FX2D extends BaseFX {
 		super.make(ctx);
 		#else
 		var root = getFXRoot(ctx, this);
-		if(root != null){
-			for( c in root.children ){
-				var co = Std.downcast(c , Constraint);
-				if(co == null) c.make(ctx);
-			}
-		}
-		else
+		if( root != null ) {
+			for( c in root.children )
+				if( filterChildren(ctx, c) )
+					c.make(ctx);
+		} else
 			super.make(ctx);
 		#end
 		fxanim.init(ctx, this);