removeFromTree method

void removeFromTree()

Implementation

void removeFromTree() {
  //already an orphan
  if (parent == 0) return;

  var pgo = GameObject(parent);

  if (pgo.child == id) {
    //we are the parent's child so...
    pgo.child = 0;
    if (sibling != 0) {
      //move sibling to parent's child
      pgo.child = sibling;
    }
  } else {
    //find the sibling to the left of us...
    var leftSib = leftSibling();

    // now set that sibling's sibling to our sibling
    // effectively removing us from the list.
    GameObject(leftSib).sibling = sibling;
  }
  parent = 0;
  sibling = 0;
}