| 1 | module main |
| 2 | |
| 3 | interface IGameObject { |
| 4 | mut: |
| 5 | name string |
| 6 | parent ?&IGameObject |
| 7 | children []&IGameObject |
| 8 | add_child(mut o IGameObject) |
| 9 | } |
| 10 | |
| 11 | @[heap] |
| 12 | struct GameObject implements IGameObject { |
| 13 | mut: |
| 14 | name string |
| 15 | parent ?&IGameObject |
| 16 | children []&IGameObject |
| 17 | } |
| 18 | |
| 19 | fn (mut gameobject GameObject) add_child(mut o IGameObject) { |
| 20 | o.parent = gameobject |
| 21 | gameobject.children << o |
| 22 | } |
| 23 | |
| 24 | fn test_main() { |
| 25 | mut v1 := &GameObject{ |
| 26 | name: 'v1' |
| 27 | } |
| 28 | mut v2 := &GameObject{ |
| 29 | name: 'v2' |
| 30 | } |
| 31 | v1.add_child(mut v2) |
| 32 | if v1.children[0].parent != none { |
| 33 | assert '${v1.children[0].parent.name}' == 'v1' |
| 34 | } |
| 35 | } |
| 36 |