diff options
-rw-r--r-- | core/variant/variant_call.cpp | 31 | ||||
-rw-r--r-- | doc/classes/Array.xml | 15 | ||||
-rw-r--r-- | doc/classes/Dictionary.xml | 8 | ||||
-rw-r--r-- | doc/classes/PackedByteArray.xml | 7 | ||||
-rw-r--r-- | doc/classes/PackedColorArray.xml | 7 | ||||
-rw-r--r-- | doc/classes/PackedFloat32Array.xml | 7 | ||||
-rw-r--r-- | doc/classes/PackedFloat64Array.xml | 7 | ||||
-rw-r--r-- | doc/classes/PackedInt32Array.xml | 7 | ||||
-rw-r--r-- | doc/classes/PackedInt64Array.xml | 7 | ||||
-rw-r--r-- | doc/classes/PackedStringArray.xml | 7 | ||||
-rw-r--r-- | doc/classes/PackedVector2Array.xml | 7 | ||||
-rw-r--r-- | doc/classes/PackedVector3Array.xml | 7 | ||||
-rw-r--r-- | doc/classes/PackedVector4Array.xml | 7 |
13 files changed, 124 insertions, 0 deletions
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 63fb5e8d94..ab33c9db55 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -657,7 +657,23 @@ static _FORCE_INLINE_ void vc_ptrcall(void (*method)(T *, P...), void *p_base, c } \ }; +#define VARCALL_PACKED_GETTER(m_packed_type, m_return_type) \ + static m_return_type func_##m_packed_type##_get(m_packed_type *p_instance, int64_t p_index) { \ + return p_instance->get(p_index); \ + } + struct _VariantCall { + VARCALL_PACKED_GETTER(PackedByteArray, uint8_t) + VARCALL_PACKED_GETTER(PackedColorArray, Color) + VARCALL_PACKED_GETTER(PackedFloat32Array, float) + VARCALL_PACKED_GETTER(PackedFloat64Array, double) + VARCALL_PACKED_GETTER(PackedInt32Array, int32_t) + VARCALL_PACKED_GETTER(PackedInt64Array, int64_t) + VARCALL_PACKED_GETTER(PackedStringArray, String) + VARCALL_PACKED_GETTER(PackedVector2Array, Vector2) + VARCALL_PACKED_GETTER(PackedVector3Array, Vector3) + VARCALL_PACKED_GETTER(PackedVector4Array, Vector4) + static String func_PackedByteArray_get_string_from_ascii(PackedByteArray *p_instance) { String s; if (p_instance->size() > 0) { @@ -2268,6 +2284,7 @@ static void _register_variant_builtin_methods_misc() { bind_method(Dictionary, duplicate, sarray("deep"), varray(false)); bind_method(Dictionary, get, sarray("key", "default"), varray(Variant())); bind_method(Dictionary, get_or_add, sarray("key", "default"), varray(Variant())); + bind_method(Dictionary, set, sarray("key", "value"), varray()); bind_method(Dictionary, is_typed, sarray(), varray()); bind_method(Dictionary, is_typed_key, sarray(), varray()); bind_method(Dictionary, is_typed_value, sarray(), varray()); @@ -2293,6 +2310,8 @@ static void _register_variant_builtin_methods_array() { bind_method(Array, clear, sarray(), varray()); bind_method(Array, hash, sarray(), varray()); bind_method(Array, assign, sarray("array"), varray()); + bind_method(Array, get, sarray("index"), varray()); + bind_method(Array, set, sarray("index", "value"), varray()); bind_method(Array, push_back, sarray("value"), varray()); bind_method(Array, push_front, sarray("value"), varray()); bind_method(Array, append, sarray("value"), varray()); @@ -2337,6 +2356,18 @@ static void _register_variant_builtin_methods_array() { bind_method(Array, make_read_only, sarray(), varray()); bind_method(Array, is_read_only, sarray(), varray()); + /* Packed*Array get (see VARCALL_PACKED_GETTER macro) */ + bind_function(PackedByteArray, get, _VariantCall::func_PackedByteArray_get, sarray("index"), varray()); + bind_function(PackedColorArray, get, _VariantCall::func_PackedColorArray_get, sarray("index"), varray()); + bind_function(PackedFloat32Array, get, _VariantCall::func_PackedFloat32Array_get, sarray("index"), varray()); + bind_function(PackedFloat64Array, get, _VariantCall::func_PackedFloat64Array_get, sarray("index"), varray()); + bind_function(PackedInt32Array, get, _VariantCall::func_PackedInt32Array_get, sarray("index"), varray()); + bind_function(PackedInt64Array, get, _VariantCall::func_PackedInt64Array_get, sarray("index"), varray()); + bind_function(PackedStringArray, get, _VariantCall::func_PackedStringArray_get, sarray("index"), varray()); + bind_function(PackedVector2Array, get, _VariantCall::func_PackedVector2Array_get, sarray("index"), varray()); + bind_function(PackedVector3Array, get, _VariantCall::func_PackedVector3Array_get, sarray("index"), varray()); + bind_function(PackedVector4Array, get, _VariantCall::func_PackedVector4Array_get, sarray("index"), varray()); + /* Byte Array */ bind_method(PackedByteArray, size, sarray(), varray()); bind_method(PackedByteArray, is_empty, sarray(), varray()); diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index adb6be1070..1b7dbf7c41 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -422,6 +422,13 @@ [b]Note:[/b] Unlike with the [code][][/code] operator ([code]array[0][/code]), an error is generated without stopping project execution. </description> </method> + <method name="get" qualifiers="const"> + <return type="Variant" /> + <param index="0" name="index" type="int" /> + <description> + Returns the element at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]). + </description> + </method> <method name="get_typed_builtin" qualifiers="const"> <return type="int" /> <description> @@ -693,6 +700,14 @@ Returns the index of the [b]last[/b] element of the array that causes [param method] to return [code]true[/code], or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the beginning of the array. This method is the reverse of [method find_custom]. </description> </method> + <method name="set"> + <return type="void" /> + <param index="0" name="index" type="int" /> + <param index="1" name="value" type="Variant" /> + <description> + Sets the value of the element at the given [param index] to the given [param value]. This will not change the size of the array, it only changes the value at an index already in the array. This is the same as using the [code][][/code] operator ([code]array[index] = value[/code]). + </description> + </method> <method name="shuffle"> <return type="void" /> <description> diff --git a/doc/classes/Dictionary.xml b/doc/classes/Dictionary.xml index feb2a07e4a..4441c3cb79 100644 --- a/doc/classes/Dictionary.xml +++ b/doc/classes/Dictionary.xml @@ -460,6 +460,14 @@ Returns [code]true[/code] if the two dictionaries contain the same keys and values, inner [Dictionary] and [Array] keys and values are compared recursively. </description> </method> + <method name="set"> + <return type="bool" /> + <param index="0" name="key" type="Variant" /> + <param index="1" name="value" type="Variant" /> + <description> + Sets the value of the element at the given [param key] to the given [param value]. This is the same as using the [code][][/code] operator ([code]array[index] = value[/code]). + </description> + </method> <method name="size" qualifiers="const"> <return type="int" /> <description> diff --git a/doc/classes/PackedByteArray.xml b/doc/classes/PackedByteArray.xml index e179c111a2..75193ae8ed 100644 --- a/doc/classes/PackedByteArray.xml +++ b/doc/classes/PackedByteArray.xml @@ -307,6 +307,13 @@ Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. </description> </method> + <method name="get" qualifiers="const"> + <return type="int" /> + <param index="0" name="index" type="int" /> + <description> + Returns the byte at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]). + </description> + </method> <method name="get_string_from_ascii" qualifiers="const"> <return type="String" /> <description> diff --git a/doc/classes/PackedColorArray.xml b/doc/classes/PackedColorArray.xml index 57295cb1e3..b9cef0ead6 100644 --- a/doc/classes/PackedColorArray.xml +++ b/doc/classes/PackedColorArray.xml @@ -94,6 +94,13 @@ Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. </description> </method> + <method name="get" qualifiers="const"> + <return type="Color" /> + <param index="0" name="index" type="int" /> + <description> + Returns the [Color] at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]). + </description> + </method> <method name="has" qualifiers="const"> <return type="bool" /> <param index="0" name="value" type="Color" /> diff --git a/doc/classes/PackedFloat32Array.xml b/doc/classes/PackedFloat32Array.xml index 2db1386fd0..d421993b8f 100644 --- a/doc/classes/PackedFloat32Array.xml +++ b/doc/classes/PackedFloat32Array.xml @@ -93,6 +93,13 @@ [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. </description> </method> + <method name="get" qualifiers="const"> + <return type="float" /> + <param index="0" name="index" type="int" /> + <description> + Returns the 32-bit float at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]). + </description> + </method> <method name="has" qualifiers="const"> <return type="bool" /> <param index="0" name="value" type="float" /> diff --git a/doc/classes/PackedFloat64Array.xml b/doc/classes/PackedFloat64Array.xml index 0bcee918ed..4622d63258 100644 --- a/doc/classes/PackedFloat64Array.xml +++ b/doc/classes/PackedFloat64Array.xml @@ -94,6 +94,13 @@ [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. </description> </method> + <method name="get" qualifiers="const"> + <return type="float" /> + <param index="0" name="index" type="int" /> + <description> + Returns the 64-bit float at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]). + </description> + </method> <method name="has" qualifiers="const"> <return type="bool" /> <param index="0" name="value" type="float" /> diff --git a/doc/classes/PackedInt32Array.xml b/doc/classes/PackedInt32Array.xml index 93b2ae7394..3a3596b2d0 100644 --- a/doc/classes/PackedInt32Array.xml +++ b/doc/classes/PackedInt32Array.xml @@ -90,6 +90,13 @@ Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. </description> </method> + <method name="get" qualifiers="const"> + <return type="int" /> + <param index="0" name="index" type="int" /> + <description> + Returns the 32-bit integer at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]). + </description> + </method> <method name="has" qualifiers="const"> <return type="bool" /> <param index="0" name="value" type="int" /> diff --git a/doc/classes/PackedInt64Array.xml b/doc/classes/PackedInt64Array.xml index 3d34165915..cfaf012a55 100644 --- a/doc/classes/PackedInt64Array.xml +++ b/doc/classes/PackedInt64Array.xml @@ -91,6 +91,13 @@ Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. </description> </method> + <method name="get" qualifiers="const"> + <return type="int" /> + <param index="0" name="index" type="int" /> + <description> + Returns the 64-bit integer at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]). + </description> + </method> <method name="has" qualifiers="const"> <return type="bool" /> <param index="0" name="value" type="int" /> diff --git a/doc/classes/PackedStringArray.xml b/doc/classes/PackedStringArray.xml index 621831c7a3..511850d645 100644 --- a/doc/classes/PackedStringArray.xml +++ b/doc/classes/PackedStringArray.xml @@ -97,6 +97,13 @@ Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. </description> </method> + <method name="get" qualifiers="const"> + <return type="String" /> + <param index="0" name="index" type="int" /> + <description> + Returns the [String] at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]). + </description> + </method> <method name="has" qualifiers="const"> <return type="bool" /> <param index="0" name="value" type="String" /> diff --git a/doc/classes/PackedVector2Array.xml b/doc/classes/PackedVector2Array.xml index 14a3816353..da41812e0b 100644 --- a/doc/classes/PackedVector2Array.xml +++ b/doc/classes/PackedVector2Array.xml @@ -98,6 +98,13 @@ [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. </description> </method> + <method name="get" qualifiers="const"> + <return type="Vector2" /> + <param index="0" name="index" type="int" /> + <description> + Returns the [Vector2] at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]). + </description> + </method> <method name="has" qualifiers="const"> <return type="bool" /> <param index="0" name="value" type="Vector2" /> diff --git a/doc/classes/PackedVector3Array.xml b/doc/classes/PackedVector3Array.xml index 49220c6fd6..d47f2f3cd1 100644 --- a/doc/classes/PackedVector3Array.xml +++ b/doc/classes/PackedVector3Array.xml @@ -97,6 +97,13 @@ [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. </description> </method> + <method name="get" qualifiers="const"> + <return type="Vector3" /> + <param index="0" name="index" type="int" /> + <description> + Returns the [Vector3] at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]). + </description> + </method> <method name="has" qualifiers="const"> <return type="bool" /> <param index="0" name="value" type="Vector3" /> diff --git a/doc/classes/PackedVector4Array.xml b/doc/classes/PackedVector4Array.xml index fd0cfeb74b..6dbfc7413d 100644 --- a/doc/classes/PackedVector4Array.xml +++ b/doc/classes/PackedVector4Array.xml @@ -96,6 +96,13 @@ [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. </description> </method> + <method name="get" qualifiers="const"> + <return type="Vector4" /> + <param index="0" name="index" type="int" /> + <description> + Returns the [Vector4] at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]). + </description> + </method> <method name="has" qualifiers="const"> <return type="bool" /> <param index="0" name="value" type="Vector4" /> |