adds a lot holy crap i forgot to commit
This commit is contained in:
parent
a496bb3982
commit
c684a00f3a
54
caching.gd
54
caching.gd
@ -31,6 +31,8 @@ func setup() -> Error:
|
|||||||
if !_all_downloads_done():
|
if !_all_downloads_done():
|
||||||
push_error("Not done downloading Bulk Data.")
|
push_error("Not done downloading Bulk Data.")
|
||||||
return FAILED
|
return FAILED
|
||||||
|
|
||||||
|
_fetch_mana_symbols()
|
||||||
|
|
||||||
_setup_cache_in_mem()
|
_setup_cache_in_mem()
|
||||||
return OK
|
return OK
|
||||||
@ -130,6 +132,58 @@ func _get_card_data_from_bulk(dict_entry: Dictionary) -> Dictionary:
|
|||||||
|
|
||||||
return dict_entry
|
return dict_entry
|
||||||
|
|
||||||
|
func _get_mana_img(symbol: String, img_url: String) -> Error:
|
||||||
|
fetch_start.emit()
|
||||||
|
if FileAccess.file_exists("user://card_cache/" + symbol + ".svg"):
|
||||||
|
return OK
|
||||||
|
|
||||||
|
var httpr = HTTPRequest.new()
|
||||||
|
add_child(httpr)
|
||||||
|
|
||||||
|
var err = httpr.request(img_url, _req_headers)
|
||||||
|
if err != OK:
|
||||||
|
push_error(_cache_error("GET_REQUEST") + "An error occured in the Scryfall request.")
|
||||||
|
return FAILED
|
||||||
|
var resp = await httpr.request_completed
|
||||||
|
|
||||||
|
var img = Image.new()
|
||||||
|
err = img.load_svg_from_buffer(resp[3])
|
||||||
|
if err != OK:
|
||||||
|
push_error(_cache_error("IMG_LOADING") + "Couldn't load the image.")
|
||||||
|
return FAILED
|
||||||
|
|
||||||
|
img.save_png("user://symbol_cache/" + symbol.replace("/", "-") + ".png")
|
||||||
|
img = null
|
||||||
|
|
||||||
|
fetch_done.emit()
|
||||||
|
|
||||||
|
return OK
|
||||||
|
|
||||||
|
|
||||||
|
func _fetch_mana_symbols() -> Error:
|
||||||
|
if DirAccess.dir_exists_absolute("user://symbol_cache"):
|
||||||
|
return OK
|
||||||
|
else:
|
||||||
|
DirAccess.make_dir_absolute("user://symbol_cache")
|
||||||
|
|
||||||
|
var httpr = HTTPRequest.new()
|
||||||
|
add_child(httpr)
|
||||||
|
|
||||||
|
var err = httpr.request("https://api.scryfall.com/symbology", _req_headers)
|
||||||
|
if err != OK:
|
||||||
|
push_error(_cache_error("GET_REQUEST") + "An error occured in the Scryfall request.")
|
||||||
|
return FAILED
|
||||||
|
var resp = await httpr.request_completed
|
||||||
|
|
||||||
|
var unprocessed_body = resp[3].get_string_from_utf8()
|
||||||
|
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.")
|
||||||
|
|
||||||
|
print("Done caching mana symbols.")
|
||||||
|
return OK
|
||||||
|
|
||||||
func _fetch_card_img(data: Dictionary) -> Error:
|
func _fetch_card_img(data: Dictionary) -> Error:
|
||||||
fetch_start.emit()
|
fetch_start.emit()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
@warning_ignore("unused_signal")
|
@warning_ignore("unused_signal")
|
||||||
signal card_on_hover(val)
|
signal card_on_hover(card_info, card_image)
|
||||||
@warning_ignore("unused_signal")
|
@warning_ignore("unused_signal")
|
||||||
signal card_on_unhover()
|
signal card_on_unhover()
|
||||||
|
@ -6,6 +6,7 @@ extends Node2D
|
|||||||
|
|
||||||
# Card information.
|
# Card information.
|
||||||
var card_info: Dictionary
|
var card_info: Dictionary
|
||||||
|
var cached_image: Image
|
||||||
|
|
||||||
# Card properties.
|
# Card properties.
|
||||||
var tapped: bool
|
var tapped: bool
|
||||||
@ -55,7 +56,7 @@ func _on_mouse_entered() -> void:
|
|||||||
|
|
||||||
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
|
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
|
||||||
$TweenController.scale(1.05)
|
$TweenController.scale(1.05)
|
||||||
EventBus.emit_signal("card_on_hover", card_info)
|
EventBus.emit_signal("card_on_hover", card_info, cached_image)
|
||||||
|
|
||||||
|
|
||||||
func _on_mouse_exited() -> void:
|
func _on_mouse_exited() -> void:
|
||||||
|
@ -46,15 +46,23 @@ func _load_data() -> Error:
|
|||||||
|
|
||||||
|
|
||||||
func _load_image() -> Error:
|
func _load_image() -> Error:
|
||||||
# NOTE: Assuming we're going with using the .png cards on board.
|
|
||||||
var cached_img = FileAccess.get_file_as_bytes("user://card_cache/" + card.card_info["id"] + "/card.png")
|
var cached_img = FileAccess.get_file_as_bytes("user://card_cache/" + card.card_info["id"] + "/card.png")
|
||||||
|
|
||||||
if cached_img.is_empty():
|
if cached_img.is_empty():
|
||||||
push_error("%sCard on-board image was not found in cache" % card.error("CACHE"))
|
push_error("%sCard on-board image was not found in cache" % card.error("CACHE"))
|
||||||
return FAILED
|
return FAILED
|
||||||
|
|
||||||
|
var cache_image = Image.new()
|
||||||
|
var image_status: Error = cache_image.load_png_from_buffer(cached_img)
|
||||||
|
|
||||||
|
if image_status != OK:
|
||||||
|
push_error("%sCard on-board image failed to load correctly" % card.error("IMAGE"))
|
||||||
|
return FAILED
|
||||||
|
|
||||||
|
card.cached_image = cache_image
|
||||||
|
|
||||||
var image = Image.new()
|
var image = Image.new()
|
||||||
var image_status: Error = image.load_png_from_buffer(cached_img)
|
image_status = image.load_png_from_buffer(cached_img)
|
||||||
|
|
||||||
if image_status != OK:
|
if image_status != OK:
|
||||||
push_error("%sCard on-board image failed to load correctly" % card.error("IMAGE"))
|
push_error("%sCard on-board image failed to load correctly" % card.error("IMAGE"))
|
||||||
@ -69,4 +77,5 @@ func _load_image() -> Error:
|
|||||||
var card_sprite = card.get_node("Sprite2D")
|
var card_sprite = card.get_node("Sprite2D")
|
||||||
card_sprite.texture = image_texture
|
card_sprite.texture = image_texture
|
||||||
|
|
||||||
|
|
||||||
return OK
|
return OK
|
||||||
|
14
scenes/tooltip/card_image.gd
Normal file
14
scenes/tooltip/card_image.gd
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
extends TextureRect
|
||||||
|
|
||||||
|
func _set_tip_image(_card_info: Dictionary, card_image: Image) -> void:
|
||||||
|
card_image.resize(int(size.x / 1.75), int(size.y), Image.INTERPOLATE_LANCZOS)
|
||||||
|
var tex = ImageTexture.new()
|
||||||
|
tex.set_image(card_image)
|
||||||
|
texture = tex
|
||||||
|
|
||||||
|
func _clear_tip_image() -> void:
|
||||||
|
texture = null
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
EventBus.connect("card_on_hover", _set_tip_image)
|
||||||
|
EventBus.connect("card_on_unhover", _clear_tip_image)
|
1
scenes/tooltip/card_image.gd.uid
Normal file
1
scenes/tooltip/card_image.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://cpvbftm0swoa6
|
12
scenes/tooltip/card_text.gd
Normal file
12
scenes/tooltip/card_text.gd
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
extends RichTextLabel
|
||||||
|
|
||||||
|
func _set_tip_text(card_info: Dictionary, _card_image: Image) -> void:
|
||||||
|
text = card_info["name"] + " | " + card_info["type"] + "\n"
|
||||||
|
text += card_info["desc"]
|
||||||
|
|
||||||
|
func _clear_tip_text() -> void:
|
||||||
|
text = ""
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
EventBus.connect("card_on_hover", _set_tip_text)
|
||||||
|
EventBus.connect("card_on_unhover", _clear_tip_text)
|
1
scenes/tooltip/card_text.gd.uid
Normal file
1
scenes/tooltip/card_text.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://b8tioen4n1rip
|
@ -1,7 +1,8 @@
|
|||||||
[gd_scene load_steps=6 format=3 uid="uid://b4ldtb3gw0jlu"]
|
[gd_scene load_steps=7 format=3 uid="uid://b4ldtb3gw0jlu"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://cfkew150yl1y3" path="res://tabletop.gd" id="1_3we3x"]
|
[ext_resource type="Script" uid="uid://cfkew150yl1y3" path="res://tabletop.gd" id="1_3we3x"]
|
||||||
[ext_resource type="Script" uid="uid://brto6yniu3yx1" path="res://tooltip.gd" id="2_d43bn"]
|
[ext_resource type="Script" uid="uid://b8tioen4n1rip" path="res://scenes/tooltip/card_text.gd" id="2_d43bn"]
|
||||||
|
[ext_resource type="Script" uid="uid://cpvbftm0swoa6" path="res://scenes/tooltip/card_image.gd" id="2_pqag1"]
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_3we3x"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_3we3x"]
|
||||||
bg_color = Color(0, 0, 0, 1)
|
bg_color = Color(0, 0, 0, 1)
|
||||||
@ -35,6 +36,20 @@ theme_override_constants/separation = 0
|
|||||||
[node name="MenuArea" type="PanelContainer" parent="UI/BigBar/Items"]
|
[node name="MenuArea" type="PanelContainer" parent="UI/BigBar/Items"]
|
||||||
custom_minimum_size = Vector2(0, 540)
|
custom_minimum_size = Vector2(0, 540)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="UI/BigBar/Items/MenuArea"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="TextureRect" type="TextureRect" parent="UI/BigBar/Items/MenuArea/VBoxContainer"]
|
||||||
|
custom_minimum_size = Vector2(400, 300)
|
||||||
|
layout_direction = 2
|
||||||
|
layout_mode = 2
|
||||||
|
stretch_mode = 5
|
||||||
|
script = ExtResource("2_pqag1")
|
||||||
|
|
||||||
|
[node name="RichTextLabel" type="RichTextLabel" parent="UI/BigBar/Items/MenuArea/VBoxContainer"]
|
||||||
|
custom_minimum_size = Vector2(0, 230)
|
||||||
|
layout_mode = 2
|
||||||
script = ExtResource("2_d43bn")
|
script = ExtResource("2_d43bn")
|
||||||
|
|
||||||
[node name="ChatArea" type="PanelContainer" parent="UI/BigBar/Items"]
|
[node name="ChatArea" type="PanelContainer" parent="UI/BigBar/Items"]
|
||||||
|
20
tooltip.gd
20
tooltip.gd
@ -1,20 +0,0 @@
|
|||||||
extends PanelContainer
|
|
||||||
|
|
||||||
var back: ColorRect
|
|
||||||
|
|
||||||
func _clear_card_info():
|
|
||||||
tooltip_text = ""
|
|
||||||
back.color = Color(1,1,1,1)
|
|
||||||
|
|
||||||
func _display_card_info(card_info: Dictionary):
|
|
||||||
tooltip_text = "TEST"
|
|
||||||
back.color = Color(0,0,0,1)
|
|
||||||
|
|
||||||
func _ready():
|
|
||||||
back = ColorRect.new()
|
|
||||||
add_child(back)
|
|
||||||
|
|
||||||
back.color = Color(1, 1, 1, 1)
|
|
||||||
|
|
||||||
EventBus.connect("card_on_hover", _display_card_info)
|
|
||||||
EventBus.connect("card_on_unhover", _clear_card_info)
|
|
@ -1 +0,0 @@
|
|||||||
uid://brto6yniu3yx1
|
|
Loading…
x
Reference in New Issue
Block a user