diff --git a/.gitignore b/.gitignore index 0af181c..9a1c2ab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ # Godot 4+ specific ignores .godot/ /android/ + +# custom ignores +symbol_cache/ diff --git a/caching.gd b/caching.gd index 35db0f1..3957374 100644 --- a/caching.gd +++ b/caching.gd @@ -134,7 +134,7 @@ func _get_card_data_from_bulk(dict_entry: Dictionary) -> Dictionary: func _get_mana_img(symbol: String, img_url: String) -> Error: fetch_start.emit() - if FileAccess.file_exists("user://card_cache/" + symbol + ".svg"): + if FileAccess.file_exists("res://symbol_cache/" + symbol + ".svg"): return OK var httpr = HTTPRequest.new() @@ -152,7 +152,7 @@ func _get_mana_img(symbol: String, img_url: String) -> Error: push_error(_cache_error("IMG_LOADING") + "Couldn't load the image.") return FAILED - img.save_png("user://symbol_cache/" + symbol.replace("/", "-") + ".png") + img.save_png("res://symbol_cache/" + symbol.replace("/", "-") + ".png") img = null fetch_done.emit() @@ -161,10 +161,11 @@ func _get_mana_img(symbol: String, img_url: String) -> Error: func _fetch_mana_symbols() -> Error: - if DirAccess.dir_exists_absolute("user://symbol_cache"): + var mana_symbols: Dictionary = Dictionary() + if DirAccess.dir_exists_absolute("res://symbol_cache"): return OK else: - DirAccess.make_dir_absolute("user://symbol_cache") + DirAccess.make_dir_absolute("res://symbol_cache") var httpr = HTTPRequest.new() add_child(httpr) @@ -179,8 +180,14 @@ func _fetch_mana_symbols() -> Error: var json_body = JSON.parse_string(unprocessed_body) for icon in json_body["data"]: err = await _get_mana_img(icon["symbol"], icon["svg_uri"]) - if err == OK: - print(icon["symbol"] + " image cached.") + if err != OK: + push_error("Couldn't fetch mana symbol " + icon["symbol"]) + mana_symbols[icon["symbol"]] = "res://symbol_cache/" + icon["symbol"].replace("/", "-") + ".png" + print(icon["symbol"] + " image cached.") + + var file = FileAccess.open("res://symbol_cache/symbols.json", FileAccess.WRITE) + file.store_line(JSON.stringify(mana_symbols)) + file.close() print("Done caching mana symbols.") return OK diff --git a/player.gd b/player.gd index 40ce7bf..5bbe065 100644 --- a/player.gd +++ b/player.gd @@ -17,7 +17,7 @@ func _ready() -> void: # TODO: Currently working with an already-cached card with a known ID to load this. # Later on, the cards should be pulling the IDs directly from the library's list of IDs. - card.init("d3f10f07-7cfe-4a6f-8de6-373e367a731b") + card.init("162e81d3-6cd4-4cb8-8ed8-cfbd8d34ca71") add_child(card) diff --git a/scenes/tooltip/card_text.gd b/scenes/tooltip/card_text.gd index 1ac97c5..80855c7 100644 --- a/scenes/tooltip/card_text.gd +++ b/scenes/tooltip/card_text.gd @@ -1,12 +1,39 @@ extends RichTextLabel +var mana_symbols: Dictionary + func _set_tip_text(card_info: Dictionary, _card_image: Image) -> void: text = card_info["name"] + " | " + card_info["type"] + "\n" - text += card_info["desc"] + var oracle_text = card_info["desc"] + var last_idx = 0 + # TODO: fix the string splitting here because its missing some symbols, and misplacing others + for symbol in mana_symbols: + if oracle_text.find(symbol, last_idx) == -1: + continue + text += oracle_text.substr(last_idx, oracle_text.find(symbol, last_idx)) + last_idx = oracle_text.find(symbol, last_idx) + symbol.length() + + # NOTE: + # add_image() from richtextlabel has no positioning, and just throws it at the end, + # so we need to use raw bbcode to actually do this intext + # it also needs to be in res:// to actually be able to access it + # for some reason bbcode can't read from user:// + text += "[img width=\"16\" height=\"16\"]" + mana_symbols[symbol] + "[/img]" + text += oracle_text.substr(last_idx, -1) + func _clear_tip_text() -> void: text = "" func _ready() -> void: + if !FileAccess.file_exists("res://symbol_cache/symbols.json"): + push_error("Symbols haven't been cached yet!") + return + var file = FileAccess.open("res://symbol_cache/symbols.json", FileAccess.READ) + mana_symbols = JSON.parse_string(file.get_as_text()) + file.close() + + set_use_bbcode(true) + EventBus.connect("card_on_hover", _set_tip_text) EventBus.connect("card_on_unhover", _clear_tip_text)