diff --git a/card.gd b/card.gd index 7234c47..1ad0dfe 100644 --- a/card.gd +++ b/card.gd @@ -18,6 +18,9 @@ var oracle_text = "placeholder_oracle_text" 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" + func _init(id) -> void: card_id = id @@ -46,7 +49,7 @@ func _do_http_request_imgs(image_path: String, png: bool) -> void: var headers = PackedStringArray(["User-Agent: MTGUntapClone/0.1", "Accept: */*"]) var error = httpr.request(image_path, headers) if error != OK: - push_error("An error occurred in the Scryfall request.") + push_error(_card_error("GET_REQUEST") + "An error occurred in the Scryfall request.") var response = await httpr.request_completed var img = Image.new() @@ -56,7 +59,7 @@ func _do_http_request_imgs(image_path: String, png: bool) -> void: else: imgerr = img.load_jpg_from_buffer(response[3]) if imgerr != OK: - push_error("couldn't load the image.") + push_error(_card_error("IMG_LOADING") + "Couldn't load the image.") img.save_png("user://card_cache/" + card_id + ("/card.png" if png else "/card.jpg")) img = null @@ -68,19 +71,19 @@ func _do_http_request_card() -> void: var headers = PackedStringArray(["User-Agent: MTGUntapClone/0.1", "Accept: */*"]) var error = httpr.request("https://api.scryfall.com/cards/" + card_id, headers) if error != OK: - push_error("An error occurred in the Scryfall request.") + push_error(_card_error("GET_REQUEST") + "An error occurred in the Scryfall request.") var response = await httpr.request_completed if response[0] != HTTPRequest.RESULT_SUCCESS: - push_error("Failed to fetch card data from Scryfall") + push_error(_card_error("GET_REQUEST") + "Failed to fetch card data from Scryfall") return var unprocessed_body = response[3].get_string_from_utf8() var card_content = JSON.parse_string(unprocessed_body) if (card_content == null): - push_error("Failed to parse the Scryfall card results.") + push_error(_card_error("PARSING") + "Failed to parse the Scryfall card results.") var dir = DirAccess.open("user://") dir.make_dir_recursive("user://card_cache/" + card_id + "/") # lets ensure the path is there @@ -94,14 +97,14 @@ func _do_http_request_card() -> void: png_path = image_uris["png"] jpg_path = image_uris["normal"] -func load_card(id) -> bool: - if !_check_cache(id): +func load_card() -> bool: + if !_check_cache(card_id): await do_cache_grab() - push_error("Cache wasn't ready, this card will need to be reinitialized") + push_error(_card_error("CACHE_FAIL") + "Cache wasn't ready, this card will need to be reinitialized") return false - var ondisk_card = FileAccess.open("user://card_cache/" + id + "/card.json", FileAccess.READ) + var ondisk_card = FileAccess.open("user://card_cache/" + card_id + "/card.json", FileAccess.READ) var card_json = JSON.parse_string(ondisk_card.get_as_text()) card_name = card_json["name"] diff --git a/player.gd b/player.gd index e7061a0..7dfe5e4 100644 --- a/player.gd +++ b/player.gd @@ -12,6 +12,8 @@ func _ready() -> void: var card = _card_class.new("d3f10f07-7cfe-4a6f-8de6-373e367a731b") add_child(card) + card.load_card() + print(card.card_id) print(card.card_name) print(card.card_type) diff --git a/tabletop.gd b/tabletop.gd index 725cb7b..3970446 100644 --- a/tabletop.gd +++ b/tabletop.gd @@ -8,8 +8,6 @@ var player_class = preload("res://player.gd") func _ready() -> void: # TODO: Create 2-4 player instances as children of this tabletop node. - - var player = player_class.new() add_child(player)