Skip to content

Commit

Permalink
Deprecate old signal API (#649)
Browse files Browse the repository at this point in the history
* Deprecate old signal API

* Use Xcode 16.2 for CI.
  • Loading branch information
samdeane authored Jan 24, 2025
1 parent b9c098a commit bc2db01
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Sources/SwiftGodot/Core/SignalRegistration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/// Describes a signal and its arguments.
/// - note: It is recommended to use the @Signal macro instead of using this directly.
@available(*, deprecated, message: "Use the @Signal macro instead.")
public struct SignalWithNoArguments {
public let name: StringName
public let arguments: [PropInfo] = [] // needed for registration in macro, but always []
Expand All @@ -18,6 +19,7 @@ public struct SignalWithNoArguments {

/// Describes a signal and its arguments.
/// - note: It is recommended to use the @Signal macro instead of using this directly.
@available(*, deprecated, message: "Use the @Signal macro instead.")
public struct SignalWith1Argument<Argument: VariantStorable> {
public let name: StringName
public let arguments: [PropInfo]
Expand All @@ -35,6 +37,7 @@ public struct SignalWith1Argument<Argument: VariantStorable> {

/// Describes a signal and its arguments.
/// - note: It is recommended to use the @Signal macro instead of using this directly.
@available(*, deprecated, message: "Use the @Signal macro instead.")
public struct SignalWith2Arguments<
Argument1: VariantStorable,
Argument2: VariantStorable
Expand All @@ -57,6 +60,7 @@ public struct SignalWith2Arguments<

/// Describes a signal and its arguments.
/// - note: It is recommended to use the @Signal macro instead of using this directly.
@available(*, deprecated, message: "Use the @Signal macro instead.")
public struct SignalWith3Arguments<
Argument1: VariantStorable,
Argument2: VariantStorable,
Expand All @@ -82,6 +86,7 @@ public struct SignalWith3Arguments<

/// Describes a signal and its arguments.
/// - note: It is recommended to use the @Signal macro instead of using this directly.
@available(*, deprecated, message: "Use the @Signal macro instead.")
public struct SignalWith4Arguments<
Argument1: VariantStorable,
Argument2: VariantStorable,
Expand Down Expand Up @@ -110,6 +115,7 @@ public struct SignalWith4Arguments<

/// Describes a signal and its arguments.
/// - note: It is recommended to use the @Signal macro instead of using this directly.
@available(*, deprecated, message: "Use the @Signal macro instead.")
public struct SignalWith5Arguments<
Argument1: VariantStorable,
Argument2: VariantStorable,
Expand Down Expand Up @@ -141,6 +147,7 @@ public struct SignalWith5Arguments<

/// Describes a signal and its arguments.
/// - note: It is recommended to use the @Signal macro instead of using this directly.
@available(*, deprecated, message: "Use the @Signal macro instead.")
public struct SignalWith6Arguments<
Argument1: VariantStorable,
Argument2: VariantStorable,
Expand Down Expand Up @@ -189,6 +196,7 @@ public extension Object {
/// - method: the name of a @Callable method defined on the `target` object.
/// - Example: connect(signal: Player.scored, to: self, method: "updateScore")
@discardableResult
@available(*, deprecated, message: "Use the @Signal macro instead.")
func connect(signal: SignalWithNoArguments, to target: some Object, method: String) -> GodotError {
connect(signal: signal.name, callable: .init(object: target, method: .init(method)))
}
Expand All @@ -197,6 +205,7 @@ public extension Object {
/// The argument must match the type of the argument at that position in the signal.
/// - Example: emit(signal: Player.scored, 12)
@discardableResult
@available(*, deprecated, message: "Use the @Signal macro instead.")
func emit<A: VariantStorable>(signal: SignalWith1Argument<A>, _ argument: A) -> GodotError {
emitSignal(signal.name, .init(argument))
}
Expand All @@ -208,6 +217,7 @@ public extension Object {
/// - method: the name of a @Callable method defined on the `target` object.
/// - Example: connect(signal: Player.scored, to: self, method: "updateScore")
@discardableResult
@available(*, deprecated, message: "Use the @Signal macro instead.")
func connect(signal: SignalWith1Argument<some Any>, to target: some Object, method: String) -> GodotError {
connect(signal: signal.name, callable: .init(object: target, method: .init(method)))
}
Expand All @@ -216,6 +226,7 @@ public extension Object {
/// The argument must match the type of the argument at that position in the signal.
/// - Example: emit(signal: Player.scored, 12, "hooray")
@discardableResult
@available(*, deprecated, message: "Use the @Signal macro instead.")
func emit<A: VariantStorable, B: VariantStorable>(
signal: SignalWith2Arguments<A, B>,
_ argument1: A,
Expand All @@ -231,6 +242,7 @@ public extension Object {
/// - method: the name of a @Callable method defined on the `target` object.
/// - Example: connect(signal: Player.scored, to: self, method: "updateScore")
@discardableResult
@available(*, deprecated, message: "Use the @Signal macro instead.")
func connect(signal: SignalWith2Arguments<some Any, some Any>, to target: some Object, method: String) -> GodotError {
connect(signal: signal.name, callable: .init(object: target, method: .init(method)))
}
Expand All @@ -239,6 +251,7 @@ public extension Object {
/// The argument must match the type of the argument at that position in the signal.
/// - Example: emit(signal: Player.scored, 12, "hooray", self)
@discardableResult
@available(*, deprecated, message: "Use the @Signal macro instead.")
func emit<A: VariantStorable, B: VariantStorable, C: VariantStorable>(
signal: SignalWith3Arguments<A, B, C>,
_ argument1: A,
Expand All @@ -255,6 +268,7 @@ public extension Object {
/// - method: the name of a @Callable method defined on the `target` object.
/// - Example: connect(signal: Player.scored, to: self, method: "updateScore")
@discardableResult
@available(*, deprecated, message: "Use the @Signal macro instead.")
func connect(
signal: SignalWith3Arguments<some Any, some Any, some Any>,
to target: some Object,
Expand All @@ -267,6 +281,7 @@ public extension Object {
/// The argument must match the type of the argument at that position in the signal.
/// - Example: emit(signal: Player.scored, 12, "hooray", self, 4)
@discardableResult
@available(*, deprecated, message: "Use the @Signal macro instead.")
func emit<A: VariantStorable, B: VariantStorable, C: VariantStorable, D: VariantStorable>(
signal: SignalWith4Arguments<A, B, C, D>,
_ argument1: A,
Expand All @@ -290,6 +305,7 @@ public extension Object {
/// - method: the name of a @Callable method defined on the `target` object.
/// - Example: connect(signal: Player.scored, to: self, method: "updateScore")
@discardableResult
@available(*, deprecated, message: "Use the @Signal macro instead.")
func connect(
signal: SignalWith4Arguments<some Any, some Any, some Any, some Any>,
to target: some Object,
Expand All @@ -302,6 +318,7 @@ public extension Object {
/// The argument must match the type of the argument at that position in the signal.
/// - Example: emit(signal: Player.scored, 12, "hooray", self, 4, "another_one")
@discardableResult
@available(*, deprecated, message: "Use the @Signal macro instead.")
func emit<A: VariantStorable, B: VariantStorable, C: VariantStorable, D: VariantStorable, E: VariantStorable>(
signal: SignalWith5Arguments<A, B, C, D, E>,
_ argument1: A,
Expand All @@ -327,6 +344,7 @@ public extension Object {
/// - method: the name of a @Callable method defined on the `target` object.
/// - Example: connect(signal: Player.scored, to: self, method: "updateScore")
@discardableResult
@available(*, deprecated, message: "Use the @Signal macro instead.")
func connect(
signal: SignalWith5Arguments<some Any, some Any, some Any, some Any, some Any>,
to target: some Object,
Expand All @@ -339,6 +357,7 @@ public extension Object {
/// The argument must match the type of the argument at that position in the signal.
/// - Example: emit(signal: Player.scored, 12, "hooray", self, 4, reason)
@discardableResult
@available(*, deprecated, message: "Use the @Signal macro instead.")
func emit<A: VariantStorable, B: VariantStorable, C: VariantStorable, D: VariantStorable, E: VariantStorable, F: VariantStorable>(
signal: SignalWith6Arguments<A, B, C, D, E, F>,
_ argument1: A,
Expand Down Expand Up @@ -366,6 +385,7 @@ public extension Object {
/// - method: the name of a @Callable method defined on the `target` object.
/// - Example: connect(signal: Player.scored, to: self, method: "updateScore")
@discardableResult
@available(*, deprecated, message: "Use the @Signal macro instead.")
func connect(
signal: SignalWith6Arguments<some Any, some Any, some Any, some Any, some Any, some Any>,
to target: some Object,
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftGodot/MacroDefs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public macro SceneTree(path: String? = nil) = #externalMacro(module: "SwiftGodot
/// example, ["name" : String.self] declares that the signal takes one argument of string type. The argument name is provided to the godot
/// editor. Argument types are enforced on the `emit(signal:_argument)` method. Argument types must conform to GodotVariant.
@freestanding(declaration, names: arbitrary)
@available(*, deprecated, message: "Use the @Signal macro instead.")
public macro signal(_ signalName: String, arguments: Dictionary<String, Any.Type> = [:]) = #externalMacro(module: "SwiftGodotMacroLibrary", type: "SignalMacro")

/// Defines a Godot signal on a class.
Expand Down

0 comments on commit bc2db01

Please sign in to comment.