From 545618d58ff7a3fa562dc90eec9d3a3bb9630dc6 Mon Sep 17 00:00:00 2001
From: Alan <alanjfogel@gmail.com>
Date: Fri, 7 Feb 2025 17:08:36 -0600
Subject: [PATCH] Seperated game logic and state from the shop to the game
 script

---
 .godot/editor/create_recent.Node              |  2 +-
 .godot/editor/editor_layout.cfg               | 10 +--
 .godot/editor/filesystem_update4              |  9 +++
 ...state-c2a7af834e91ff64325daddf58e45dc0.cfg |  2 +-
 ...lding-c2a7af834e91ff64325daddf58e45dc0.cfg |  2 +-
 ...state-3070c538c03ee49b7677ff960a3f5195.cfg |  2 +-
 .godot/editor/project_metadata.cfg            |  2 +-
 .godot/editor/script_editor_cache.cfg         | 12 ++--
 scenes/Shop.tscn                              | 61 ++-----------------
 scenes/game.tscn                              |  1 +
 scripts/Shop.gd                               | 60 ++++++++----------
 scripts/game.gd                               | 56 +++++++++--------
 12 files changed, 90 insertions(+), 129 deletions(-)

diff --git a/.godot/editor/create_recent.Node b/.godot/editor/create_recent.Node
index b7fd6c6..701732f 100644
--- a/.godot/editor/create_recent.Node
+++ b/.godot/editor/create_recent.Node
@@ -1,3 +1,4 @@
+ColorRect
 Label
 TextureRect
 HBoxContainer
@@ -9,6 +10,5 @@ Node2D
 Node
 Control
 AnimationPlayer
-ColorRect
 CanvasLayer
 Sprite2D
diff --git a/.godot/editor/editor_layout.cfg b/.godot/editor/editor_layout.cfg
index 90deb6b..393bb09 100644
--- a/.godot/editor/editor_layout.cfg
+++ b/.godot/editor/editor_layout.cfg
@@ -10,7 +10,7 @@ dock_split_2=0
 dock_split_3=0
 dock_hsplit_1=0
 <<<<<<<HEADdock_hsplit_2=498
-dock_hsplit_3=-436
+dock_hsplit_3=-318
 dock_hsplit_2=306
 dock_hsplit_4=0
 dock_filesystem_h_split_offset=240
@@ -27,16 +27,16 @@ dock_5="Inspector,Node,History"
 [EditorNode]
 
 open_scenes=PackedStringArray("res://scenes/game.tscn", "res://main.tscn", "res://scenes/Shop.tscn", "res://scenes/ShopItem.tscn")
-current_scene="res://scenes/ShopItem.tscn"
-center_split_offset=-314
+current_scene="res://scenes/game.tscn"
+center_split_offset=-336
 selected_default_debugger_tab_idx=0
-selected_main_editor_idx=0
+selected_main_editor_idx=2
 selected_bottom_panel_item=0
 
 [ScriptEditor]
 
 open_scripts=["res://scripts/game.gd", "res://README.md", "res://scripts/scene_manager.gd", "res://scripts/Shop.gd"]
-selected_script="res://scripts/Shop.gd"
+selected_script="res://scripts/game.gd"
 open_help=[]
 script_split_offset=70
 list_split_offset=0
diff --git a/.godot/editor/filesystem_update4 b/.godot/editor/filesystem_update4
index bc232df..89772e7 100644
--- a/.godot/editor/filesystem_update4
+++ b/.godot/editor/filesystem_update4
@@ -11,3 +11,12 @@ res://scenes/Shop.tscn
 res://scripts/Shop.gd
 res://scenes/ShopItem.tscn
 res://scripts/Piece.gd
+res://scripts/Pawn.gd
+res://scripts/Rook.gd
+res://scripts/Bishop.gd
+res://scripts/Queen.gd
+res://scripts/King.gd
+res://scripts/Knight.gd
+res://scripts/Assassin.gd
+res://scripts/Mage.gd
+res://scripts/Wizard.gd
diff --git a/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg b/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg
index e9cdfcf..9f24398 100644
--- a/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg
+++ b/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg
@@ -175,4 +175,4 @@ Anim={
 "zfar": 4000.01,
 "znear": 0.05
 }
-selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/ShopItem/MarginContainer/VBoxContainer/ItemSprite")])
+selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/Game/GoldDisplay")])
diff --git a/.godot/editor/game.tscn-folding-c2a7af834e91ff64325daddf58e45dc0.cfg b/.godot/editor/game.tscn-folding-c2a7af834e91ff64325daddf58e45dc0.cfg
index 07cfab6..c74d2ef 100644
--- a/.godot/editor/game.tscn-folding-c2a7af834e91ff64325daddf58e45dc0.cfg
+++ b/.godot/editor/game.tscn-folding-c2a7af834e91ff64325daddf58e45dc0.cfg
@@ -1,5 +1,5 @@
 [folding]
 
-node_unfolds=[NodePath("."), PackedStringArray("opponent_shader", "Editor Description"), NodePath("ShadowContainer"), PackedStringArray("Ordering"), NodePath("TileContainer"), PackedStringArray("Transform", "Ordering"), NodePath("PieceContainer"), PackedStringArray("Ordering", "Process", "Texture"), NodePath("Background"), PackedStringArray("Layout", "material", "Ordering", "Layout/Transform", "Layout/Grow Direction", "Layout/Container Sizing", "Layout/Anchor Points", "Layout/Anchor Offsets", "Texture"), NodePath("Explosion"), PackedStringArray("Ordering", "Transform", "Scale", "Time"), NodePath("PlayerPieces"), PackedStringArray("Transform"), NodePath("OpponentPieces"), PackedStringArray("Visibility", "Transform")]
+node_unfolds=[NodePath("."), PackedStringArray("opponent_shader", "Editor Description"), NodePath("ShadowContainer"), PackedStringArray("Ordering"), NodePath("TileContainer"), PackedStringArray("Transform", "Ordering"), NodePath("PieceContainer"), PackedStringArray("Ordering", "Process", "Texture"), NodePath("Background"), PackedStringArray("Layout", "material", "Ordering", "Layout/Transform", "Layout/Grow Direction", "Layout/Container Sizing", "Layout/Anchor Points", "Layout/Anchor Offsets", "Texture"), NodePath("Explosion"), PackedStringArray("Ordering", "Transform", "Scale", "Time"), NodePath("PlayerPieces"), PackedStringArray("Transform"), NodePath("OpponentPieces"), PackedStringArray("Visibility", "Transform"), NodePath("GoldDisplay"), PackedStringArray("Theme Overrides", "Theme Overrides/fonts", "Theme Overrides/font_sizes")]
 resource_unfolds=["res://scenes/game.tscn::ShaderMaterial_gdbwp", PackedStringArray("Shader Parameters", "Resource")]
 nodes_folded=[]
diff --git a/.godot/editor/main.tscn-editstate-3070c538c03ee49b7677ff960a3f5195.cfg b/.godot/editor/main.tscn-editstate-3070c538c03ee49b7677ff960a3f5195.cfg
index a564203..04f445f 100644
--- a/.godot/editor/main.tscn-editstate-3070c538c03ee49b7677ff960a3f5195.cfg
+++ b/.godot/editor/main.tscn-editstate-3070c538c03ee49b7677ff960a3f5195.cfg
@@ -175,4 +175,4 @@ Anim={
 "zfar": 4000.01,
 "znear": 0.05
 }
-selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/ShopItem/MarginContainer/VBoxContainer/ItemSprite")])
+selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/Game/GoldDisplay")])
diff --git a/.godot/editor/project_metadata.cfg b/.godot/editor/project_metadata.cfg
index 0fc6f8d..6f5dc72 100644
--- a/.godot/editor/project_metadata.cfg
+++ b/.godot/editor/project_metadata.cfg
@@ -21,4 +21,4 @@ last_selected_language="GDScript"
 [color_picker]
 
 picker_shape=3
-recent_presets=PackedColorArray(0.408717, 0.672092, 0.458479, 1)
+recent_presets=PackedColorArray(0, 0, 0, 1, 0, 0, 0, 0.313726, 0, 0, 0.137255, 0.313726, 4.81308e-08, 9.62615e-08, 0.540356, 0.313726, 0, 0, 1, 0.313726, 0, 0, 1, 0.156863, 0, 1, 1, 0.156863, 0, 1, 0, 0.156863, 1, 1, 0, 0.156863)
diff --git a/.godot/editor/script_editor_cache.cfg b/.godot/editor/script_editor_cache.cfg
index 43d3b31..afb3ebd 100644
--- a/.godot/editor/script_editor_cache.cfg
+++ b/.godot/editor/script_editor_cache.cfg
@@ -17,11 +17,11 @@ state={
 state={
 "bookmarks": PackedInt32Array(),
 "breakpoints": PackedInt32Array(),
-"column": 16,
+"column": 32,
 "folded_lines": Array[int]([]),
 "h_scroll_position": 0,
-"row": 47,
-"scroll_position": 38.0,
+"row": 551,
+"scroll_position": 534.0,
 "selection": false,
 "syntax_highlighter": "GDScript"
 }
@@ -31,11 +31,11 @@ state={
 state={
 "bookmarks": PackedInt32Array(),
 "breakpoints": PackedInt32Array(),
-"column": 33,
+"column": 0,
 "folded_lines": Array[int]([]),
 "h_scroll_position": 0,
-"row": 72,
-"scroll_position": 60.0,
+"row": 74,
+"scroll_position": 55.0,
 "selection": false,
 "syntax_highlighter": "GDScript"
 }
diff --git a/scenes/Shop.tscn b/scenes/Shop.tscn
index 5ba5fde..1be6046 100644
--- a/scenes/Shop.tscn
+++ b/scenes/Shop.tscn
@@ -1,69 +1,21 @@
-[gd_scene load_steps=3 format=3 uid="uid://ct878s7wjsq77"]
+[gd_scene load_steps=2 format=3 uid="uid://ct878s7wjsq77"]
 
 [ext_resource type="Script" path="res://scripts/Shop.gd" id="1_8nmap"]
 
-[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_rcoi1"]
-size = Vector2(16, 16)
-
 [node name="Shop" type="Node2D"]
 script = ExtResource("1_8nmap")
 
-[node name="Background" type="TextureRect" parent="."]
-visible = false
-offset_right = 131.0
-offset_bottom = 101.0
-
-[node name="Item1" type="Button" parent="."]
-visible = false
-anchors_preset = 8
-anchor_left = 0.5
-anchor_top = 0.5
-anchor_right = 0.5
-anchor_bottom = 0.5
-offset_left = -59.0
-offset_top = 30.0
-offset_right = -2.0
-offset_bottom = 61.0
-grow_horizontal = 2
-grow_vertical = 2
-text = "Item 1"
-
-[node name="Item2" type="Button" parent="."]
-visible = false
-offset_left = 2.0
-offset_top = 30.0
-offset_right = 59.0
-offset_bottom = 61.0
-text = "Item 2"
-
 [node name="MainContainer" type="MarginContainer" parent="."]
-offset_right = 40.0
-offset_bottom = 40.0
+offset_right = 180.0
+offset_bottom = 246.0
 theme_override_constants/margin_left = 20
 theme_override_constants/margin_top = 20
 theme_override_constants/margin_right = 20
 theme_override_constants/margin_bottom = 20
 
-[node name="GoldDisplay" type="MarginContainer" parent="MainContainer"]
-layout_mode = 2
-size_flags_horizontal = 8
-size_flags_vertical = 0
-theme_override_constants/margin_top = 20
-theme_override_constants/margin_right = 20
-
-[node name="HBoxContainer" type="HBoxContainer" parent="MainContainer/GoldDisplay"]
-layout_mode = 2
-theme_override_constants/separation = 10
-
-[node name="GoldIcon" type="TextureRect" parent="MainContainer/GoldDisplay/HBoxContainer"]
-layout_mode = 2
-texture = SubResource("PlaceholderTexture2D_rcoi1")
-stretch_mode = 2
-
-[node name="GoldAmount" type="Label" parent="MainContainer/GoldDisplay/HBoxContainer"]
+[node name="Background" type="ColorRect" parent="MainContainer"]
 layout_mode = 2
-theme_override_font_sizes/font_size = 24
-text = "0"
+color = Color(1, 1, 0, 0.156863)
 
 [node name="RowsContainer" type="VBoxContainer" parent="MainContainer"]
 layout_mode = 2
@@ -96,7 +48,4 @@ size_flags_horizontal = 8
 text = "Next Round
 "
 
-[connection signal="item_purchased" from="." to="." method="_on_item_purchased"]
-[connection signal="pressed" from="Item1" to="." method="_on_item_1_pressed"]
-[connection signal="pressed" from="Item2" to="." method="_on_item_2_pressed"]
 [connection signal="pressed" from="MainContainer/RowsContainer/BottomSection/NextRoundButton" to="." method="_on_next_round_button_pressed"]
diff --git a/scenes/game.tscn b/scenes/game.tscn
index 3a2e163..6c13944 100644
--- a/scenes/game.tscn
+++ b/scenes/game.tscn
@@ -85,5 +85,6 @@ offset_top = 36.0
 offset_right = -2.0
 offset_bottom = 103.0
 grow_horizontal = 0
+theme_override_font_sizes/font_size = 26
 
 [connection signal="pressed" from="ShopButton" to="." method="_on_shop_button_pressed"]
diff --git a/scripts/Shop.gd b/scripts/Shop.gd
index 2e95e57..17f4a2d 100644
--- a/scripts/Shop.gd
+++ b/scripts/Shop.gd
@@ -1,31 +1,26 @@
 # Shop.gd
 extends Node2D
 
-signal item_purchased(item_name: String)  # Define the signal
-signal gold_spent(amount: int)
+signal purchase_attempted(item_data: Dictionary)
 signal next_round_requested
 
-@onready var gold_display: Label = $GoldDisplay
 @onready var shop_item_scene = preload("res://scenes/ShopItem.tscn")
-@onready var gold_amount: Label = $MainContainer/GoldDisplay/HBoxContainer/GoldAmount
-@onready var gold_icon: TextureRect = $MainContainer/GoldDisplay/HBoxContainer/GoldIcon
 
-var player_gold: int = 0
 
 var shop_items = {
 	"pieces": [
-		{"name": "Pawn", "price": 1, "texture": "res://assets/Resized Chess Piece Assets/White_Pawn.png"},
-		{"name": "Rook", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/White_Rook.png"},
-		{"name": "Bishop", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/White_Bishop.png"},
-		{"name": "Knight", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/White_Knight.png"},
-		{"name": "Queen", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/White_Queen.png"}
+		{"name": "Pawn", "price": 1, "texture": "res://assets/Resized Chess Piece Assets/White_Pawn.png", "purchased": false},
+		{"name": "Rook", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/White_Rook.png", "purchased": false},
+		{"name": "Bishop", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/White_Bishop.png", "purchased": false},
+		{"name": "Knight", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/White_Knight.png", "purchased": false},
+		{"name": "Queen", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/White_Queen.png", "purchased": false}
 	],
 	"upgrades": [
-		{"name": "Upgrade 1", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/Black_Pawn.png"},
-		{"name": "Upgrade 2", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Rook.png"},
-		{"name": "Upgrade 3", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Bishop.png"},
-		{"name": "Upgrade 4", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Knight.png"},
-		{"name": "Upgrade 5", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Queen.png"}
+		{"name": "Upgrade 1", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/Black_Pawn.png", "purchased": false},
+		{"name": "Upgrade 2", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Rook.png", "purchased": false},
+		{"name": "Upgrade 3", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Bishop.png", "purchased": false},
+		{"name": "Upgrade 4", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Knight.png", "purchased": false},
+		{"name": "Upgrade 5", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Queen.png", "purchased": false}
 	]
 }
 
@@ -33,26 +28,28 @@ func _ready():
 	self.visible = false  # Start hidden
 	print("Shop scene loaded!")  # Check if this prints
 	populate_rows()  # Populate the shop rows
-	update_gold_display(player_gold)  # Initialize gold display
 	
 func set_visibility(visible: bool):
 	self.visible = visible
-	
-func update_gold_display(gold: int):
-	player_gold = gold  # Store gold locally for shop logic
-	gold_amount.text = str(gold)  # Update the label text
 
 func _on_back_button_pressed():
 	get_tree().change_scene_to_file("res://Game.tscn")  # Return to game
 
 func populate_rows():
 	for item in shop_items["pieces"]:
-		add_item_to_row(item, $MainContainer/RowsContainer/PiecesRow)
+		# Create a copy to avoid modifying the original data
+		var item_copy = item.duplicate()
+		add_item_to_row(item_copy, $MainContainer/RowsContainer/PiecesRow)
+
 	for item in shop_items["upgrades"]:
-		add_item_to_row(item, $MainContainer/RowsContainer/UpgradesRow)
+		var item_copy = item.duplicate()
+		add_item_to_row(item_copy, $MainContainer/RowsContainer/UpgradesRow)
 
 
 func add_item_to_row(item_data: Dictionary, row: HBoxContainer):
+	if item_data["purchased"]:
+		return  # Skip purchased items
+
 	var shop_item = shop_item_scene.instantiate()
 
 	shop_item.get_node("MarginContainer/VBoxContainer/ItemName").text = item_data["name"]
@@ -63,21 +60,18 @@ func add_item_to_row(item_data: Dictionary, row: HBoxContainer):
 	var buy_button = shop_item.get_node("MarginContainer/VBoxContainer/BuyButton")
 
 	# Connect the button to a handler, passing the item_data
-	buy_button.connect("pressed", Callable(self, "_on_item_purchased").bind(item_data))
+	buy_button.connect("pressed", Callable(self, "_on_buy_button_pressed").bind(item_data))
 
 	row.add_child(shop_item)
 
-func _on_item_purchased(item_data: Dictionary):
-	if player_gold >= item_data["price"]:
-		player_gold -= item_data["price"]
-		update_gold_display(player_gold)
-		emit_signal("gold_spent", item_data["price"])  # Emit the signal
-		emit_signal("item_purchased", item_data["name"])  # Notify the main game
-		print("Purchased: ", item_data["name"])
+func _on_buy_button_pressed(item_data: Dictionary):
+	if !item_data["purchased"]:
+		print("Attempting to Purchase: ", item_data["name"])
+		# Emit signals to let Game.gd handle the purchase
+		emit_signal("purchase_attempted", item_data)  # Emit the full item data
 		# TODO: Add a sound effect / Animation for purchasing items
 	else:
-		# TODO: Add a sound effect / warning for not enough gold
-		print("Not enough gold!")
+		print("Item already purchased!")
 	
 
 
diff --git a/scripts/game.gd b/scripts/game.gd
index ae3d7f8..9da1e2c 100644
--- a/scripts/game.gd
+++ b/scripts/game.gd
@@ -4,6 +4,8 @@ class_name game
 var player_gold: int = 10
 var shop_scene = preload("res://scenes/Shop.tscn")
 var shop: Node2D
+var purchased_pieces: Array = []
+var purchased_upgrades: Array = []
 
 @export var tile_size = 64
 @export var dark = Color(0,0,0,1)
@@ -48,8 +50,9 @@ func _ready() -> void:
 	add_child(shop)
 	shop.position = Vector2(200, 10)
 	shop.visible = false  # Start hidden
-	shop.gold_spent.connect(_on_gold_spent)
 	update_gold_display()  # Initialize gold display
+	set_gold_display_position() # Set the anchors and margins for the gold display
+	shop.purchase_attempted.connect(_on_purchase_attempted)
 	shop.next_round_requested.connect(_on_next_round_requested)
 	
 	DisplayServer.window_set_min_size(Vector2(1152, 648))  # Set minimum window size
@@ -500,34 +503,32 @@ func shoot_projectile(x: int, y: int):
 	
 # Shop Stuff
 func _on_shop_button_pressed():
-	print("Attempting to open shop...")
 	shop.visible = !shop.visible
-	shop.update_gold_display(player_gold)  # Pass current gold to shop
+	update_gold_display()  # Pass current gold to shop
 	piece_container.visible = !piece_container.visible
 	shadow_container.visible = !shadow_container.visible
 	tile_container.visible = !tile_container.visible
-	print("Shop added to scene tree!")  # Check if this prints
-
-# Signal handler method
-func _on_item_purchased(item_name: String):
-	print("Signal received: ", item_name)
-	match item_name:
-		"item1":
-			player_gold -= 1
-			print("Purchased Item 1! Remaining gold: ", player_gold)
-			# Add logic to apply the item effect
-		"item2":
-			player_gold -= 2
-			print("Purchased Item 2! Remaining gold: ", player_gold)
-
-
-func _on_shop_item_purchased(item_name: String) -> void:
-	print("Signal received: ", item_name)
-	match item_name:
-		"item1":
-			player_gold -= 10
-			print("Purchased Item 1! Remaining gold: ", player_gold)
 
+func _on_purchase_attempted(item_data: Dictionary):
+	# Check gold here where we have access to the real value
+	if player_gold >= item_data["price"]:
+		# Deduct gold and mark the item as purchased
+		player_gold -= item_data["price"]
+		item_data["purchased"] = true
+
+		# Track purchased items
+		if item_data in shop.shop_items["pieces"]:
+			purchased_pieces.append(item_data)
+		elif item_data in shop.shop_items["upgrades"]:
+			purchased_upgrades.append(item_data)
+
+		# Update UI and print debug info
+		update_gold_display()
+		print("Purchased: ", item_data["name"])
+		print("Remaining gold: ", player_gold)
+	else:
+		# TODO: Play sound / animation for not enough gold
+		print("Not enough gold!")
 
 func _on_gold_spent(amount: int):
 	player_gold -= amount
@@ -543,3 +544,10 @@ func _on_next_round_requested():
 	piece_container.visible = true  # Show the board
 	shadow_container.visible = true
 	tile_container.visible = true
+
+func set_gold_display_position():
+	# Set anchors to a percentage of the parent container's size
+	gold_display.anchor_left = 0.2
+	gold_display.anchor_top = 0.0
+	gold_display.anchor_right = 1.0
+	gold_display.anchor_bottom = 0.1
-- 
GitLab