| 1 | pub type FnGridObject = fn (mut object GridObject) |
| 2 | |
| 3 | @[flag] |
| 4 | pub enum GridObjectAuto { |
| 5 | drag |
| 6 | drop |
| 7 | scale_on_hover |
| 8 | pickup |
| 9 | sound |
| 10 | off // auto "deactivation" |
| 11 | } |
| 12 | |
| 13 | @[params] |
| 14 | pub struct GridObjectConfig { |
| 15 | auto GridObjectAuto = ~GridObjectAuto.zero() |
| 16 | on ?FnGridObject |
| 17 | } |
| 18 | |
| 19 | @[heap] |
| 20 | struct GridObject { |
| 21 | mut: |
| 22 | config GridObjectConfig |
| 23 | auto GridObjectAuto = ~GridObjectAuto.zero() |
| 24 | } |
| 25 | |
| 26 | pub fn on(config GridObjectConfig) &GridObject { |
| 27 | mut ob := &GridObject{} |
| 28 | ob.config = config |
| 29 | ob.auto = config.auto |
| 30 | if func := ob.config.on { |
| 31 | func(mut ob) |
| 32 | } |
| 33 | return ob |
| 34 | } |
| 35 | |
| 36 | fn test_main() { |
| 37 | _ := on( |
| 38 | on: fn (mut o GridObject) { |
| 39 | o.auto = .off | .pickup | .sound |
| 40 | } |
| 41 | ) |
| 42 | assert true |
| 43 | } |
| 44 | |