1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Merge pull request #100673 from RandomShaper/res_duplicate

Overhaul resource duplication
This commit is contained in:
Thaddeus Crews
2025-05-27 09:39:25 -05:00
19 changed files with 951 additions and 140 deletions

View File

@@ -0,0 +1,40 @@
# We could use @export_custom to really test every property usage, but we know for good
# that duplicating scripted properties flows through the same code already thoroughly tested
# in the [Resource] test cases. The same goes for all the potential deep duplicate modes.
# Therefore, it's enough to ensure the exported scriped properties are copied when invoking
# duplication by each entry point.
class TestResource:
extends Resource
@export var text: String = "holaaa"
@export var arr: Array = [1, 2, 3]
@export var dict: Dictionary = { "a": 1, "b": 2 }
func test():
# Via Resource type.
var res := TestResource.new()
var dupe: TestResource
dupe = res.duplicate()
print(dupe.text)
print(dupe.arr)
print(dupe.dict)
dupe = res.duplicate_deep()
print(dupe.text)
print(dupe.arr)
print(dupe.dict)
# Via Variant type.
var res_var = TestResource.new()
var dupe_var
dupe_var = res_var.duplicate()
print(dupe_var.text)
print(dupe_var.arr)
print(dupe_var.dict)
dupe_var = res_var.duplicate_deep()
print(dupe_var.text)
print(dupe_var.arr)
print(dupe_var.dict)

View File

@@ -0,0 +1,13 @@
GDTEST_OK
holaaa
[1, 2, 3]
{ "a": 1, "b": 2 }
holaaa
[1, 2, 3]
{ "a": 1, "b": 2 }
holaaa
[1, 2, 3]
{ "a": 1, "b": 2 }
holaaa
[1, 2, 3]
{ "a": 1, "b": 2 }