untap/card.gd

52 lines
1.4 KiB
GDScript

extends Node
# we want to use this to convert the mana cost into text
# in the helper text box, but thats for the future
const ManaCosts = preload("res://data/mana.gd")
var cached = false
var card_id = "placedholder_id"
var card_name = "placeholder_name"
var card_type = "placeholder_card_type"
var oracle_text = "placeholder_oracle_text"
var image_path = "placeholder_image_path"
func _check_cache(id) -> bool:
if (FileAccess.file_exists("user://card_cache/" + id + ".json")):
return true
return false
func _do_scryfall_get(id) -> void:
# TODO: fetch the card here...
var fetched = false
if !fetched:
print("Failed to fetch card data from scryfall")
var card_content = "fetched_card_json" #TODO
var card_cache = FileAccess.open("user://card_cache/" + id + ".json", FileAccess.WRITE)
card_cache.store_string(card_content)
card_cache = null # closes the file
# store image at the same spot ("user://card_cache/id.png")
func load_card(id) -> void:
if !(_check_cache(id)):
_do_scryfall_get(id)
var ondisk_card = FileAccess.open("user://card_cache/" + id + ".json", FileAccess.READ)
# parse json here to get card content
card_id = id
card_name = "loaded_cardname"
card_type = "loaded_type"
oracle_text = "loaded_oracletext"
image_path = "loaded_image_path"
ondisk_card = null
pass
## these variables above will be used for the helper boxes we draw
## on hover, to make cards easier to read