module main

@[heap]
interface IGameObject {
mut:
	name       string
	parent     ?&IGameObject
	next       ?&IGameObject
	child      ?&IGameObject
	last_child ?&IGameObject
	add_child(mut o IGameObject)
}

@[heap]
struct GameObject implements IGameObject {
mut:
	name       string
	parent     ?&IGameObject
	next       ?&IGameObject
	child      ?&IGameObject
	last_child ?&IGameObject
}

fn (mut gameobject GameObject) add_child(mut o IGameObject) {
	o.parent = gameobject
	if mut last_child := gameobject.last_child {
		last_child.next = o
	} else {
		gameobject.child = o
	}
	gameobject.last_child = o
}

fn main() {
	mut v1 := &GameObject{
		name: 'v1'
	}
	mut v2 := &GameObject{
		name: 'v2'
	}
	v1.add_child(mut v2)
}
