Skip to content

Commit

Permalink
Surface notifications, fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
migueldeicaza committed Nov 15, 2024
1 parent 05e632c commit 926b229
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Generator/Generator/DocModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ func doc (_ p: Printer, _ cdef: JClassInfo?, _ text: String?) {
mod = mod.replacing(rxEnumMethodMember, with: { x in
switch x.output.1 {
case "method":
if x.output.2 == "Object._notification" {
return "``Wrapper._notification(code:reverse)``"
}
return "``\(convertMethod (x.output.2))``"
case "member":
// Same as method for now?
Expand Down
13 changes: 12 additions & 1 deletion Sources/SwiftGodot/Core/Wrapped.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,16 @@ open class Wrapped: Equatable, Identifiable, Hashable {
}
return ""
}

/// This method is posted by Godot, you can override this method and
/// be notified of interesting events, the values for this notification are declared on various
/// different types, like the constants in Object or Node.
///
/// For example `Node.notificationProcess`
open func _notification(code: Int, reversed: Bool) {
}


/// Checks if this object has a script with the given method.
/// - Parameter method: StringName identifying the method.
/// - Returns: `true` if the object has a script and that script has a method with the given name.
Expand Down Expand Up @@ -528,7 +537,9 @@ func freeFunc (_ userData: UnsafeMutableRawPointer?, _ objectHandle: UnsafeMutab
}

func notificationFunc (ptr: UnsafeMutableRawPointer?, code: Int32, reversed: UInt8) {
//print ("SWIFT: Notification \(code) on \(ptr)")
guard let ptr else { return }
let original = Unmanaged<Wrapped>.fromOpaque(ptr).takeUnretainedValue()
original._notification(code: Int(code), reversed: reversed != 0)
}

func userTypeBindingCreate (_ token: UnsafeMutableRawPointer?, _ instance: UnsafeMutableRawPointer?) -> UnsafeMutableRawPointer? {
Expand Down

0 comments on commit 926b229

Please sign in to comment.