From c9e23209c1ebe80d6b78b560d9e8fe58743fcf27 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Tue, 2 Jul 2024 15:03:34 -0400 Subject: [PATCH] Drop the `value:` parameter name from the various PackedArray.* append methods. Do that, but still provide a deprecated entry point to prevent breaking code. In a few cases where we surfaced an API that did the append but with the underlying type, we keep the value: parameter in the API, but introduce a convenience `append(_:)` method of the right type, for example for PackedByteArray that would be: 'func append(_ value: UInt8)` --- Generator/Generator/ClassGen.swift | 11 +++++-- Sources/SwiftGodot/Core/Packed.swift | 43 +++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/Generator/Generator/ClassGen.swift b/Generator/Generator/ClassGen.swift index 8c74bf5d9..277a9c731 100644 --- a/Generator/Generator/ClassGen.swift +++ b/Generator/Generator/ClassGen.swift @@ -204,7 +204,7 @@ func generateVirtualProxy (_ p: Printer, // Dictioanry of Godot Type Name to array of method names that can get a @discardableResult let discardableResultList: [String: Set] = [ "Object": ["emit_signal"], - "GArray": ["append"], + "GArray": ["append", "resize"], "PackedByteArray": ["append", "push_back"], "PackedColorArray": ["append", "push_back"], "PackedFloat32Array": ["append", "push_back"], @@ -239,7 +239,14 @@ let omittedMethodsList: [String: Set] = [ // Dictionary used to explicitly tell the generator to replace the first argument label with "_ " let omittedFirstArgLabelList: [String: Set] = [ - "GArray": ["append"] + "GArray": ["append"], + "PackedColorArray": ["append"], + "PackedFloat64Array": ["append"], + "PackedInt64Array": ["append"], + "PackedStringArray": ["append"], + "PackedVector2Array": ["append"], + "PackedVector3Array": ["append"], + ] /// Determines if the first argument name should be replaced with an underscore. diff --git a/Sources/SwiftGodot/Core/Packed.swift b/Sources/SwiftGodot/Core/Packed.swift index 0dc20fcc4..1d3a5c43c 100644 --- a/Sources/SwiftGodot/Core/Packed.swift +++ b/Sources/SwiftGodot/Core/Packed.swift @@ -23,6 +23,11 @@ extension PackedStringArray { set (index: Int64 (index), value: newValue) } } + + @available(*, deprecated, renamed: "append(_:)", message: "This method signature has been deprecated in favor of append(_:)") + public func append(value: String) { + append(value) + } } extension PackedByteArray { @@ -107,6 +112,11 @@ extension PackedByteArray { } } } + + /// Appends an element at the end of the array + public func append(_ value: UInt8) { + append(value: Int64(value)) + } } extension PackedColorArray { @@ -120,6 +130,10 @@ extension PackedColorArray { set (index: Int64 (index), value: newValue) } } + @available(*, deprecated, renamed: "append(_:)", message: "This method signature has been deprecated in favor of append(_:)") + public func append(value: Color) { + append(value) + } } extension PackedFloat32Array { @@ -148,6 +162,11 @@ extension PackedFloat32Array { } } } + + /// Appends an element at the end of the array + public func append(_ value: Float) { + append (value: Double (value)) + } } extension PackedFloat64Array { @@ -176,7 +195,11 @@ extension PackedFloat64Array { } } } - + + @available(*, deprecated, renamed: "append(_:)", message: "This method signature has been deprecated in favor of append(_:)") + public func append(value: Double) { + append(value) + } } extension PackedInt32Array { @@ -205,6 +228,11 @@ extension PackedInt32Array { } } } + + /// Appends an element at the end of the array + public func append(_ value: Int32) { + append (value: Int64 (value)) + } } extension PackedInt64Array { @@ -233,6 +261,11 @@ extension PackedInt64Array { } } } + + @available(*, deprecated, renamed: "append(_:)", message: "This method signature has been deprecated in favor of append(_:)") + public func append(value: Int64) { + append(value) + } } extension PackedVector2Array { @@ -246,6 +279,10 @@ extension PackedVector2Array { set (index: Int64 (index), value: newValue) } } + @available(*, deprecated, renamed: "append(_:)", message: "This method signature has been deprecated in favor of append(_:)") + public func append(value: Vector2) { + append(value) + } } extension PackedVector3Array { @@ -259,6 +296,10 @@ extension PackedVector3Array { set (index: Int64 (index), value: newValue) } } + @available(*, deprecated, renamed: "append(_:)", message: "This method signature has been deprecated in favor of append(_:)") + public func append(value: Vector3) { + append(value) + } }