Skip to content

Commit dae32f8

Browse files
committed
Merge pull request #92737 from AThousandShips/packed_erase
[Core] Expose `Packed*Array::erase`
2 parents a13067e + 46b6acd commit dae32f8

11 files changed

+85
-0
lines changed

core/variant/variant_call.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,6 +2451,7 @@ static void _register_variant_builtin_methods_array() {
24512451
bind_method(PackedByteArray, find, sarray("value", "from"), varray(0));
24522452
bind_method(PackedByteArray, rfind, sarray("value", "from"), varray(-1));
24532453
bind_method(PackedByteArray, count, sarray("value"), varray());
2454+
bind_method(PackedByteArray, erase, sarray("value"), varray());
24542455

24552456
bind_function(PackedByteArray, get_string_from_ascii, _VariantCall::func_PackedByteArray_get_string_from_ascii, sarray(), varray());
24562457
bind_function(PackedByteArray, get_string_from_utf8, _VariantCall::func_PackedByteArray_get_string_from_utf8, sarray(), varray());
@@ -2517,6 +2518,7 @@ static void _register_variant_builtin_methods_array() {
25172518
bind_method(PackedInt32Array, find, sarray("value", "from"), varray(0));
25182519
bind_method(PackedInt32Array, rfind, sarray("value", "from"), varray(-1));
25192520
bind_method(PackedInt32Array, count, sarray("value"), varray());
2521+
bind_method(PackedInt32Array, erase, sarray("value"), varray());
25202522

25212523
/* Int64 Array */
25222524

@@ -2540,6 +2542,7 @@ static void _register_variant_builtin_methods_array() {
25402542
bind_method(PackedInt64Array, find, sarray("value", "from"), varray(0));
25412543
bind_method(PackedInt64Array, rfind, sarray("value", "from"), varray(-1));
25422544
bind_method(PackedInt64Array, count, sarray("value"), varray());
2545+
bind_method(PackedInt64Array, erase, sarray("value"), varray());
25432546

25442547
/* Float32 Array */
25452548

@@ -2563,6 +2566,7 @@ static void _register_variant_builtin_methods_array() {
25632566
bind_method(PackedFloat32Array, find, sarray("value", "from"), varray(0));
25642567
bind_method(PackedFloat32Array, rfind, sarray("value", "from"), varray(-1));
25652568
bind_method(PackedFloat32Array, count, sarray("value"), varray());
2569+
bind_method(PackedFloat32Array, erase, sarray("value"), varray());
25662570

25672571
/* Float64 Array */
25682572

@@ -2586,6 +2590,7 @@ static void _register_variant_builtin_methods_array() {
25862590
bind_method(PackedFloat64Array, find, sarray("value", "from"), varray(0));
25872591
bind_method(PackedFloat64Array, rfind, sarray("value", "from"), varray(-1));
25882592
bind_method(PackedFloat64Array, count, sarray("value"), varray());
2593+
bind_method(PackedFloat64Array, erase, sarray("value"), varray());
25892594

25902595
/* String Array */
25912596

@@ -2609,6 +2614,7 @@ static void _register_variant_builtin_methods_array() {
26092614
bind_method(PackedStringArray, find, sarray("value", "from"), varray(0));
26102615
bind_method(PackedStringArray, rfind, sarray("value", "from"), varray(-1));
26112616
bind_method(PackedStringArray, count, sarray("value"), varray());
2617+
bind_method(PackedStringArray, erase, sarray("value"), varray());
26122618

26132619
/* Vector2 Array */
26142620

@@ -2632,6 +2638,7 @@ static void _register_variant_builtin_methods_array() {
26322638
bind_method(PackedVector2Array, find, sarray("value", "from"), varray(0));
26332639
bind_method(PackedVector2Array, rfind, sarray("value", "from"), varray(-1));
26342640
bind_method(PackedVector2Array, count, sarray("value"), varray());
2641+
bind_method(PackedVector2Array, erase, sarray("value"), varray());
26352642

26362643
/* Vector3 Array */
26372644

@@ -2655,6 +2662,7 @@ static void _register_variant_builtin_methods_array() {
26552662
bind_method(PackedVector3Array, find, sarray("value", "from"), varray(0));
26562663
bind_method(PackedVector3Array, rfind, sarray("value", "from"), varray(-1));
26572664
bind_method(PackedVector3Array, count, sarray("value"), varray());
2665+
bind_method(PackedVector3Array, erase, sarray("value"), varray());
26582666

26592667
/* Color Array */
26602668

@@ -2678,6 +2686,7 @@ static void _register_variant_builtin_methods_array() {
26782686
bind_method(PackedColorArray, find, sarray("value", "from"), varray(0));
26792687
bind_method(PackedColorArray, rfind, sarray("value", "from"), varray(-1));
26802688
bind_method(PackedColorArray, count, sarray("value"), varray());
2689+
bind_method(PackedColorArray, erase, sarray("value"), varray());
26812690

26822691
/* Vector4 Array */
26832692

@@ -2701,6 +2710,7 @@ static void _register_variant_builtin_methods_array() {
27012710
bind_method(PackedVector4Array, find, sarray("value", "from"), varray(0));
27022711
bind_method(PackedVector4Array, rfind, sarray("value", "from"), varray(-1));
27032712
bind_method(PackedVector4Array, count, sarray("value"), varray());
2713+
bind_method(PackedVector4Array, erase, sarray("value"), varray());
27042714
}
27052715

27062716
static void _register_variant_builtin_constants() {

doc/classes/PackedByteArray.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@
292292
Encodes a [Variant] at the index of [param byte_offset] bytes. A sufficient space must be allocated, depending on the encoded variant's size. If [param allow_objects] is [code]false[/code], [Object]-derived values are not permitted and will instead be serialized as ID-only.
293293
</description>
294294
</method>
295+
<method name="erase">
296+
<return type="bool" />
297+
<param index="0" name="value" type="int" />
298+
<description>
299+
Removes the first occurrence of a value from the array and returns [code]true[/code]. If the value does not exist in the array, nothing happens and [code]false[/code] is returned. To remove an element by index, use [method remove_at] instead.
300+
</description>
301+
</method>
295302
<method name="fill">
296303
<return type="void" />
297304
<param index="0" name="value" type="int" />

doc/classes/PackedColorArray.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@
7979
Creates a copy of the array, and returns it.
8080
</description>
8181
</method>
82+
<method name="erase">
83+
<return type="bool" />
84+
<param index="0" name="value" type="Color" />
85+
<description>
86+
Removes the first occurrence of a value from the array and returns [code]true[/code]. If the value does not exist in the array, nothing happens and [code]false[/code] is returned. To remove an element by index, use [method remove_at] instead.
87+
</description>
88+
</method>
8289
<method name="fill">
8390
<return type="void" />
8491
<param index="0" name="value" type="Color" />

doc/classes/PackedFloat32Array.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@
7777
Creates a copy of the array, and returns it.
7878
</description>
7979
</method>
80+
<method name="erase">
81+
<return type="bool" />
82+
<param index="0" name="value" type="float" />
83+
<description>
84+
Removes the first occurrence of a value from the array and returns [code]true[/code]. If the value does not exist in the array, nothing happens and [code]false[/code] is returned. To remove an element by index, use [method remove_at] instead.
85+
[b]Note:[/b] [constant @GDScript.NAN] doesn't behave the same as other numbers. Therefore, the results from this method may not be accurate if NaNs are included.
86+
</description>
87+
</method>
8088
<method name="fill">
8189
<return type="void" />
8290
<param index="0" name="value" type="float" />

doc/classes/PackedFloat64Array.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@
7878
Creates a copy of the array, and returns it.
7979
</description>
8080
</method>
81+
<method name="erase">
82+
<return type="bool" />
83+
<param index="0" name="value" type="float" />
84+
<description>
85+
Removes the first occurrence of a value from the array and returns [code]true[/code]. If the value does not exist in the array, nothing happens and [code]false[/code] is returned. To remove an element by index, use [method remove_at] instead.
86+
[b]Note:[/b] [constant @GDScript.NAN] doesn't behave the same as other numbers. Therefore, the results from this method may not be accurate if NaNs are included.
87+
</description>
88+
</method>
8189
<method name="fill">
8290
<return type="void" />
8391
<param index="0" name="value" type="float" />

doc/classes/PackedInt32Array.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@
7575
Creates a copy of the array, and returns it.
7676
</description>
7777
</method>
78+
<method name="erase">
79+
<return type="bool" />
80+
<param index="0" name="value" type="int" />
81+
<description>
82+
Removes the first occurrence of a value from the array and returns [code]true[/code]. If the value does not exist in the array, nothing happens and [code]false[/code] is returned. To remove an element by index, use [method remove_at] instead.
83+
</description>
84+
</method>
7885
<method name="fill">
7986
<return type="void" />
8087
<param index="0" name="value" type="int" />

doc/classes/PackedInt64Array.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@
7676
Creates a copy of the array, and returns it.
7777
</description>
7878
</method>
79+
<method name="erase">
80+
<return type="bool" />
81+
<param index="0" name="value" type="int" />
82+
<description>
83+
Removes the first occurrence of a value from the array and returns [code]true[/code]. If the value does not exist in the array, nothing happens and [code]false[/code] is returned. To remove an element by index, use [method remove_at] instead.
84+
</description>
85+
</method>
7986
<method name="fill">
8087
<return type="void" />
8188
<param index="0" name="value" type="int" />

doc/classes/PackedStringArray.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@
8282
Creates a copy of the array, and returns it.
8383
</description>
8484
</method>
85+
<method name="erase">
86+
<return type="bool" />
87+
<param index="0" name="value" type="String" />
88+
<description>
89+
Removes the first occurrence of a value from the array and returns [code]true[/code]. If the value does not exist in the array, nothing happens and [code]false[/code] is returned. To remove an element by index, use [method remove_at] instead.
90+
</description>
91+
</method>
8592
<method name="fill">
8693
<return type="void" />
8794
<param index="0" name="value" type="String" />

doc/classes/PackedVector2Array.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@
8282
Creates a copy of the array, and returns it.
8383
</description>
8484
</method>
85+
<method name="erase">
86+
<return type="bool" />
87+
<param index="0" name="value" type="Vector2" />
88+
<description>
89+
Removes the first occurrence of a value from the array and returns [code]true[/code]. If the value does not exist in the array, nothing happens and [code]false[/code] is returned. To remove an element by index, use [method remove_at] instead.
90+
[b]Note:[/b] Vectors with [constant @GDScript.NAN] elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.
91+
</description>
92+
</method>
8593
<method name="fill">
8694
<return type="void" />
8795
<param index="0" name="value" type="Vector2" />

doc/classes/PackedVector3Array.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@
8181
Creates a copy of the array, and returns it.
8282
</description>
8383
</method>
84+
<method name="erase">
85+
<return type="bool" />
86+
<param index="0" name="value" type="Vector3" />
87+
<description>
88+
Removes the first occurrence of a value from the array and returns [code]true[/code]. If the value does not exist in the array, nothing happens and [code]false[/code] is returned. To remove an element by index, use [method remove_at] instead.
89+
[b]Note:[/b] Vectors with [constant @GDScript.NAN] elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.
90+
</description>
91+
</method>
8492
<method name="fill">
8593
<return type="void" />
8694
<param index="0" name="value" type="Vector3" />

0 commit comments

Comments
 (0)