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