From de5e107b869de7d4231fe86520857f5e2fd10908 Mon Sep 17 00:00:00 2001 From: Nathan Singer Date: Wed, 23 Apr 2025 13:05:47 -0400 Subject: [PATCH] adds a signal for completion, card should be done --- card.gd | 18 ++++++++++-------- player.gd | 20 +++++++++++++------- player.tscn | 4 +--- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/card.gd b/card.gd index 6804d96..5c9ddca 100644 --- a/card.gd +++ b/card.gd @@ -9,14 +9,14 @@ extends Node # in the helper text box, but thats for the future const ManaCosts = preload("res://data/mana.gd") -var cached = false +signal cache_done var card_id = "placedholder_id" var card_name = "placeholder_name" var card_type = "placeholder_card_type" var oracle_text = "placeholder_oracle_text" -var png_path = "placeholder_image_path" -var jpg_path = "placeholder_image_path" +var _png_path = "placeholder_image_path" +var _jpg_path = "placeholder_image_path" func _card_error(error_type: String) -> String: return "CARD::" + card_id + "::" + error_type + "\n" @@ -25,13 +25,15 @@ func _init(id) -> void: card_id = id func _ready() -> void: + if (_check_cache(card_id)): + return await _do_cache_grab() func _do_cache_grab() -> void: await _do_http_request_card() - await _do_http_request_imgs(png_path, true) - await _do_http_request_imgs(jpg_path, false) - + await _do_http_request_imgs(_png_path, true) + await _do_http_request_imgs(_jpg_path, false) + cache_done.emit() func _check_cache(id: String) -> bool: if (!FileAccess.file_exists("user://card_cache/" + id + "/card.json")): @@ -94,8 +96,8 @@ func _do_http_request_card() -> void: card_cache = null # closes the file var image_uris = card_content["image_uris"] - png_path = image_uris["png"] - jpg_path = image_uris["normal"] + _png_path = image_uris["png"] + _jpg_path = image_uris["normal"] ## load_card ## diff --git a/player.gd b/player.gd index 7dfe5e4..c7cb1a0 100644 --- a/player.gd +++ b/player.gd @@ -2,22 +2,28 @@ extends Node2D var _card_class = preload("res://card.gd") +var card + func _on_request_completed(result, response_code, headers, body): var json = JSON.parse_string(body.get_string_from_utf8()) print(json["name"]) -# Called when the node enters the scene tree for the first time. -func _ready() -> void: - # TODO: Create 2-4 player instances as children of this tabletop node. - var card = _card_class.new("d3f10f07-7cfe-4a6f-8de6-373e367a731b") - add_child(card) - +func _test_func(): card.load_card() - print(card.card_id) print(card.card_name) print(card.card_type) print(card.oracle_text) + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + # TODO: Create 2-4 player instances as children of this tabletop node. + card = _card_class.new("d3f10f07-7cfe-4a6f-8de6-373e367a731b") + add_child(card) + + card.cache_done.connect(_test_func) + pass # Replace with function body. diff --git a/player.tscn b/player.tscn index 8d34023..dc9a8c5 100644 --- a/player.tscn +++ b/player.tscn @@ -1,7 +1,6 @@ -[gd_scene load_steps=3 format=3 uid="uid://cx0vga81xwckh"] +[gd_scene load_steps=2 format=3 uid="uid://cx0vga81xwckh"] [ext_resource type="Script" uid="uid://w2rqm1u7p7im" path="res://player.gd" id="1_4flbx"] -[ext_resource type="Script" uid="uid://b3yqd1qu7dyq" path="res://card.gd" id="2_onrkg"] [node name="Player" type="Node2D"] script = ExtResource("1_4flbx") @@ -9,7 +8,6 @@ script = ExtResource("1_4flbx") [node name="Field" type="Node2D" parent="."] [node name="Hand" type="Node2D" parent="."] -script = ExtResource("2_onrkg") [node name="Library" type="Node2D" parent="."]