featured_gates_request

This commit is contained in:
Nordup 2024-04-10 11:44:04 +04:00
parent d86fea31c3
commit e5be40a3d0
4 changed files with 33 additions and 7 deletions

View file

@ -26,6 +26,11 @@ search_results = ExtResource("4_phjpd")
world_scene = ExtResource("4_p75rl")
scenes_root = NodePath("Menu/VBoxContainer/Body")
[node name="Debug" parent="." instance=ExtResource("7_3xeb8")]
[node name="Window" parent="Debug" index="0"]
visible = false
[node name="BookmarkSaver" type="Node" parent="."]
script = ExtResource("5_ev0ch")
save_dir = "user://resources"
@ -62,11 +67,6 @@ script = ExtResource("15_c1fxl")
api = ExtResource("10_04o5h")
bookmarks = ExtResource("6_rupvx")
[node name="Debug" parent="." instance=ExtResource("7_3xeb8")]
[node name="Window" parent="Debug" index="0"]
visible = false
[node name="Menu" parent="." instance=ExtResource("3_o1f7b")]
[editable path="Debug"]

View file

@ -3,11 +3,35 @@ extends Node
@export var api: ApiSettings
@export var bookmarks: Bookmarks
var result_str: String = "{}"
func _ready() -> void:
bookmarks.on_ready.connect(on_bookmarks_ready)
if bookmarks.is_ready: on_bookmarks_ready()
func on_bookmarks_ready() -> void:
if bookmarks.gates.size() > 0: return
# TODO: Get featured gates
await featured_gates_request()
Debug.logclr("Featured gates requested", Color.LIGHT_SEA_GREEN)
var gates = JSON.parse_string(result_str)
if gates == null or gates.is_empty():
Debug.logclr("No featured gates found", Color.YELLOW)
return
for gate in gates:
# TODO: download image and add to bookmarks
Debug.logr(gate["url"])
func featured_gates_request() -> void:
var callback = func(_result, code, _headers, body):
if code == 200:
result_str = body.get_string_from_utf8()
else: Debug.logclr("Featured gates request failed. Code " + str(code), Color.RED)
var err = await Backend.request(api.featured_gates, callback)
if err != HTTPRequest.RESULT_SUCCESS: Debug.logclr("Cannot send featured gates request", Color.RED)

View file

@ -8,6 +8,7 @@ signal save_image(gate: Gate)
@export var starred_gates: Array[Gate]
var is_ready: bool
var gates = {}
@ -16,6 +17,7 @@ func ready() -> void:
if gate == null or not Url.is_valid(gate.url): continue
gates[gate.url] = gate
is_ready = true
on_ready.emit()

View file

@ -4,7 +4,7 @@ extends VBoxContainer
@export var api: ApiSettings
@export var result_scene: PackedScene
var result_str: String
var result_str: String = "{}"
func _ready() -> void: