Skip to content

Commit

Permalink
Drop the value: parameter name from the various PackedArray.* append
Browse files Browse the repository at this point in the history
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)`
  • Loading branch information
migueldeicaza committed Jul 2, 2024
1 parent 5295ca9 commit c9e2320
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
11 changes: 9 additions & 2 deletions Generator/Generator/ClassGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>] = [
"Object": ["emit_signal"],
"GArray": ["append"],
"GArray": ["append", "resize"],
"PackedByteArray": ["append", "push_back"],
"PackedColorArray": ["append", "push_back"],
"PackedFloat32Array": ["append", "push_back"],
Expand Down Expand Up @@ -239,7 +239,14 @@ let omittedMethodsList: [String: Set<String>] = [

// Dictionary used to explicitly tell the generator to replace the first argument label with "_ "
let omittedFirstArgLabelList: [String: Set<String>] = [
"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.
Expand Down
43 changes: 42 additions & 1 deletion Sources/SwiftGodot/Core/Packed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
}
}


0 comments on commit c9e2320

Please sign in to comment.