diff --git a/godot/src/test/avatar/avatar_list.json b/godot/src/test/avatar/avatar_list.json index 17f0aa33..b87b3e7b 100644 --- a/godot/src/test/avatar/avatar_list.json +++ b/godot/src/test/avatar/avatar_list.json @@ -734,6 +734,78 @@ "urn:decentraland:off-chain:base-avatars:pearls_earring", "urn:decentraland:off-chain:base-avatars:f_mouth_05" ] + }, + { + "ref": "bafkreidyaysvsyof3f2s2k7ufmhkksm6lsawebg7bcdqlnzimwumu5qz7e", + "bodyShape": "urn:decentraland:off-chain:base-avatars:BaseMale", + "wearables": [ + "urn:decentraland:matic:collections-v2:0x4ea1cfe9e8ca641fbe362469f79029a0eaa6a996:0:1", + "urn:decentraland:matic:collections-v2:0xded1e53d7a43ac1844b66c0ca0f02627eb42e16d:7:737186041679900306885426193785693026232265667803843778780176842775", + "urn:decentraland:matic:collections-v2:0x80ec22f149a3f4727ba1ab91ddcefe9860ed4808:0:409", + "urn:decentraland:matic:collections-v2:0x3f0ba00d6a98db91f92e5e04accc9735a6fc562d:3:315936875005671560093754083051011296956685286201647333762932932618", + "urn:decentraland:matic:collections-v2:0x8cc5f22eec7b03c6a183499d7bb50679097ddfb6:0:10", + "urn:decentraland:matic:collections-v2:0x083230402677cad61d7a0cc040dc8a08cfeb809e:6:631873750011343120187508166102022593913370572403294667525865865251", + "urn:decentraland:matic:collections-v2:0xd1b84ae24b95f290211a6da61cde8d1b2647c711:0:5", + "urn:decentraland:matic:collections-v2:0xbad1c910568230c92c223b55564cf689928ec1b6:0:4", + "urn:decentraland:matic:collections-v2:0x5b7bd3e12f7d1461fc0ad370cd12402049b4b0d9:0:25", + "urn:decentraland:matic:collections-v2:0x324cb2c654be51c6ad6c76a3e022cabe49cc4e46:4:421249166674228746791672110734681729275580381602196445017243910158", + "urn:decentraland:off-chain:base-avatars:eyebrows_06", + "urn:decentraland:ethereum:collections-v1:halloween_2020:hwn_2020_cat_eyes:409", + "urn:decentraland:ethereum:collections-v1:halloween_2020:hwn_2020_pumpkin_mouth:394", + "urn:decentraland:matic:collections-v2:0xcbd17d94f5be12fff27566c23888d6936b8e70b8:6:631873750011343120187508166102022593913370572403294667525865865262" + ], + "forceRender": [ + "eyewear", + "hands_wear", + "facial_hair" + ] + }, + { + "description": "", + "avatar": { + "bodyShape": "urn:decentraland:off-chain:base-avatars:BaseMale", + "snapshots": { + "body": "https://peer-ec2.decentraland.org/content/contents/bafkreiegje2flk3yiyu5qelqiyx3uchkvvlegurmec36nbp5gz2pzwklny", + "face256": "https://peer-ec2.decentraland.org/content/contents/bafkreicbzfziozcirg5b4cxvhul67kzgl6grmhsa4zdrrpa2ttrierimgy" + }, + "eyes": { + "color": { + "r": 0.37109375, + "g": 0.22265625, + "b": 0.1953125 + } + }, + "hair": { + "color": { + "r": 0.234375, + "g": 0.12890625, + "b": 0.04296875 + } + }, + "skin": { + "color": { + "r": 0.94921875, + "g": 0.76171875, + "b": 0.6484375 + } + }, + "emotes": [], + "wearables": [ + "urn:decentraland:off-chain:base-avatars:eyes_00", + "urn:decentraland:off-chain:base-avatars:eyebrows_00", + "urn:decentraland:off-chain:base-avatars:mouth_00", + "urn:decentraland:off-chain:base-avatars:casual_hair_01", + "urn:decentraland:off-chain:base-avatars:beard", + "urn:decentraland:off-chain:base-avatars:sneakers", + "urn:decentraland:matic:collections-v2:0xd98aeb263b7709a8954ac8cc3c488494016cf785:0:12329" + ] + }, + "hasClaimedName": false, + "name": "Guest#ce46", + "tutorialStep": 0, + "version": 974, + "userId": "0xdb85ed07980d17a0e890af48f15e92199879ce46", + "ethAddress": "0xdb85ed07980d17a0e890af48f15e92199879ce46" } ], "emotes": [ diff --git a/godot/src/test/avatar/avatar_tester_standalone.gd b/godot/src/test/avatar/avatar_tester_standalone.gd index 1c6fef53..c6ac3bf4 100644 --- a/godot/src/test/avatar/avatar_tester_standalone.gd +++ b/godot/src/test/avatar/avatar_tester_standalone.gd @@ -11,8 +11,12 @@ var avatar_list: Array = [] @onready var line_edit_custom = $TabContainer/Emotes/LineEdit_Custom @onready var option_button_avatar_list = $TabContainer/Avatars/OptionButton_AvatarList +@onready var spinner = $Spinner +@onready var line_edit_profile_entity = $TabContainer/Avatars/LineEdit_ProfileEntity + func _ready(): + spinner.hide() load_avatar_list() avatar.avatar_loaded.connect(self._on_avatar_loaded) option_button_avatar_list.selected = -1 @@ -41,7 +45,7 @@ func load_avatar_list(): avatar_list = json_value.get("avatars", []) for avatar_i in avatar_list.size(): - option_button_avatar_list.add_item(avatar_list[avatar_i].ref, avatar_i) + option_button_avatar_list.add_item(avatar_list[avatar_i].get("ref", "no_ref"), avatar_i) func download_wearable(id: String): @@ -114,16 +118,20 @@ func _on_button_clear_pressed(): func _on_option_button_avatar_list_item_selected(index): var avatar_i = option_button_avatar_list.get_item_id(index) + _async_render_avatar(avatar_list[avatar_i]) + + +func _async_render_avatar(avatar_dict: Dictionary) -> void: var profile: DclUserProfile = DclUserProfile.new() var avatar_wf: DclAvatarWireFormat = profile.get_avatar() - avatar_wf.set_wearables(PackedStringArray(avatar_list[avatar_i].wearables)) - avatar_wf.set_force_render(avatar_list[avatar_i].get("forceRender", [])) - avatar_wf.set_body_shape(avatar_list[avatar_i].bodyShape) + avatar_wf.set_wearables(PackedStringArray(avatar_dict.wearables)) + avatar_wf.set_force_render(avatar_dict.get("forceRender", [])) + avatar_wf.set_body_shape(avatar_dict.bodyShape) - var skin_color = avatar_list[avatar_i].get("skin", {}).get("color", {}) - var eyes_color = avatar_list[avatar_i].get("eye", {}).get("color", {}) - var hair_color = avatar_list[avatar_i].get("hair", {}).get("color", {}) + var skin_color = avatar_dict.get("skin", {}).get("color", {}) + var eyes_color = avatar_dict.get("eye", {}).get("color", {}) + var hair_color = avatar_dict.get("hair", {}).get("color", {}) skin_color = Color(skin_color.get("r", 0.8), skin_color.get("g", 0.8), skin_color.get("b", 0.8)) eyes_color = Color(eyes_color.get("r", 0.8), eyes_color.get("g", 0.8), eyes_color.get("b", 0.8)) @@ -133,7 +141,9 @@ func _on_option_button_avatar_list_item_selected(index): avatar_wf.set_hair_color(hair_color) avatar_wf.set_skin_color(skin_color) + spinner.show() await avatar.async_update_avatar(avatar_wf, "") + spinner.hide() func _on_button_download_wearables_pressed(): @@ -146,3 +156,47 @@ func _on_button_copy_wearable_data_pressed(): func _on_button_refresh_pressed(): _on_option_button_avatar_list_item_selected(option_button_avatar_list.selected) + + +# gdlint:ignore = async-function-name +func _on_button_fetch_pressed(): + var avatars_fetched = null + spinner.show() + + if line_edit_profile_entity.text.begins_with("0x"): + var address = line_edit_profile_entity.text + var url = "https://peer.decentraland.org/lambdas/profiles/" + address + var promise: Promise = Global.http_requester.request_json( + url, HTTPClient.METHOD_GET, "", {} + ) + var response = await PromiseUtils.async_awaiter(promise) + + if response is PromiseError: + printerr("Error while fetching profile " + url, " reason: ", response.get_error()) + spinner.hide() + return + + var json: Dictionary = response.get_string_response_as_json() + avatars_fetched = json.get("avatars", []) + elif line_edit_profile_entity.text.begins_with("bafk"): + var url = "https://peer.decentraland.org/content/contents/" + line_edit_profile_entity.text + var promise: Promise = Global.http_requester.request_json( + url, HTTPClient.METHOD_GET, "", {} + ) + var response = await PromiseUtils.async_awaiter(promise) + + if response is PromiseError: + printerr("Error while fetching entity " + url, " reason: ", response.get_error()) + spinner.hide() + return + + var json: Dictionary = response.get_string_response_as_json() + avatars_fetched = json.get("metadata", {}).get("avatars", []) + + if avatars_fetched.is_empty(): + printerr("no avatars found") + spinner.hide() + return + + spinner.hide() + _async_render_avatar(avatars_fetched[0].get("avatar", {})) diff --git a/godot/src/test/avatar/avatar_tester_standalone.tscn b/godot/src/test/avatar/avatar_tester_standalone.tscn index d199f462..baa66da3 100644 --- a/godot/src/test/avatar/avatar_tester_standalone.tscn +++ b/godot/src/test/avatar/avatar_tester_standalone.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=7 format=3 uid="uid://4227l72a8kdu"] +[gd_scene load_steps=8 format=3 uid="uid://4227l72a8kdu"] [ext_resource type="PackedScene" uid="uid://cy43hvd5bivso" path="res://src/ui/components/backpack/avatar_preview.tscn" id="1_1eenv"] [ext_resource type="Script" path="res://src/test/avatar/avatar_tester_standalone.gd" id="1_l1th6"] [ext_resource type="Environment" uid="uid://c6yftsnvufsg8" path="res://assets/environment/cli_environment.tres" id="3_2n2br"] [ext_resource type="PackedScene" uid="uid://ec0egfeyv5fm" path="res://src/ui/components/emotes/emote_wheel.tscn" id="3_ubmva"] [ext_resource type="Texture2D" uid="uid://ckn18yn0v8tsa" path="res://src/ui/components/debug_panel/icons/Clear.svg" id="4_wetld"] +[ext_resource type="PackedScene" uid="uid://buu3ox7iefpgx" path="res://src/ui/components/loading_spinner/loading_spinner.tscn" id="6_wsp5b"] [sub_resource type="CodeHighlighter" id="CodeHighlighter_684t6"] number_color = Color(0, 0.670588, 0, 1) @@ -50,17 +51,17 @@ offset_bottom = 47.0 [node name="Button_DownloadWearables" type="Button" parent="TabContainer/Avatars"] layout_mode = 0 offset_left = 16.0 -offset_top = 64.0 +offset_top = 512.0 offset_right = 581.0 -offset_bottom = 111.0 +offset_bottom = 559.0 text = "Download wearables" [node name="Button_CopyWearableData" type="Button" parent="TabContainer/Avatars"] layout_mode = 0 offset_left = 16.0 -offset_top = 120.0 +offset_top = 568.0 offset_right = 581.0 -offset_bottom = 167.0 +offset_bottom = 615.0 text = "Copy wearables data" [node name="Button_Refresh" type="Button" parent="TabContainer/Avatars"] @@ -71,6 +72,22 @@ offset_right = 575.0 offset_bottom = 48.0 icon = ExtResource("4_wetld") +[node name="LineEdit_ProfileEntity" type="LineEdit" parent="TabContainer/Avatars"] +layout_mode = 0 +offset_left = 24.0 +offset_top = 88.0 +offset_right = 575.0 +offset_bottom = 127.0 +placeholder_text = "Profile Adress(0xff...) or Entity ID (bafk...)" + +[node name="Button_Fetch" type="Button" parent="TabContainer/Avatars"] +layout_mode = 0 +offset_left = 16.0 +offset_top = 136.0 +offset_right = 583.0 +offset_bottom = 174.0 +text = "Render Avatar" + [node name="Emotes" type="Panel" parent="TabContainer"] visible = false custom_minimum_size = Vector2(600, 600) @@ -193,10 +210,18 @@ text = "asdasd" editable = false wrap_mode = 1 +[node name="Spinner" parent="." instance=ExtResource("6_wsp5b")] +layout_mode = 0 +offset_left = 875.0 +offset_top = 257.0 +offset_right = 1003.0 +offset_bottom = 385.0 + [connection signal="item_selected" from="TabContainer/Avatars/OptionButton_AvatarList" to="." method="_on_option_button_avatar_list_item_selected"] [connection signal="pressed" from="TabContainer/Avatars/Button_DownloadWearables" to="." method="_on_button_download_wearables_pressed"] [connection signal="pressed" from="TabContainer/Avatars/Button_CopyWearableData" to="." method="_on_button_copy_wearable_data_pressed"] [connection signal="pressed" from="TabContainer/Avatars/Button_Refresh" to="." method="_on_button_refresh_pressed"] +[connection signal="pressed" from="TabContainer/Avatars/Button_Fetch" to="." method="_on_button_fetch_pressed"] [connection signal="pressed" from="TabContainer/Emotes/Button_OpenWheel" to="." method="_on_button_open_wheel_pressed"] [connection signal="pressed" from="TabContainer/Emotes/Button_PlayCustom" to="." method="_on_button_play_custom_pressed"] [connection signal="pressed" from="TabContainer/Emotes/Button_Clear" to="." method="_on_button_clear_pressed"]