pragmagic / godot-nim

Nim bindings for Godot Engine
https://pragmagic.github.io/godot-nim/
Other
497 stars 27 forks source link

added async handling for signals #83

Open geekrelief opened 3 years ago

geekrelief commented 3 years ago

So we can handle signals with an {.async.} proc like this:

...
import asynchdispatch

gdobj SpriteComp of Sprite:

  signal bsclick(button_idx:int, shape_idx:int)

  method ready() =
    ...
    registerFrameCallback(
      proc() =
        if hasPendingOperations():
          poll(0)
    )
    asyncCheck self.fireTimer()
    self.emit_signal("bsclick", 1.toVariant, 0.toVariant)

  proc fireTimer() {.async.} =
    await on_signal(self.get_tree().createTimer(1), "timeout")
    print "timeout sceneTree"

    var vals = await on_signal(self, "bsclick", tuple[button_idx:int, shape_idx:int])
    print &"bsclick {vals.button_idx = } {vals.shape_idx = }"
arunvickram commented 3 years ago

Do signals work with either camelCase or snake_case? Or does it only work with snake_case?