Skip to content

Commit 0a194e5

Browse files
[prefab] Remove parent setter
Only one way to setup prefab hierarchy now with addChild() Migration notes : `a.parent = b` -> `b.addChild(a)`
1 parent a2caf3f commit 0a194e5

4 files changed

Lines changed: 10 additions & 21 deletions

File tree

hrt/prefab/Model.hx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class Model extends Object3D {
132132
toAdd.props = toRemove.props;
133133
toAdd.setTransform(toRemove.getTransform());
134134
parent.addChildAt(toAdd, idx);
135-
@:bypassAccessor toAdd.parent = parent;
136135
@:privateAccess ctx.scene.editor.rebuild(toAdd);
137136
}
138137

hrt/prefab/Prefab.hx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Prefab {
104104
/**
105105
The parent of the prefab in the tree view
106106
**/
107-
public var parent(default, set) : Prefab;
107+
public var parent(default, null) : Prefab;
108108

109109
/**
110110
Infos shared by all the prefabs in a given prefab hierarchy (but not by references)
@@ -125,7 +125,7 @@ class Prefab {
125125
}
126126
}
127127
else
128-
this.parent = parent;
128+
parent.addChild(this);
129129
}
130130

131131
function get_type() {
@@ -135,11 +135,6 @@ class Prefab {
135135

136136
inline function get_children() return _children ?? NULL_CHILDREN;
137137

138-
function set_parent(p) {
139-
handleParenting(this, this.parent, p, p?.children.length ?? 0);
140-
return p;
141-
}
142-
143138
/**
144139
Instanciate this prefab. If `newContextShared` is given or if `this.shared.isInstance` is false,
145140
this prefab is cloned and then the clone is instanciated and returned.
@@ -208,15 +203,10 @@ class Prefab {
208203

209204
inst.copy(this);
210205
if (withChildren && children.length > 0) {
211-
inst._children = [];
212-
inst._children.resize(children.length);
213206
for (idx => child in children) {
214207
var cloneChild = child.clone(null, sh);
215208

216-
// "parent" setter pushes into children, but we don't want that
217-
// as we have prealocated the array children
218-
@:bypassAccessor cloneChild.parent = inst;
219-
inst._children[idx] = cloneChild;
209+
inst.addChildAt(cloneChild, idx);
220210
}
221211
}
222212

@@ -341,7 +331,9 @@ class Prefab {
341331
}
342332

343333
public function remove() : Void {
344-
parent = null;
334+
if (parent != null) {
335+
parent.removeChild(this);
336+
}
345337
}
346338

347339
/**
@@ -852,7 +844,7 @@ class Prefab {
852844
oldParent._children = null;
853845
}
854846
}
855-
@:bypassAccessor child.parent = newParent;
847+
child.parent = newParent;
856848
if (newParent != null) {
857849
if (newParent._children == null)
858850
newParent._children = [];

hrt/prefab/Reference.hx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,7 @@ class Reference extends Object3D {
593593
break;
594594
}
595595
editor.removeInstance(selectedRef, false);
596-
@:bypassAccessor clones[i].parent = parents[i];
597-
@:bypassAccessor selectedRef.parent = null;
596+
selectedRef.remove();
598597
newSelection.push(clones[i]);
599598
}
600599
else {
@@ -607,8 +606,7 @@ class Reference extends Object3D {
607606
break;
608607
}
609608
editor.removeInstance(clones[i], false);
610-
@:bypassAccessor clones[i].parent = null;
611-
@:bypassAccessor selectedRef.parent = parents[i];
609+
clones[i].remove();
612610
newSelection.push(selectedRef);
613611
}
614612
editor.queueRebuild(parents[i]);

hrt/prefab/fx/ShaderTarget.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ShaderTargetObj extends h3d.scene.Object {
1111
while ( i < obj.children.length ) {
1212
var c = obj.children[i];
1313
if ( (c.enabled && !c.editorOnly) && (Std.isOfType(c, Shader) || Std.isOfType(c, Material) || Std.isOfType(c, MaterialSelector)) ) {
14-
c.parent = shadersRoot;
14+
shadersRoot.addChild(c);
1515
i--;
1616
}
1717
i++;

0 commit comments

Comments
 (0)