<commit_before>package hxd.prefab;

@:final class Context {

	public var local2d : h2d.Object;
	public var local3d : h3d.scene.Object;
	public var shared : ContextShared;
	public var cleanup : Void -> Void;
	public var custom : Dynamic;
	public var isRef : Bool = false;

	public function new() {
	}

	public function init() {
		if( shared == null )
			shared = new ContextShared();
		local2d = shared.root2d;
		local3d = shared.root3d;
	}

	public function clone( p : Prefab ) {
		var c = new Context();
		c.shared = shared;
		c.local2d = local2d;
		c.local3d = local3d;
		c.custom = custom;
		c.isRef = isRef;
		if( p != null ) {
			if(!isRef)
				shared.contexts.set(p, c);
			else {
				if(!shared.references.exists(p))
					shared.references.set(p, [c])
				else
					shared.references[p].push(c);
			}
		}
		return c;
	}

	public function loadModel( path : String ) {
		return shared.loadModel(path);
	}

	public function loadAnimation( path : String ) {
		return shared.loadAnimation(path);
	}

	public function loadTexture( path : String ) {
		return shared.loadTexture(path);
	}

	public function loadShader( name : String ) {
		return shared.loadShader(name);
	}

	public function locateObject( path : String ) {
		if( path == null )
			return null;
		var parts = path.split(".");
		var root = shared.root3d;
		while( parts.length > 0 ) {
			var v = null;
			var pname = parts.shift();
			for( o in root )
				if( o.name == pname ) {
					v = o;
					break;
				}
			if( v == null ) {
				v = root.getObjectByName(pname);
				if( v != null && v.parent != root ) v = null;
			}
			if( v == null ) {
				var parts2 = path.split(".");
				for( i in 0...parts.length ) parts2.pop();
				shared.onError("Object not found " + parts2.join("."));
				return null;
			}
			root = v;
		}
		return root;
	}

}<commit_msg>Update locateObject for context<commit_after>package hxd.prefab;

@:final class Context {

	public var local2d : h2d.Object;
	public var local3d : h3d.scene.Object;
	public var shared : ContextShared;
	public var cleanup : Void -> Void;
	public var custom : Dynamic;
	public var isRef : Bool = false;

	public function new() {
	}

	public function init() {
		if( shared == null )
			shared = new ContextShared();
		local2d = shared.root2d;
		local3d = shared.root3d;
	}

	public function clone( p : Prefab ) {
		var c = new Context();
		c.shared = shared;
		c.local2d = local2d;
		c.local3d = local3d;
		c.custom = custom;
		c.isRef = isRef;
		if( p != null ) {
			if(!isRef)
				shared.contexts.set(p, c);
			else {
				if(!shared.references.exists(p))
					shared.references.set(p, [c])
				else
					shared.references[p].push(c);
			}
		}
		return c;
	}

	public function loadModel( path : String ) {
		return shared.loadModel(path);
	}

	public function loadAnimation( path : String ) {
		return shared.loadAnimation(path);
	}

	public function loadTexture( path : String ) {
		return shared.loadTexture(path);
	}

	public function loadShader( name : String ) {
		return shared.loadShader(name);
	}

	public function locateObject( path : String ) {
		if( path == null )
			return null;
		var parts = path.split(".");
		var root = shared.root3d;
		while( parts.length > 0 ) {
			var v = null;
			var pname = parts.shift();
			for( o in root )
				if( o.name == pname ) {
					v = o;
					break;
				}
			if( v == null ) {
				v = root.getObjectByName(pname);
				//if( v != null && v.parent != root ) v = null; ??
			}
			if( v == null ) {
				var parts2 = path.split(".");
				for( i in 0...parts.length ) parts2.pop();
				shared.onError("Object not found " + parts2.join("."));
				return null;
			}
			root = v;
		}
		return root;
	}

}
{'fraction_non_alphanumeric': 0.1414141414141414, 'fraction_numerical': 0.009828009828009828, 'mean_word_length': 2.7349643221202853, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6500035', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1297, 'n_words': 355}