mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2026-01-05 14:10:19 +03:00
Merge Sphinx translations with Weblate translations, sync classref
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
.. DO NOT EDIT THIS FILE!!!
|
||||
.. Generated automatically from Godot engine sources.
|
||||
.. Generator: https://github.com/godotengine/godot/tree/4.4/doc/tools/make_rst.py.
|
||||
.. XML source: https://github.com/godotengine/godot/tree/4.4/doc/classes/Array.xml.
|
||||
.. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
|
||||
.. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Array.xml.
|
||||
|
||||
.. _class_Array:
|
||||
|
||||
@@ -28,7 +28,7 @@ Array
|
||||
print(array[0]) # 输出“第一”
|
||||
print(array[2]) # 输出 3
|
||||
print(array[-1]) # 输出“最后”
|
||||
|
||||
|
||||
array[1] = "第二"
|
||||
print(array[1]) # 输出“第二”
|
||||
print(array[-3]) # 输出“第二”
|
||||
@@ -39,7 +39,7 @@ Array
|
||||
GD.Print(array[0]); // 输出“开头”
|
||||
GD.Print(array[2]); // 输出 3
|
||||
GD.Print(array[^1]); // 输出“最后”
|
||||
|
||||
|
||||
array[2] = "第二";
|
||||
GD.Print(array[1]); // 输出“第二”
|
||||
GD.Print(array[^3]); // 输出“第二”
|
||||
@@ -123,6 +123,8 @@ Array
|
||||
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`Array<class_Array>` | :ref:`duplicate<class_Array_method_duplicate>`\ (\ deep\: :ref:`bool<class_bool>` = false\ ) |const| |
|
||||
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`Array<class_Array>` | :ref:`duplicate_deep<class_Array_method_duplicate_deep>`\ (\ deep_subresources_mode\: :ref:`int<class_int>` = 1\ ) |const| |
|
||||
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| |void| | :ref:`erase<class_Array_method_erase>`\ (\ value\: :ref:`Variant<class_Variant>`\ ) |
|
||||
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| |void| | :ref:`fill<class_Array_method_fill>`\ (\ value\: :ref:`Variant<class_Variant>`\ ) |
|
||||
@@ -267,10 +269,10 @@ Array
|
||||
|
||||
class_name Sword
|
||||
extends Node
|
||||
|
||||
|
||||
class Stats:
|
||||
pass
|
||||
|
||||
|
||||
func _ready():
|
||||
var a = Array([], TYPE_INT, "", null) # Array[int]
|
||||
var b = Array([], TYPE_OBJECT, "Node", null) # Array[Node]
|
||||
@@ -285,7 +287,7 @@ Array
|
||||
|
||||
var numbers: Array[float] = []
|
||||
var children: Array[Node] = [$Node, $Sprite2D, $RigidBody3D]
|
||||
|
||||
|
||||
var integers: Array[int] = [0.2, 4.5, -2.0]
|
||||
print(integers) # 输出 [0, 4, -2]
|
||||
|
||||
@@ -425,13 +427,13 @@ Array
|
||||
|
||||
func greater_than_5(number):
|
||||
return number > 5
|
||||
|
||||
|
||||
func _ready():
|
||||
print([6, 10, 6].all(greater_than_5)) # 输出 true (3/3 元素被评估为真)。
|
||||
print([4, 10, 4].all(greater_than_5)) # 输出 false (1/3 元素被评估为真)。
|
||||
print([4, 4, 4].all(greater_than_5)) # 输出 false (0/3 元素被评估为真)。
|
||||
print([].all(greater_than_5)) # 输出 true (0/0 元素被评估为真)。
|
||||
|
||||
|
||||
# 与上面的第一行相同,但使用 lambda 函数。
|
||||
print([6, 10, 6].all(func(element): return element > 5)) # 输出 true
|
||||
|
||||
@@ -441,7 +443,7 @@ Array
|
||||
{
|
||||
return number > 5;
|
||||
}
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
// 输出 True (3/3 元素被评估为真)。
|
||||
@@ -452,7 +454,7 @@ Array
|
||||
GD.Print(new Godot.Collections.Array>int< { 4, 4, 4 }.All(GreaterThan5));
|
||||
// 输出 True (0/0 元素被评估为真)。
|
||||
GD.Print(new Godot.Collections.Array>int< { }.All(GreaterThan5));
|
||||
|
||||
|
||||
// 与上面的第一行相同,但使用 lambda 函数。
|
||||
GD.Print(new Godot.Collections.Array>int< { 6, 10, 6 }.All(element => element > 5)); // 输出 True
|
||||
}
|
||||
@@ -483,13 +485,13 @@ Array
|
||||
|
||||
func greater_than_5(number):
|
||||
return number > 5
|
||||
|
||||
|
||||
func _ready():
|
||||
print([6, 10, 6].any(greater_than_5)) # 输出 true (3 个元素被评估为真)。
|
||||
print([4, 10, 4].any(greater_than_5)) #输出 true (1 个元素被评估为真)。
|
||||
print([4, 4, 4].any(greater_than_5)) # 输出 false (0 个元素被评估为真)。
|
||||
print([].any(greater_than_5)) # 输出 false (0 个元素被评估为真)。
|
||||
|
||||
|
||||
# 与上面的第一行相同,但使用 lambda 函数。
|
||||
print([6, 10, 6].any(func(number): return number > 5)) # 输出 true
|
||||
|
||||
@@ -574,10 +576,10 @@ Array
|
||||
|
||||
var numbers = [2, 4, 8, 10]
|
||||
var idx = numbers.bsearch(7)
|
||||
|
||||
|
||||
numbers.insert(idx, 7)
|
||||
print(numbers) # 输出 [2, 4, 7, 8, 10]
|
||||
|
||||
|
||||
var fruits = ["Apple", "Lemon", "Lemon", "Orange"]
|
||||
print(fruits.bsearch("Lemon", true)) # 输出 1,位于第一个 "Lemon"。
|
||||
print(fruits.bsearch("Lemon", false)) # 输出 3,位于 "Orange"。
|
||||
@@ -606,18 +608,18 @@ Array
|
||||
if a[1] < b[1]:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _ready():
|
||||
var my_items = [["Tomato", 2], ["Kiwi", 5], ["Rice", 9]]
|
||||
|
||||
|
||||
var apple = ["Apple", 5]
|
||||
# "Apple" 被插入在 "Kiwi" 之前。
|
||||
my_items.insert(my_items.bsearch_custom(apple, sort_by_amount, true), apple)
|
||||
|
||||
|
||||
var banana = ["Banana", 5]
|
||||
# "Banana" 被插入在 "Kiwi" 之后。
|
||||
my_items.insert(my_items.bsearch_custom(banana, sort_by_amount, false), banana)
|
||||
|
||||
|
||||
# 输出 [["Tomato", 2], ["Apple", 5], ["Kiwi", 5], ["Banana", 5], ["Rice", 9]]
|
||||
print(my_items)
|
||||
|
||||
@@ -661,9 +663,23 @@ Array
|
||||
|
||||
返回数组的新副本。
|
||||
|
||||
默认情况下返回的是\ **浅拷贝**\ :嵌套的 **Array** 和 :ref:`Dictionary<class_Dictionary>` 元素与原数组共享。对这些元素的修改会影响另一个数组。
|
||||
默认情况下返回的是\ **浅拷贝**\ :嵌套的 **Array**\ 、\ :ref:`Dictionary<class_Dictionary>` 和 :ref:`Resource<class_Resource>` 元素与原数组共享。对这些元素的修改会影响另一个数组。
|
||||
|
||||
如果 ``deep`` 为 ``true`` 则会返回\ **深拷贝**\ :嵌套的数组和字典也会进行(递归的)复制。
|
||||
如果 ``deep`` 为 ``true`` 则会返回\ **深拷贝**\ :嵌套的数组和字典也会进行(递归的)复制。不过 :ref:`Resource<class_Resource>` 仍然是和原数组共享的。
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
----
|
||||
|
||||
.. _class_Array_method_duplicate_deep:
|
||||
|
||||
.. rst-class:: classref-method
|
||||
|
||||
:ref:`Array<class_Array>` **duplicate_deep**\ (\ deep_subresources_mode\: :ref:`int<class_int>` = 1\ ) |const| :ref:`🔗<class_Array_method_duplicate_deep>`
|
||||
|
||||
深度复制该数组,类似 :ref:`duplicate()<class_Array_method_duplicate>`\ ``(true)``\ ,但能够额外控制子资源的处理方式。
|
||||
|
||||
\ ``deep_subresources_mode`` 必须是 :ref:`DeepDuplicateMode<enum_Resource_DeepDuplicateMode>` 中的一个值。默认只会(递归)复制内部资源。
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
@@ -734,10 +750,10 @@ Array
|
||||
|
||||
func is_even(number):
|
||||
return number % 2 == 0
|
||||
|
||||
|
||||
func _ready():
|
||||
print([1, 4, 5, 8].filter(is_even)) # 输出 [4, 8]
|
||||
|
||||
|
||||
# 与上面相同,但使用 lambda 函数。
|
||||
print([1, 4, 5, 8].filter(func(number): return number % 2 == 0))
|
||||
|
||||
@@ -782,7 +798,7 @@ Array
|
||||
|
||||
func is_even(number):
|
||||
return number % 2 == 0
|
||||
|
||||
|
||||
func _ready():
|
||||
print([1, 3, 4, 7].find_custom(is_even.bind())) # 输出 2
|
||||
|
||||
@@ -812,7 +828,9 @@ Array
|
||||
|
||||
:ref:`Variant<class_Variant>` **get**\ (\ index\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_Array_method_get>`
|
||||
|
||||
返回数组中给定索引 ``index`` 位置的元素。这与使用 ``[]`` 运算符(\ ``array[index]``\ )是一样的。
|
||||
返回数组中索引为 ``index`` 的元素。如果 ``index`` 越界或为负数,则该方法失败并返回 ``null``\ 。
|
||||
|
||||
该方法类似于 ``[]`` 运算符(但不等价)。最显著的区别就是从编辑器中运行时,该方法失败不会暂停项目运行。
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
@@ -916,7 +934,7 @@ Array
|
||||
|
||||
:ref:`int<class_int>` **insert**\ (\ position\: :ref:`int<class_int>`, value\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_Array_method_insert>`
|
||||
|
||||
在数组中给定索引(\ ``position``\ )处插入新元素(\ ``value``\ )。\ ``position`` 应介于 ``0`` 和数组的 :ref:`size()<class_Array_method_size>` 之间。
|
||||
在数组中给定索引(\ ``position``\ )处插入新元素(\ ``value``\ )。\ ``position`` 应介于 ``0`` 和数组的 :ref:`size()<class_Array_method_size>` 之间。如果为负数,则认为 ``position`` 为相对于数组结尾的索引。
|
||||
|
||||
如果成功,则返回 :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>`\ ;如果该方法失败,则返回其他 :ref:`Error<enum_@GlobalScope_Error>` 常量之一。
|
||||
|
||||
@@ -1011,10 +1029,10 @@ Array
|
||||
|
||||
func double(number):
|
||||
return number * 2
|
||||
|
||||
|
||||
func _ready():
|
||||
print([1, 2, 3].map(double)) # 输出 [2, 4, 6]
|
||||
|
||||
|
||||
# 与上面相同,但使用 lambda 函数。
|
||||
print([1, 2, 3].map(func(element): return element * 2))
|
||||
|
||||
@@ -1087,7 +1105,7 @@ Array
|
||||
|
||||
移除并返回数组中位于 ``position`` 索引处的元素。如果 ``position`` 为负数,则认为是相对于该数组末尾的值。如果数组为空,则返回 ``null``\ ;如果 ``position`` 超出范围,还会生成错误消息。
|
||||
|
||||
\ **注意:**\ 该方法将 ``position`` 之后每个元素的索引向后移动,这可能会产生明显的性能成本,尤其是在较大的数组上。
|
||||
\ **注意:**\ 该方法将 ``position`` 之后每个元素的索引向前移动,这可能会产生明显的性能成本,尤其是在较大的数组上。
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
@@ -1159,11 +1177,11 @@ Array
|
||||
|
||||
func sum(accum, number):
|
||||
return accum + number
|
||||
|
||||
|
||||
func _ready():
|
||||
print([1, 2, 3].reduce(sum, 0)) # 输出 6
|
||||
print([1, 2, 3].reduce(sum, 10)) # 输出 16
|
||||
|
||||
|
||||
# 与上面相同,但是使用 lambda 函数。
|
||||
print([1, 2, 3].reduce(func(accum, number): return accum + number, 10))
|
||||
|
||||
@@ -1173,10 +1191,10 @@ Array
|
||||
|
||||
func _ready():
|
||||
var arr = [Vector2i(5, 0), Vector2i(3, 4), Vector2i(1, 2)]
|
||||
|
||||
|
||||
var longest_vec = arr.reduce(func(max, vec): return vec if is_length_greater(vec, max) else max)
|
||||
print(longest_vec) # 输出 (3, 4)
|
||||
|
||||
|
||||
func is_length_greater(a, b):
|
||||
return a.length() > b.length()
|
||||
|
||||
@@ -1186,7 +1204,7 @@ Array
|
||||
|
||||
func is_even(number):
|
||||
return number % 2 == 0
|
||||
|
||||
|
||||
func _ready():
|
||||
var arr = [1, 2, 3, 4, 5]
|
||||
# 当前元素为偶数则增加计数器,否则保持计数不变。
|
||||
@@ -1205,11 +1223,11 @@ Array
|
||||
|
||||
|void| **remove_at**\ (\ position\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Array_method_remove_at>`
|
||||
|
||||
从数组中移除指定索引(\ ``position``\ )处的元素。如果索引超出范围,则该方法失败。
|
||||
从数组中移除指定索引(\ ``position``\ )处的元素。如果索引超出范围,则该方法失败。如果为负数,则认为 ``position`` 为相对于数组结尾的索引。
|
||||
|
||||
如果需要返回被移除的元素,请使用 :ref:`pop_at()<class_Array_method_pop_at>`\ 。要按值移除元素,请改用 :ref:`erase()<class_Array_method_erase>`\ 。
|
||||
|
||||
\ **注意:**\ 该方法将 ``position`` 之后每个元素的索引向后移,这可能会产生明显的性能成本,尤其是在较大的数组上。
|
||||
\ **注意:**\ 该方法将 ``position`` 之后每个元素的索引向前移动,这可能会产生明显的性能成本,尤其是在较大的数组上。
|
||||
|
||||
\ **注意:**\ ``position`` 不能为负数。要移除相对于数组末尾的元素,请使用 ``arr.remove_at(arr.size() - (i + 1))``\ 。要从数组中移除最后一个元素,请使用 ``arr.resize(arr.size() - 1)``\ 。
|
||||
|
||||
@@ -1225,7 +1243,7 @@ Array
|
||||
|
||||
将数组的元素数设置为 ``size``\ 。如果 ``size`` 小于数组的当前大小,则移除末尾的元素。如果 ``size`` 大于数组的当前大小,则添加新的默认元素(通常为 ``null``\ ),具体取决于数组的类型。
|
||||
|
||||
如果成功,则返回 :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>`\ ;如果该方法失败,则返回其他 :ref:`Error<enum_@GlobalScope_Error>` 常量之一。
|
||||
如果成功则返回 :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>`\ ,如果该方法失败则返回其他 :ref:`Error<enum_@GlobalScope_Error>` 常量之一:数组只读时为 :ref:`@GlobalScope.ERR_LOCKED<class_@GlobalScope_constant_ERR_LOCKED>`\ ,大小为负数时为 :ref:`@GlobalScope.ERR_INVALID_PARAMETER<class_@GlobalScope_constant_ERR_INVALID_PARAMETER>`\ ,分配失败时为 :ref:`@GlobalScope.ERR_OUT_OF_MEMORY<class_@GlobalScope_constant_ERR_OUT_OF_MEMORY>`\ 。请使用 :ref:`size()<class_Array_method_size>` 查看数组调整后的实际大小。
|
||||
|
||||
\ **注意:**\ 调用该方法一次并分配新值,要比为每个新元素调用 :ref:`append()<class_Array_method_append>` 更快。
|
||||
|
||||
@@ -1319,16 +1337,16 @@ Array
|
||||
|
||||
如果 ``step`` 为负数,则该方法反向遍历数组,返回按反向顺序排列的切片数组。要使其起作用,\ ``begin`` 必须大于 ``end``\ 。
|
||||
|
||||
如果 ``deep`` 为 ``true``\ ,则切片数组中所有嵌套的 **Array** 和 :ref:`Dictionary<class_Dictionary>` 元素都将从原始元素中递归复制。另见 :ref:`duplicate()<class_Array_method_duplicate>`)。
|
||||
如果 ``deep`` 为 ``true``\ ,则切片数组中所有嵌套的 **Array** 和 :ref:`Dictionary<class_Dictionary>` 元素都将从原始元素中递归复制。另见 :ref:`duplicate()<class_Array_method_duplicate>`\ 。
|
||||
|
||||
::
|
||||
|
||||
var letters = ["A", "B", "C", "D", "E", "F"]
|
||||
|
||||
|
||||
print(letters.slice(0, 2)) # 输出 ["A", "B"]
|
||||
print(letters.slice(2, -2)) # 输出 ["C", "D"]
|
||||
print(letters.slice(-2, 6)) # 输出 ["E", "F"]
|
||||
|
||||
|
||||
print(letters.slice(0, 6, 2)) # 输出 ["A", "C", "E"]
|
||||
print(letters.slice(4, 1, -1)) # 输出 ["E", "D", "C"]
|
||||
|
||||
@@ -1383,12 +1401,12 @@ Array
|
||||
if a[1] < b[1]:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _ready():
|
||||
var my_items = [["Tomato", 5], ["Apple", 9], ["Rice", 4]]
|
||||
my_items.sort_custom(sort_ascending)
|
||||
print(my_items) # 输出 [["Rice", 4], ["Tomato", 5], ["Apple", 9]]
|
||||
|
||||
|
||||
# 使用 lambda 函数按降序排序。
|
||||
my_items.sort_custom(func(a, b): return a[0] > b[0])
|
||||
print(my_items) # 输出 [["Apple", 9], ["Tomato", 5], ["Rice", 4]]
|
||||
@@ -1537,6 +1555,7 @@ Array
|
||||
返回指定 ``index`` 处的 :ref:`Variant<class_Variant>` 元素。数组从索引 0 开始。如果 ``index`` 大于或等于 ``0``\ ,则从数组开头开始获取元素。如果 ``index`` 为负值,则从末尾开始获取元素。越界访问数组将导致运行时错误,从编辑器中运行时会暂停项目执行。
|
||||
|
||||
.. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)`
|
||||
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
||||
.. |const| replace:: :abbr:`const (本方法无副作用,不会修改该实例的任何成员变量。)`
|
||||
.. |vararg| replace:: :abbr:`vararg (本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。)`
|
||||
.. |constructor| replace:: :abbr:`constructor (本方法用于构造某个类型。)`
|
||||
|
||||
Reference in New Issue
Block a user