Card Overlay/Biggercard Issues(Solved)

Godot Version

4.3

Question

Hello everyone. It’s my first time posting here and I’m really having some issues.

I am trying to create a TCG game and currently ran into a wall. I’m trying to increase readability of the cards by having a biggercard instantiate on the middle right side. However, when I hover over the card, its only showing me the back of the card.

Here is the current code of the BiggerCard.gd. Please note that there’s no straight node for this one as the cards instantiate from the Player Hand. I have already had the CardDatabase.gd which contains the card data along with the code for recalling the png image. The names also match and whatnot.

extends Node2D

signal hovered
signal hovered_off

var starting_position
var card_slot_card_is_in
var card_type
var defense
var attack
var defeated = false
var ability_script
var ability_text

var card_database = CardDatabase

Preload the CardDatabase script

var CardDatabase = preload(“res://Scripts/CardDatabase.gd”)

Reference to the player hand or relevant parent node where cards are stored

var player_hand

Called when the node enters the scene tree for the first time.

func _ready() → void:
# Access the CardDatabase singleton and assign it to the variable
CardDatabase = CardDatabase

print("Checking CardDatabase singleton: ", CardDatabase)
print("Type of CardDatabase: ", typeof(CardDatabase))

# Ensure player hand exists and we can access cards from it
player_hand = get_parent()  # Assuming the player hand is the parent node
if player_hand != null:
	# Connect signals or perform relevant actions on the player hand
	player_hand.connect("hovered", Callable(self, "_on_card_hovered"))
	print("Card database initialization check.")
	
	# Access CardDatabase directly as it's a global singleton
	if CardDatabase != null:
		card_database = CardDatabase
		print("Card database successfully loaded.")  # Confirm it's loaded
	else:
		# Attempt to load manually
		card_database = preload("res://Scripts/CardDatabase.gd").new()
		if card_database != null:
			print("Card database manually initialized.")
		else:
			print("Error: Could not initialize the card database.")
else:
	print("Error: PlayerHand node not found.")

Handling the hover event and passing the card to BiggerCard

func _on_card_hovered(card):
# Handle the hovered card here
print("Card hovered: ", card.name) # Debugging
$BiggerCard.setup(card)

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _process(delta: float) → void:
pass

func _on_area_2d_mouse_entered() → void:
emit_signal(“hovered”, self) # ‘self’ is the card object

func _on_area_2d_mouse_exited() → void:
emit_signal(“hovered_off”, self)

Setup function to retrieve card data based on the passed card

func setup(card):
print("Card Object: ", card) # Debugging
var card_name = card.name # Use the name of the hovered card
print("Card Name: ", card_name)

# Check if the card database is properly initialized
if CardDatabase != null and CardDatabase.CARDS.has(card_name):
	var card_data = card_database.get_card_data(card_name)
	if card_data != null:
		card_name = card_data [0] # Card Name
		attack = card_data[1]  # Attack
		defense = card_data[2]  # Defense
		card_type = card_data[4]  # Card Type
		ability_script = card_data[5]  # Ability Script
		ability_text = card_data[6]  # Ability Text
		
		print("Card Found: ", card_name)
		print("Attack: ", attack, " Defense: ", defense)
		
		# Load and set the card image
		var card_affinity = card_data[3]  # Affinity
		var card_image_path = "res://Cards/" + card_affinity + "/" + card_data["Card Name"] + ".png"
		if FileAccess.file_exists(card_image_path):
			$CardImage.texture = load(card_image_path)
			print("Card Image Loaded: ", card_image_path)
		else:
			print("Error: Card image not found for ", card_name)
	else:
		print("Error: Card data is null for ", card_name)

func update_visuals(original_card):
# Update the BiggerCard’s visuals to match the hovered card
$CardImage.texture = original_card.get_node(“CardImage”).texture

# Get card details from the database
var card_data = CardDatabase.CARDS[original_card.name]
if card_data:
	print("Updated Card Name: ", original_card.name)
	attack = card_data.attack
	defense = card_data.defense