Skip to content

Commit

Permalink
cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
samdeane committed Oct 28, 2024
1 parent f005e37 commit 29304d3
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions Sources/SwiftGodot/Core/GenericSignal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extension VariantStorable {
static func propInfo(name: String) -> PropInfo {
let gType = Self.Representable.godotType
return PropInfo(
propertyType: gType,
propertyType: gType,
propertyName: StringName(name),
className: gType == .object ? StringName(String(describing: Self.self)) : "",
hint: .none,
Expand All @@ -16,32 +16,6 @@ extension VariantStorable {
}
}

func getProps<each TT>(_ type: repeat each TT) -> [PropInfo] {
var args = [PropInfo]()
var argC = 1
for arg in repeat each type {
if let a = arg as? any VariantStorable.Type {
args.append(a.propInfo(name: "arg\(argC)"))
// let gType = a.Representable.godotType
// args.append(
// PropInfo(
// propertyType: gType,
// propertyName: "arg\(argC)",
// className: gType == .object ? StringName(String(describing: a.self)) : "",
// hint: .none,
// hintStr: "",
// usage: .default
// )
// )
argC += 1
print("variant")
} else {
print("not variant")
}
}
return args
}

/// Signal support.
/// Use the ``GenericSignal/connect(flags:_:)`` method to connect to the signal on the container object,
/// and ``GenericSignal/disconnect(_:)`` to drop the connection.
Expand All @@ -59,9 +33,26 @@ public class GenericSignal<each T: VariantStorable> {
}

/// Register this signal with the Godot runtime.
// TODO: the signal macro could probably pass in the argument names, so that we could register them as well
public static func register<C: Object>(_ signalName: String, info: ClassInfo<C>) {
let boxed = getProps(repeat (each T).self)
info.registerSignal(name: StringName(signalName), arguments: boxed)
let arguments = expandArguments(repeat (each T).self)
info.registerSignal(name: StringName(signalName), arguments: arguments)
}

/// Expand a list of argument types into a list of PropInfo objects
/// Note: it doesn't currently seem to be possible to constrain
/// the type of the pack expansion to be ``VariantStorable.Type``, but
/// we know that it always will be, so we can force cast it.
static func expandArguments<each ArgType>(_ type: repeat each ArgType) -> [PropInfo] {
var args = [PropInfo]()
var argC = 1
for arg in repeat each type {
let a = arg as! any VariantStorable.Type
args.append(a.propInfo(name: "arg\(argC)"))
argC += 1

}
return args
}

/// Connects the signal to the specified callback
Expand Down

0 comments on commit 29304d3

Please sign in to comment.