migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
1.19k stars 77 forks source link

Fixed Generator issue when using class arguments not looking up subtypes #538

Closed jay18001 closed 2 months ago

jay18001 commented 2 months ago

Fixes #535

When using the inputEvent on CollisionObject3D, for example, the callback alway returns an InputEvent instance instead of the correct subclass. In the example code the if in mouse_input_event will never pass.

Example code:

class SomeNode: Node3D {

  @SceneTree(path: "CollisionObject3D")
  var nodeArea: CollisionObject3D?

  public override func _ready() {
        nodeArea?.inputEvent.connect(mouse_input_event)
  }

  func mouse_input_event(camera: Node, event: InputEvent, eventPosition: Vector3, normal: Vector3, _shape_idx: Int64) {
      if event is InputEventMouse {
           print("InputEventMouse") // Will never print
      }
  }
}

The original output would be

let arg_1 = lookupLiveObject (handleAddress: ptr_1!) as? InputEvent ?? InputEvent (nativeHandle: ptr_1!)

Now it will be this if the type has a subclass

let arg_1 = lookupLiveObject (handleAddress: ptr_1!) as? InputEvent ?? lookupObject (nativeHandle: ptr_1!) ?? InputEvent (nativeHandle: ptr_1!)
migueldeicaza commented 2 months ago

Thank you for tracking this down and the fix!