<commit_before>package hxd.prefab;

@:keepSub
class Prefab {

	public var type(default, null) : String;
	public var name(default, set) : String;
	public var parent(default, set) : Prefab;
	public var source(default, set) : String;
	public var children(default, null) : Array<Prefab>;
	public var enabled : Bool = true;
	public var props : Any;

	public function new(?parent) {
		this.parent = parent;
		children = [];
	}

	function set_name(n) {
		return name = n;
	}

	function set_source(f) {
		return source = f;
	}

	function set_parent(p) {
		if( parent != null )
			parent.children.remove(this);
		parent = p;
		if( parent != null )
			parent.children.push(this);
		return p;
	}

	#if editor
	public function edit( ctx : hide.prefab.EditContext ) {
	}

	public function getHideProps() : hide.prefab.HideProps {
		return { icon : "question-circle", name : "Unknown" };
	}

	public function setSelected( ctx : hide.prefab.Context, b : Bool ) {
		var materials = ctx.shared.getMaterials(this);

		if( !b ) {
			for( m in materials ) {
				m.mainPass.stencil = null;
				m.removePass(m.getPass("outline"));
			}
			return;
		}

		var outlineShader = new h3d.shader.Outline();
		outlineShader.size = 0.12;
		outlineShader.distance = 0;
		outlineShader.color.setColor(0xffffff);

		var s1 = new h3d.mat.Stencil();
		s1.setFunc(Always, 1);
		s1.setOp(Keep, Keep, Replace);

		var s2 = new h3d.mat.Stencil();
		s2.setFunc(Greater, 1, 0xFF, 0);
		for( m in materials ) {
			m.mainPass.stencil = s1;
			var p = m.allocPass("outline");
			p.culling = None;
			p.depthWrite = false;
			p.addShader(outlineShader);
			p.stencil = s2;
		}
	}
	#end

	public inline function iterator() : Iterator<Prefab> {
		return children.iterator();
	}

	public function load( v : Dynamic ) {
		throw "Not implemented";
	}

	public function save() : {} {
		throw "Not implemented";
		return null;
	}

	public function makeInstance( ctx : Context ) : Context {
		return ctx;
	}

	public function updateInstance( ctx : Context, ?propName : String ) {
	}

	public function saveRec() : {} {
		var obj : Dynamic = save();
		obj.type = type;
		if( !enabled )
			obj.enabled = false;
		if( name != null )
			obj.name = name;
		if( source != null )
			obj.source = source;
		if( children.length > 0 )
			obj.children = [for( s in children ) s.saveRec()];
		if( props != null )
			obj.props = props;
		return obj;
	}

	public function reload( p : Dynamic ) {
		load(p);
		var childData : Array<Dynamic> = p.children;
		if( childData == null ) {
			if( this.children.length > 0 ) this.children = [];
			return;
		}
		var curChild = new Map();
		for( c in children )
			curChild.set(c.name, c);
		var newchild = [];
		for( v in childData ) {
			var name : String = v.name;
			var prev = curChild.get(name);
			if( prev != null && prev.type == v.type ) {
				curChild.remove(name);
				prev.reload(v);
				newchild.push(prev);<commit_msg>Prefab: don't overide props on save if already defined<commit_after>package hxd.prefab;

@:keepSub
class Prefab {

	public var type(default, null) : String;
	public var name(default, set) : String;
	public var parent(default, set) : Prefab;
	public var source(default, set) : String;
	public var children(default, null) : Array<Prefab>;
	public var enabled : Bool = true;
	public var props : Any;

	public function new(?parent) {
		this.parent = parent;
		children = [];
	}

	function set_name(n) {
		return name = n;
	}

	function set_source(f) {
		return source = f;
	}

	function set_parent(p) {
		if( parent != null )
			parent.children.remove(this);
		parent = p;
		if( parent != null )
			parent.children.push(this);
		return p;
	}

	#if editor
	public function edit( ctx : hide.prefab.EditContext ) {
	}

	public function getHideProps() : hide.prefab.HideProps {
		return { icon : "question-circle", name : "Unknown" };
	}

	public function setSelected( ctx : hide.prefab.Context, b : Bool ) {
		var materials = ctx.shared.getMaterials(this);

		if( !b ) {
			for( m in materials ) {
				m.mainPass.stencil = null;
				m.removePass(m.getPass("outline"));
			}
			return;
		}

		var outlineShader = new h3d.shader.Outline();
		outlineShader.size = 0.12;
		outlineShader.distance = 0;
		outlineShader.color.setColor(0xffffff);

		var s1 = new h3d.mat.Stencil();
		s1.setFunc(Always, 1);
		s1.setOp(Keep, Keep, Replace);

		var s2 = new h3d.mat.Stencil();
		s2.setFunc(Greater, 1, 0xFF, 0);
		for( m in materials ) {
			m.mainPass.stencil = s1;
			var p = m.allocPass("outline");
			p.culling = None;
			p.depthWrite = false;
			p.addShader(outlineShader);
			p.stencil = s2;
		}
	}
	#end

	public inline function iterator() : Iterator<Prefab> {
		return children.iterator();
	}

	public function load( v : Dynamic ) {
		throw "Not implemented";
	}

	public function save() : {} {
		throw "Not implemented";
		return null;
	}

	public function makeInstance( ctx : Context ) : Context {
		return ctx;
	}

	public function updateInstance( ctx : Context, ?propName : String ) {
	}

	public function saveRec() : {} {
		var obj : Dynamic = save();
		obj.type = type;
		if( !enabled )
			obj.enabled = false;
		if( name != null )
			obj.name = name;
		if( source != null )
			obj.source = source;
		if( children.length > 0 )
			obj.children = [for( s in children ) s.saveRec()];
		if( props != null && obj.props == null )
			obj.props = props;
		return obj;
	}

	public function reload( p : Dynamic ) {
		load(p);
		var childData : Array<Dynamic> = p.children;
		if( childData == null ) {
			if( this.children.length > 0 ) this.children = [];
			return;
		}
		var curChild = new Map();
		for( c in children )
			curChild.set(c.name, c);
		var newchild = [];
		for( v in childData ) {
			var name : String = v.name;
			var prev = curChild.get(name);
			if( prev != null && prev.type == v.type ) {
				curChild.remove(name);
				prev.reload(v);
				newchild.push(prev);
{'fraction_non_alphanumeric': 0.14195637355146556, 'fraction_numerical': 0.007157464212678937, 'mean_word_length': 3.156515580736544, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '5859877', 'n_tokens_mistral': 2350, 'n_tokens_neox': 2059, 'n_words': 557}