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" 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)