40 lines
1.3 KiB
GDScript
40 lines
1.3 KiB
GDScript
extends RichTextLabel
|
|
|
|
var mana_symbols: Dictionary
|
|
|
|
func _convert_text_to_symbol(_text: String):
|
|
var last_idx = 0
|
|
for symbol in mana_symbols:
|
|
last_idx = 0
|
|
while _text.find(symbol, last_idx) != -1:
|
|
_text = _text.replace(symbol, "[img]" + mana_symbols[symbol] + "[/img]")
|
|
last_idx = _text.find(symbol, last_idx) + symbol.length()
|
|
return _text
|
|
|
|
func _set_tip_text(card_info: Dictionary, _card_image: Image) -> void:
|
|
# TODO: add more card formatting, check all of the logos, very niche icons will be affected i believe since they're
|
|
# different sizes
|
|
# shrink text if we use too much space for it, etc
|
|
text = "[b]" + card_info["name"] + "[/b]\t"
|
|
text += _convert_text_to_symbol(card_info["cost"]) + "\n"
|
|
text += "[i]" + card_info["type"] + "[/i]\n"
|
|
|
|
text += _convert_text_to_symbol(card_info["desc"])
|
|
|
|
|
|
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)
|