Skip to content

Commit c9e2320

Browse files
committed
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)`
1 parent 5295ca9 commit c9e2320

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

Generator/Generator/ClassGen.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func generateVirtualProxy (_ p: Printer,
204204
// Dictioanry of Godot Type Name to array of method names that can get a @discardableResult
205205
let discardableResultList: [String: Set<String>] = [
206206
"Object": ["emit_signal"],
207-
"GArray": ["append"],
207+
"GArray": ["append", "resize"],
208208
"PackedByteArray": ["append", "push_back"],
209209
"PackedColorArray": ["append", "push_back"],
210210
"PackedFloat32Array": ["append", "push_back"],
@@ -239,7 +239,14 @@ let omittedMethodsList: [String: Set<String>] = [
239239

240240
// Dictionary used to explicitly tell the generator to replace the first argument label with "_ "
241241
let omittedFirstArgLabelList: [String: Set<String>] = [
242-
"GArray": ["append"]
242+
"GArray": ["append"],
243+
"PackedColorArray": ["append"],
244+
"PackedFloat64Array": ["append"],
245+
"PackedInt64Array": ["append"],
246+
"PackedStringArray": ["append"],
247+
"PackedVector2Array": ["append"],
248+
"PackedVector3Array": ["append"],
249+
243250
]
244251

245252
/// Determines if the first argument name should be replaced with an underscore.

Sources/SwiftGodot/Core/Packed.swift

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ extension PackedStringArray {
2323
set (index: Int64 (index), value: newValue)
2424
}
2525
}
26+
27+
@available(*, deprecated, renamed: "append(_:)", message: "This method signature has been deprecated in favor of append(_:)")
28+
public func append(value: String) {
29+
append(value)
30+
}
2631
}
2732

2833
extension PackedByteArray {
@@ -107,6 +112,11 @@ extension PackedByteArray {
107112
}
108113
}
109114
}
115+
116+
/// Appends an element at the end of the array
117+
public func append(_ value: UInt8) {
118+
append(value: Int64(value))
119+
}
110120
}
111121

112122
extension PackedColorArray {
@@ -120,6 +130,10 @@ extension PackedColorArray {
120130
set (index: Int64 (index), value: newValue)
121131
}
122132
}
133+
@available(*, deprecated, renamed: "append(_:)", message: "This method signature has been deprecated in favor of append(_:)")
134+
public func append(value: Color) {
135+
append(value)
136+
}
123137
}
124138

125139
extension PackedFloat32Array {
@@ -148,6 +162,11 @@ extension PackedFloat32Array {
148162
}
149163
}
150164
}
165+
166+
/// Appends an element at the end of the array
167+
public func append(_ value: Float) {
168+
append (value: Double (value))
169+
}
151170
}
152171

153172
extension PackedFloat64Array {
@@ -176,7 +195,11 @@ extension PackedFloat64Array {
176195
}
177196
}
178197
}
179-
198+
199+
@available(*, deprecated, renamed: "append(_:)", message: "This method signature has been deprecated in favor of append(_:)")
200+
public func append(value: Double) {
201+
append(value)
202+
}
180203
}
181204

182205
extension PackedInt32Array {
@@ -205,6 +228,11 @@ extension PackedInt32Array {
205228
}
206229
}
207230
}
231+
232+
/// Appends an element at the end of the array
233+
public func append(_ value: Int32) {
234+
append (value: Int64 (value))
235+
}
208236
}
209237

210238
extension PackedInt64Array {
@@ -233,6 +261,11 @@ extension PackedInt64Array {
233261
}
234262
}
235263
}
264+
265+
@available(*, deprecated, renamed: "append(_:)", message: "This method signature has been deprecated in favor of append(_:)")
266+
public func append(value: Int64) {
267+
append(value)
268+
}
236269
}
237270

238271
extension PackedVector2Array {
@@ -246,6 +279,10 @@ extension PackedVector2Array {
246279
set (index: Int64 (index), value: newValue)
247280
}
248281
}
282+
@available(*, deprecated, renamed: "append(_:)", message: "This method signature has been deprecated in favor of append(_:)")
283+
public func append(value: Vector2) {
284+
append(value)
285+
}
249286
}
250287

251288
extension PackedVector3Array {
@@ -259,6 +296,10 @@ extension PackedVector3Array {
259296
set (index: Int64 (index), value: newValue)
260297
}
261298
}
299+
@available(*, deprecated, renamed: "append(_:)", message: "This method signature has been deprecated in favor of append(_:)")
300+
public func append(value: Vector3) {
301+
append(value)
302+
}
262303
}
263304

264305

0 commit comments

Comments
 (0)