integrated map with board, deck manager and shop

This commit is contained in:
2ManyProjects 2025-03-06 13:00:36 -06:00
parent dfcd0dcc63
commit be9a84d8bd
9 changed files with 168 additions and 31 deletions

View file

@ -112,6 +112,12 @@ func playEffect(card: Card, target_piece: Pawn, board_flow = null, game_state =
# print("Failed Play Card 2")
return false
func cleanup():
if hand.size() > 0:
for card in hand:
deck.push_back(card)
hand.clear()
func updateEffectDurations():
var expired_entries = [] # Store [piece_id, card_id] pairs to remove

View file

@ -9,6 +9,7 @@ const StockfishController = preload("res://Systems/FairyStockfish/StockfishClien
# Signals
signal tile_pressed(location: String)
signal send_location(location: String)
signal map_open_requested(options)
signal turn_changed
signal game_initialized
@ -55,6 +56,7 @@ var is_initialized: bool = false
@onready var boardContainer: FlowContainer = $Flow
@onready var stateMachine: StateMachine = $StateMachine
@onready var menuContainer = get_node_or_null("/root/Board/MenuContainer")
@onready var mapContainer = get_node_or_null("/root/Board/MapScreen")
# Export parameters
@ -99,8 +101,18 @@ func _ready() -> void:
func _on_new_game_requested(options = {}):
print("ChessGame received new_game_requested signal ", is_initialized)
turnIndicator.visible = true
if options and "fen" in options:
currentFen = options.fen
if cameraController:
cameraController.reset_view()
if is_initialized:
resetBoard()
initializeDeckSystem()
if cardDisplay:
cardDisplay.visible = true
if stateMachine:
stateMachine.start()
stateMachine.transitionToNextState(Constants.WHITE_TURN)
else:
initialize_game_system()
@ -156,13 +168,13 @@ func initializeTiles() -> void:
func initializeBoard() -> void:
# Parse FEN to get board dimensions
var fen_parts = FEN.split(" ")
# Parse FEN
var fen_parts = currentFen.split(" ")
var rows = fen_parts[0].split("/")
boardYSize = rows.size()
boardXSize = 0
# Calculate width from first row by counting both pieces and numbers
# Calculate width from first row by counting both pieces numbers and tiles
for c in rows[0]:
if c.is_valid_int():
boardXSize += int(c) # Add the number of empty squares
@ -211,7 +223,6 @@ func initializeDeckSystem() -> void:
deckManager.connect("hand_updated", func(hand): cardDisplay.update_hand(hand))
func setupCameraController() -> void:
# Set up the camera controller for board navigation
cameraController = CameraController.new(boardContainer)
cameraController.name = "CameraController"
add_child(cameraController)
@ -287,9 +298,10 @@ func createBoard() -> void:
print("CREATING BOARD X " + str(boardXSize) + " Y " + str(boardYSize))
while numberY != boardYSize:
boardContainer.size.y += tileYSize + 5
boardContainer.size.x += tileXSize + 5
while numberX != boardXSize:
if numberY == 0:
boardContainer.size.x += tileXSize + 5
createTile(numberX, numberY, isWhite)
isWhite = !isWhite
numberX += 1
@ -302,8 +314,13 @@ func createTile(x: int, y: int, isWhite: bool) -> void:
# Create a single tile for the chess board
var tile = PieceContainer.new(str(x) + "-" + str(y))
tile.set_custom_minimum_size(Vector2(tileXSize, tileYSize))
# if x == 0:
# var style = StyleBoxFlat.new()
# style.bg_color = Utils.GREEN_CELL
# tile.add_theme_stylebox_override("normal", style )
# else:
tile.add_theme_stylebox_override("normal", lightStyle if isWhite else darkStyle)
print(" Create Tile " + str(x) + "-" + str(y) )
# print(" Create Tile " + str(x) + "-" + str(y) )
tile.set_name(str(x) + "-" + str(y))
# tile.pressed.connect(func(): handleTileSelection(tile.name))
tile.pressed.connect(func():
@ -315,7 +332,7 @@ func createTile(x: int, y: int, isWhite: bool) -> void:
func setupPiecesFromFEN() -> void:
# Set up chess pieces from the FEN string
var fen_parts = FEN.split(" ")
var fen_parts = currentFen.split(" ")
var rows = fen_parts[0].split("/")
# Iterate through rows in reverse to place black pieces at top
@ -335,7 +352,7 @@ func setupPiecesFromFEN() -> void:
func setupTilesFromFEN() -> void:
# Set up special tiles from the FEN string
var fen_parts = FEN.split(" ")
var fen_parts = currentFen.split(" ")
var rows = fen_parts[0].split("/")
var matchedPortals = {}
var portalCnt = 0;
@ -369,7 +386,7 @@ func setupTilesFromFEN() -> void:
x += 1
func placePiece(position: String, pieceName: String, color: int) -> void:
print("Placing Piece")
# print("Placing Piece ", position)
var piece = summonPiece(pieceName, color)
var container = boardContainer.get_node(position) as PieceContainer
await container.set_piece(piece, false)
@ -491,6 +508,13 @@ func evaluatePosition() -> Dictionary:
func isCheckmate() -> bool:
return gamecheckMate
func endRound() -> void:
print("****************ENDROUND*************")
deckManager.cleanup()
cardDisplay.visible = false
mapContainer.visible = true
resetBoard()
func isDraw() -> bool:
return gamedraw
@ -516,13 +540,7 @@ func executeMove(targetLocation: String) -> void:
# Handle capture if there's a piece in target location
if targetContainer.has_piece():
var capturedPiece = targetContainer.get_piece()
if Turn == 0:
p1Points += capturedPiece.Points
p1String.text = str(p1Points)
else:
p2Points += capturedPiece.Points
p2String.text = str(p2Points)
targetContainer.remove_piece() # This handles freeing the captured piece
updatePointsAndCapture(capturedPiece, true)
# Move piece to new location
sourceContainer.remove_piece(true)
@ -661,6 +679,8 @@ func isNull(location: String) -> bool:
func updatePointsAndCapture(capturedPiece: Pawn, animate: bool = true) -> void:
# Update points and handle piece capture
if Turn == 0:
gold += capturedPiece.Points;
p1Points += capturedPiece.Points
p1String.text = str(p1Points)
else:

View file

@ -42,6 +42,8 @@ func _ready():
if backButton:
backButton.connect("pressed", Callable(self, "_on_back_button_pressed"))
connect("map_open_requested", Callable(self, "_on_map_button_pressed"))
func setup(menu_container):
main_menu_container = menu_container

View file

@ -246,13 +246,13 @@ func generate_node_data(node):
Utils.RoomType.NORMAL:
data.metadata = generate_chess_data(data)
Utils.RoomType.BOSS:
data.metadata = {}
data.metadata = generate_chess_data(data)
Utils.RoomType.FINAL:
data.metadata = { "is_escape": true}
Utils.RoomType.SHOP:
data.metadata = generate_shop_data(data)
Utils.RoomType.EVENT:
data.metadata = {}
data.metadata = generate_event_data(data)
_:
data.metadata = {}
return data
@ -297,10 +297,20 @@ func generate_starting_data(node):
"elo": node.elo,
}
func generate_event_data(node):
return {
"is_escape": node.metadata.is_escape if node.metadata.has("is_escape") else false,
"fen": "8/4p3/8/8/8/8 w KQkq - 0 1",
"game_type": "maze",
"win_condition": Utils.WinCondition.Tile,
"elo": node.elo,
}
# "rnbqkbnr1/pppppppp1/9/9/9/9/9/PPPPPPPP1/RNBQKBNR1 w KQkq - 0 1"
func generate_chess_data(node):
return {
"is_escape": node.metadata.is_escape if node.metadata.has("is_escape") else false,
"fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"game_type": "chess",
"win_condition": Utils.WinCondition.King,
"elo": node.elo,
}

View file

@ -2,8 +2,9 @@ extends Control
class_name MapScreen
signal back_pressed
signal deckmanager_open_requested(options)
signal node_selected(node_data)
signal map_visibility_changed(is_visible)
const MapGenerator = preload("res://Systems/Game/Map/MapGenerator.gd")
# Room type constants
@ -54,13 +55,17 @@ var selected_node_panel: NodePopup = null
@onready var map_container = $MapScrollContainer/MapContainer
@onready var back_button = $BackButton
@onready var deck_manager_button = $DeckManagerButton
@onready var title_label = $TitleLabel
@onready var legend_container = $LegendContainer
@onready var gold_label = $GoldLabel
func _ready():
# Connect back button
if back_button:
back_button.connect("pressed", Callable(self, "_on_back_button_pressed"))
if deck_manager_button:
deck_manager_button.connect("pressed", Callable(self, "_on_deck_button_pressed"))
# Create legend
create_legend()
@ -388,6 +393,10 @@ func _on_back_button_pressed():
visible = false
func _on_deck_button_pressed():
emit_signal("deckmanager_open_requested", {})
visible = false
func draw_curved_connection(from_node, to_node):
var line = Line2D.new()
line.width = LINE_WIDTH
@ -509,3 +518,32 @@ func get_node_description(node_data):
desc += "\n\nWarning: This is an escape node"
return desc
func update_gold_display():
var game = get_node_or_null("/root/Board") as ChessGame
if gold_label:
gold_label.text = str(game.gold) + " GOLD"
# Notification
func _notification(what):
if what == NOTIFICATION_VISIBILITY_CHANGED:
_on_visibility_changed(visible)
func _on_visibility_changed(is_visible):
print("MapScreen visibility changed to: ", is_visible)
if is_visible:
update_gold_display()
else:
print("MapScreen is now invisible")
emit_signal("map_visibility_changed", is_visible)

View file

@ -37,6 +37,8 @@ func _ready():
gameMenuScreen.connect("map_open_requested", Callable(self, "_on_map_open_requested"))
gameMenuScreen.connect("new_game_requested", Callable(self, "_on_start_game_pressed"))
gameMenuScreen.visible = false
else:
connect("map_open_requested", Callable(self, "_on_map_open_requested"))
if deckManagerScreen:
deckManagerScreen.connect("back_pressed", Callable(self, "_on_deck_manager_back_pressed"))
@ -44,6 +46,7 @@ func _ready():
if mapScreen:
mapScreen.connect("back_pressed", Callable(self, "_on_map_back_pressed"))
mapScreen.connect("deckmanager_open_requested", Callable(self, "_on_deckmanager_open_requested_from_map"))
mapScreen.connect("node_selected", Callable(self, "_on_map_node_selected"))
mapScreen.visible = false
@ -168,6 +171,23 @@ func _on_shop_card_purchased(card, price):
deck_manager.bank.append(card)
print("Added purchased card to bank:", card.cardName)
func _on_deckmanager_open_requested_from_map(options):
print("Deck Manager requested with options:", options)
# Hide game menu
gameMenuScreen.visible = false
# Show and initialize deck manager
if deckManagerScreen:
deckManagerScreen.visible = true
deckManagerScreen.initialize(options)
back_to_map = true
# Also emit signal for other systems that might need to know
emit_signal("deckmanager_open_requested", options)
func _on_deckmanager_open_requested(options):
print("Deck Manager requested with options:", options)
@ -213,7 +233,15 @@ func _on_map_node_selected(node_data):
if node_data.type == Utils.RoomType.SHOP:
back_to_map = true
_on_shop_open_requested(node_data.metadata)
elif node_data.type == Utils.RoomType.NORMAL:
if gameMenuScreen:
gameMenuScreen.visible = false
if deckManagerScreen:
deckManagerScreen.visible = false
if mapScreen:
mapScreen.visible = false
back_to_map = true
_on_start_game_pressed(node_data.metadata)
# Implement logic for map node selection
# For example, start a battle based on the node type

View file

@ -3,21 +3,21 @@ extends "res://Systems/StateMachine/ChessGameState.gd"
func enter(_previous: String, data := {}) -> void:
print("ENTERING STATE ", Constants.ROUND_END)
if "endCondition" in data:
match data["endCondition"]:
"checkmate":
handleCheckmate()
"draw":
handleDraw()
match data["endCondition"]:
"checkmate":
handleCheckmate()
"draw":
handleDraw()
game.resetBoard()
finished.emit(Constants.WHITE_TURN)
game.endRound()
# finished.emit(Constants.WHITE_TURN)
func handleCheckmate() -> void:
var winner = "White" if game.turn == 1 else "Black"
print("Checkmate! " + winner + " wins!")
var winner = "White" if game.turn == 1 else "Black"
print("Checkmate! " + winner + " wins!")
func handleDraw() -> void:
print("Game ended in draw")
print("Game ended in draw")

View file

@ -66,3 +66,10 @@ enum RoomType {
SHOP,
EVENT
}
enum WinCondition{
King,
Clear,
Tile,
}

View file

@ -41,6 +41,15 @@ theme_override_font_sizes/font_size = 36
text = "MAP"
horizontal_alignment = 1
[node name="GoldLabel" type="Label" parent="."]
layout_mode = 2
offset_left = 950.0
offset_top = 20.0
offset_right = 1064.0
offset_bottom = 54.0
theme_override_font_sizes/font_size = 24
text = "100 GOLD"
[node name="MapScrollContainer" type="ScrollContainer" parent="."]
layout_mode = 1
anchors_preset = -1
@ -113,3 +122,20 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("3_wcttb")
[node name="DeckManagerButton" type="RichTextLabel" parent="."]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -162.0
offset_top = -48.0
offset_right = -23.0
offset_bottom = -18.0
grow_horizontal = 0
grow_vertical = 0
text = "DECK MANAGER"
horizontal_alignment = 2
script = ExtResource("bfjmon81nckns")