Attempt 1
This commit is contained in:
parent
5d410a02fb
commit
2980b3f8ee
10 changed files with 460 additions and 119 deletions
|
|
@ -42,6 +42,11 @@ func add_card_display(card):
|
|||
descLabel.autowrap_mode = TextServer.AUTOWRAP_WORD
|
||||
descLabel.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0)
|
||||
vbox.add_child(descLabel)
|
||||
var unitWhitelistLabel = Label.new()
|
||||
unitWhitelistLabel.text = ", ".join(card.unitWhitelist)
|
||||
unitWhitelistLabel.autowrap_mode = TextServer.AUTOWRAP_WORD
|
||||
unitWhitelistLabel.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0)
|
||||
vbox.add_child(unitWhitelistLabel)
|
||||
|
||||
var idLabel = Label.new()
|
||||
idLabel.text = card.id.substr(card.id.length() - 8, -1)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
|||
|
||||
if tile.get_child_count() > 1: # > 1 because we just added the overlay
|
||||
var piece = tile.get_child(0)
|
||||
if piece.Item_Color != target_piece.Item_Color:
|
||||
if target_piece && piece.Item_Color != target_piece.Item_Color:
|
||||
game_state.updatePoints(piece)
|
||||
piece.queue_free()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
class_name SupernovaCard extends Card
|
||||
|
||||
const CAPTURE_RADIUS = 4
|
||||
var valid = false;
|
||||
|
||||
func _init():
|
||||
super._init()
|
||||
|
|
@ -10,14 +11,17 @@ func _init():
|
|||
duration = 5
|
||||
description = "All enemy units within 4 radius are captured"
|
||||
unitWhitelist = ["King"]
|
||||
remaining_turns = duration
|
||||
|
||||
func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
||||
if !super.apply_effect(target_piece, board_flow, game_state):
|
||||
return false
|
||||
|
||||
attached_piece = target_piece
|
||||
if !target_piece or !board_flow or !game_state:
|
||||
print(cardName, " missing input param ")
|
||||
return false
|
||||
|
||||
setup_persistent_effect(game_state)
|
||||
# dont apply on card attachment
|
||||
if !valid:
|
||||
return true
|
||||
# Get king's position
|
||||
var king_pos = target_piece.get_parent().name.split("-")
|
||||
var king_x = int(king_pos[0])
|
||||
|
|
@ -48,47 +52,67 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
|||
# Add tile to check list
|
||||
tiles_to_check.append(str(target_x) + "-" + str(target_y))
|
||||
|
||||
# Process each tile and capture pieces
|
||||
# Process tiles and add overlay
|
||||
for tile_name in tiles_to_check:
|
||||
var tile = board_flow.get_node("Flow/" + tile_name)
|
||||
if tile.get_child_count() > 0:
|
||||
var piece = tile.get_child(0)
|
||||
if piece.Item_Color != target_piece.Item_Color: # Only capture enemy pieces
|
||||
var tile = board_flow.get_node(tile_name)
|
||||
|
||||
var existing_overlay = tile.get_node_or_null("SupernovaOverlay")
|
||||
if existing_overlay:
|
||||
existing_overlay.queue_free()
|
||||
|
||||
var overlay = ColorRect.new()
|
||||
overlay.name = "SupernovaOverlay"
|
||||
overlay.color = Color(1, 0, 0, 0.3)
|
||||
overlay.size = tile.size
|
||||
overlay.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
tile.add_child(overlay)
|
||||
overlay.show()
|
||||
|
||||
if tile.get_child_count() > 1: # > 1 because we just added the overlay
|
||||
var piece = tile.get_child(0)
|
||||
if piece.Item_Color != target_piece.Item_Color:
|
||||
game_state.updatePoints(piece)
|
||||
piece.queue_free()
|
||||
|
||||
# Visual feedback
|
||||
for tile_name in tiles_to_check:
|
||||
var tile = board_flow.get_node("Flow/" + tile_name)
|
||||
var style = StyleBoxFlat.new()
|
||||
style.bg_color = Color(1, 0, 0, 0.3) # Red tint
|
||||
tile.add_theme_stylebox_override("normal", style)
|
||||
|
||||
# Remove highlight after delay
|
||||
var timer = Timer.new()
|
||||
board_flow.add_child(timer)
|
||||
timer.wait_time = 0.5
|
||||
timer.one_shot = true
|
||||
timer.timeout.connect(func():
|
||||
tile.remove_theme_stylebox_override("normal")
|
||||
timer.queue_free()
|
||||
)
|
||||
timer.start()
|
||||
# Setup timer to remove overlays
|
||||
var timer = Timer.new()
|
||||
board_flow.add_child(timer)
|
||||
timer.wait_time = 0.5
|
||||
timer.one_shot = true
|
||||
timer.timeout.connect(func():
|
||||
for tile_name in tiles_to_check:
|
||||
var tile = board_flow.get_node(tile_name)
|
||||
var overlay = tile.get_node_or_null("SupernovaOverlay")
|
||||
if overlay:
|
||||
overlay.queue_free()
|
||||
timer.queue_free()
|
||||
)
|
||||
timer.start()
|
||||
|
||||
# game_state.stateMachine.transitionToNextState(Constants.POST_MOVE)
|
||||
return true
|
||||
func setup_persistent_effect(king, game_state):
|
||||
|
||||
|
||||
func setup_persistent_effect(game_state):
|
||||
# Connect to the turn change signal if not already connected
|
||||
if !game_state.is_connected("turn_changed", Callable(self, "on_turn_changed")):
|
||||
game_state.connect("turn_changed", Callable(self, "on_turn_changed"))
|
||||
|
||||
func on_turn_changed():
|
||||
if attached_piece and remaining_turns > 0:
|
||||
# Reapply the effect at the start of each turn
|
||||
apply_effect(attached_piece, attached_piece.get_parent().get_parent(), attached_piece.get_parent().get_parent().owner)
|
||||
remaining_turns -= 1
|
||||
if remaining_turns <= 0:
|
||||
remove_effect()
|
||||
|
||||
if attached_piece.get_parent().get_parent().owner.isPlayerTurn() and attached_piece and remaining_turns > 0:
|
||||
# print(attached_piece.get_parent().get_parent(), attached_piece.get_parent().get_parent().owner)
|
||||
var piece = attached_piece
|
||||
var flow = attached_piece.get_parent().get_parent()
|
||||
var state = attached_piece.get_parent().get_parent().owner
|
||||
|
||||
# print("Debug values:")
|
||||
# print("- Piece: ", piece, " is null? ", piece == null)
|
||||
# print("- Board Flow: ", flow, " is null? ", flow == null)
|
||||
# print("- Game State: ", state, " is null? ", state == null)
|
||||
|
||||
# Now try apply_effect with these values
|
||||
valid = true
|
||||
apply_effect(piece, flow, state)
|
||||
|
||||
func remove_effect():
|
||||
if attached_piece:
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ var Turn: int = 0
|
|||
@onready var p1String: RichTextLabel = $Player1Points
|
||||
@onready var p2String: RichTextLabel = $Player2Points
|
||||
@onready var deckManager: DeckManager
|
||||
# @onready var tileManager: TileManager
|
||||
@onready var cardDisplay: CardDisplay
|
||||
@onready var cardPreview: CardPreview
|
||||
|
||||
|
|
@ -44,8 +45,16 @@ var highlightStyle = null
|
|||
func _ready() -> void:
|
||||
initializeGame()
|
||||
stateMachine.transitionToNextState(Constants.WHITE_TURN)
|
||||
# initializeTiles()
|
||||
|
||||
|
||||
# func initializeTiles() -> void:
|
||||
# tileManager = TileManager.new(boardContainer, self)
|
||||
# add_child(tileManager)
|
||||
# tileManager.setup_initial_tiles()
|
||||
|
||||
func get_base_style(is_white: bool) -> StyleBoxFlat:
|
||||
return lightStyle if is_white else darkStyle
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
stateMachine.unhandledInput(event)
|
||||
|
||||
|
|
@ -341,7 +350,9 @@ func executeMove(targetLocation: String) -> void:
|
|||
print("executeMove ", targetLocation)
|
||||
var targetNode = get_node("Flow/" + targetLocation)
|
||||
var piece = get_node("Flow/" + selectedNode).get_child(0)
|
||||
var old_location = selectedNode
|
||||
# print("piece", piece)
|
||||
# tileManager.process_tile_effect(old_location, piece, false) # Exiting old tile
|
||||
|
||||
if targetNode.get_child_count() != 0:
|
||||
var capturedPiece = targetNode.get_child(0)
|
||||
|
|
@ -358,6 +369,7 @@ func executeMove(targetLocation: String) -> void:
|
|||
# print("piece2", piece)
|
||||
hasMoved = true
|
||||
currentlyMovingPiece = piece
|
||||
# tileManager.process_tile_effect(targetLocation, piece, true) # Entering new tile
|
||||
resetHighlights()
|
||||
|
||||
func togglePieceChessEffect() -> void:
|
||||
|
|
|
|||
99
Systems/Tile.gd
Normal file
99
Systems/Tile.gd
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
@tool
|
||||
class_name Tile
|
||||
|
||||
enum TileType {
|
||||
GENERAL, # Effects apply to any piece
|
||||
SPECIFIC, # Effects apply to specific pieces
|
||||
GLOBAL # Effects apply globally while conditions are met
|
||||
}
|
||||
|
||||
enum TileOwner {
|
||||
PLAYER, # White player's tiles
|
||||
ENEMY, # Black player's tiles
|
||||
GAME # Neutral game tiles
|
||||
}
|
||||
|
||||
const TILE_COLORS = {
|
||||
TileOwner.PLAYER: Color(0.2, 0.8, 0.2, 0.5),
|
||||
TileOwner.ENEMY: Color(0.8, 0.2, 0.2, 0.5),
|
||||
TileOwner.GAME: Color(0.2, 0.2, 0.8, 0.5)
|
||||
}
|
||||
|
||||
var type: TileType
|
||||
var tile_owner: TileOwner
|
||||
var duration: int = -1 # -1 for permanent effects
|
||||
var remaining_turns: int
|
||||
var occupied_by: Pawn = null
|
||||
var active: bool = false
|
||||
var tile_name: String
|
||||
var description: String
|
||||
var id: String = Utils.generate_guid()
|
||||
var base_button: Button # Reference to the board square button
|
||||
var base_is_white: bool # Original color of the square
|
||||
|
||||
func _init(button: Button, is_white: bool) -> void:
|
||||
base_button = button
|
||||
base_is_white = is_white
|
||||
|
||||
func initialize(tile_type: TileType, owner_type: TileOwner, turns: int = -1) -> void:
|
||||
print("initi Tile")
|
||||
type = tile_type
|
||||
tile_owner = owner_type
|
||||
duration = turns
|
||||
remaining_turns = duration
|
||||
update_appearance()
|
||||
|
||||
func update_appearance() -> void:
|
||||
if is_effect_active() && base_button:
|
||||
var style = StyleBoxFlat.new()
|
||||
var tile_color = TILE_COLORS[tile_owner]
|
||||
|
||||
# Mix the tile color with the base square color
|
||||
var base_color = Color(0.8, 0.8, 0.8) if base_is_white else Color(0.2, 0.2, 0.2)
|
||||
var mixed_color = Color(
|
||||
(base_color.r + tile_color.r) / 2,
|
||||
(base_color.g + tile_color.g) / 2,
|
||||
(base_color.b + tile_color.b) / 2
|
||||
)
|
||||
|
||||
style.bg_color = mixed_color
|
||||
style.border_width_left = 2
|
||||
style.border_width_right = 2
|
||||
style.border_width_top = 2
|
||||
style.border_width_bottom = 2
|
||||
style.border_color = tile_color
|
||||
|
||||
base_button.add_theme_stylebox_override("normal", style)
|
||||
|
||||
# Add hover style
|
||||
var hover_style = style.duplicate()
|
||||
hover_style.bg_color = tile_color.lightened(0.2)
|
||||
base_button.add_theme_stylebox_override("hover", hover_style)
|
||||
else:
|
||||
restore_base_appearance()
|
||||
|
||||
func restore_base_appearance() -> void:
|
||||
if base_button:
|
||||
var board = base_button.get_parent()
|
||||
if board && board.has_method("get_base_style"):
|
||||
var base_style = board.get_base_style(base_is_white)
|
||||
base_button.add_theme_stylebox_override("normal", base_style)
|
||||
base_button.add_theme_stylebox_override("hover", base_style)
|
||||
|
||||
func is_effect_active() -> bool:
|
||||
return active && (duration == -1 || remaining_turns > 0)
|
||||
|
||||
func update_duration() -> bool:
|
||||
if duration > 0:
|
||||
remaining_turns -= 1
|
||||
if remaining_turns <= 0:
|
||||
restore_base_appearance()
|
||||
return true # Tile should be removed
|
||||
return false
|
||||
|
||||
# Virtual methods to be overridden by specific tile effects
|
||||
func apply_effect(piece: Pawn, board_flow = null, game_state = null) -> void:
|
||||
pass
|
||||
|
||||
func remove_effect(piece: Pawn, board_flow = null, game_state = null) -> void:
|
||||
pass
|
||||
93
Systems/TileManager.gd
Normal file
93
Systems/TileManager.gd
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
extends Node
|
||||
class_name TileManager
|
||||
const INITIAL_GAME_TILES = 3 # Number of neutral tiles to place at game start
|
||||
|
||||
var active_tiles: Dictionary = {} # location -> Tile
|
||||
var game_board: Node # Reference to the game board
|
||||
var game_state: Node # Reference to the game state
|
||||
|
||||
const DoubleMovementTile = preload("res://Systems/Tiles/DoubleMovement.gd")
|
||||
const FireWallTile = preload("res://Systems/Tiles/FireWall.gd")
|
||||
const PawnBoostTile = preload("res://Systems/Tiles/PawnBoost.gd")
|
||||
|
||||
# Available tile classes
|
||||
const TILE_TYPES = {
|
||||
"double_movement": DoubleMovementTile,
|
||||
"fire_wall": FireWallTile,
|
||||
"pawn_boost": PawnBoostTile
|
||||
}
|
||||
|
||||
func _init(board: Node, state: Node = null) -> void:
|
||||
game_board = board
|
||||
game_state = state
|
||||
|
||||
func setup_initial_tiles() -> void:
|
||||
var available_positions = ["4-4", "4-6", "2-4"]
|
||||
# get_available_positions()
|
||||
available_positions.shuffle()
|
||||
|
||||
for i in range(min(INITIAL_GAME_TILES, available_positions.size())):
|
||||
var pos = available_positions[i]
|
||||
var tile_type = TILE_TYPES.keys()[randi() % TILE_TYPES.size()]
|
||||
create_tile(pos, tile_type, Tile.TileOwner.GAME)
|
||||
|
||||
func create_tile(location: String, tile_type: String, tile_owner: int, duration: int = -1) -> Tile:
|
||||
print("CREATING TILES", location)
|
||||
if location in active_tiles:
|
||||
print("In Active tiles ", location)
|
||||
var old_tile = active_tiles[location]
|
||||
old_tile.restore_base_appearance()
|
||||
active_tiles.erase(location)
|
||||
|
||||
if !TILE_TYPES.has(tile_type):
|
||||
push_error("Invalid tile type: " + tile_type)
|
||||
return null
|
||||
|
||||
var board_button = game_board.get_node(location)
|
||||
if !board_button:
|
||||
print("no Board Btn present ", location)
|
||||
return null
|
||||
|
||||
# Determine if it's a white square based on coordinates
|
||||
var coords = location.split("-")
|
||||
var is_white_square = (int(coords[0]) + int(coords[1])) % 2 == 0
|
||||
|
||||
var tile = TILE_TYPES[tile_type].new(board_button, is_white_square)
|
||||
print("Tile: ", tile)
|
||||
tile.initialize(tile.type, tile_owner, duration)
|
||||
|
||||
active_tiles[location] = tile
|
||||
return tile
|
||||
|
||||
func create_fire_wall(start_pos: String, affected_positions: Array) -> void:
|
||||
for pos in affected_positions:
|
||||
create_tile(pos, "fire_wall", Tile.TileOwner.PLAYER, 3)
|
||||
|
||||
func get_available_positions() -> Array:
|
||||
var positions = []
|
||||
# Skip edge tiles and starting rows
|
||||
for x in range(1, 7):
|
||||
for y in range(2, 6):
|
||||
var pos = str(x) + "-" + str(y)
|
||||
if !active_tiles.has(pos):
|
||||
positions.append(pos)
|
||||
return positions
|
||||
|
||||
func update_tiles() -> void:
|
||||
var expired_tiles = []
|
||||
for location in active_tiles:
|
||||
var tile = active_tiles[location]
|
||||
if tile.update_duration():
|
||||
expired_tiles.append(location)
|
||||
|
||||
for location in expired_tiles:
|
||||
active_tiles.erase(location)
|
||||
|
||||
func get_tile_at(location: String) -> Tile:
|
||||
return active_tiles.get(location)
|
||||
|
||||
func clear_tiles() -> void:
|
||||
for location in active_tiles:
|
||||
var tile = active_tiles[location]
|
||||
tile.restore_base_appearance()
|
||||
active_tiles.clear()
|
||||
39
Systems/Tiles/DoubleMovement.gd
Normal file
39
Systems/Tiles/DoubleMovement.gd
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
class_name DoubleMovementTile
|
||||
extends Tile
|
||||
|
||||
func _init(button: Button, is_white: bool) -> void:
|
||||
super._init(button, is_white)
|
||||
tile_name = "Double Movement"
|
||||
description = "Double movement for 3 turns"
|
||||
type = TileType.GENERAL
|
||||
|
||||
func update_appearance() -> void:
|
||||
print("TILE UPDATE APPR");
|
||||
if true && base_button:
|
||||
var style = StyleBoxFlat.new()
|
||||
var tile_color = TILE_COLORS[tile_owner]
|
||||
var base_color = Color(0.8, 0.8, 0.8) if base_is_white else Color(0.2, 0.2, 0.2)
|
||||
|
||||
# Brighten the color slightly for double movement
|
||||
tile_color = tile_color.lightened(0.2)
|
||||
|
||||
style.bg_color = Color(
|
||||
(base_color.r + tile_color.r) / 2,
|
||||
(base_color.g + tile_color.g) / 2,
|
||||
(base_color.b + tile_color.b) / 2
|
||||
)
|
||||
|
||||
# Add distinctive border pattern
|
||||
style.border_width_left = 4
|
||||
style.border_width_right = 4
|
||||
style.border_width_top = 4
|
||||
style.border_width_bottom = 4
|
||||
style.border_color = tile_color
|
||||
|
||||
base_button.add_theme_stylebox_override("normal", style)
|
||||
|
||||
var hover_style = style.duplicate()
|
||||
hover_style.bg_color = tile_color.lightened(0.2)
|
||||
base_button.add_theme_stylebox_override("hover", hover_style)
|
||||
else:
|
||||
restore_base_appearance()
|
||||
34
Systems/Tiles/FireWall.gd
Normal file
34
Systems/Tiles/FireWall.gd
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
class_name FireWallTile
|
||||
extends Tile
|
||||
func _init(button: Button, is_white: bool) -> void:
|
||||
super._init(button, is_white)
|
||||
tile_name = "Fire Wall"
|
||||
description = "Captures any piece that moves through"
|
||||
type = TileType.GENERAL
|
||||
|
||||
func update_appearance() -> void:
|
||||
if is_effect_active() && base_button:
|
||||
var style = StyleBoxFlat.new()
|
||||
var tile_color = Color(1, 0.4, 0) # Orange for fire
|
||||
var base_color = Color(0.8, 0.8, 0.8) if base_is_white else Color(0.2, 0.2, 0.2)
|
||||
|
||||
style.bg_color = Color(
|
||||
(base_color.r + tile_color.r) / 2,
|
||||
(base_color.g + tile_color.g) / 2,
|
||||
(base_color.b + tile_color.b) / 2
|
||||
)
|
||||
|
||||
# Thick border for danger
|
||||
style.border_width_left = 5
|
||||
style.border_width_right = 5
|
||||
style.border_width_top = 5
|
||||
style.border_width_bottom = 5
|
||||
style.border_color = tile_color
|
||||
|
||||
base_button.add_theme_stylebox_override("normal", style)
|
||||
|
||||
var hover_style = style.duplicate()
|
||||
hover_style.bg_color = tile_color.lightened(0.2)
|
||||
base_button.add_theme_stylebox_override("hover", hover_style)
|
||||
else:
|
||||
restore_base_appearance()
|
||||
35
Systems/Tiles/PawnBoost.gd
Normal file
35
Systems/Tiles/PawnBoost.gd
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
class_name PawnBoostTile
|
||||
extends Tile
|
||||
|
||||
func _init(button: Button, is_white: bool) -> void:
|
||||
super._init(button, is_white)
|
||||
tile_name = "Fire Wall"
|
||||
description = "Captures any piece that moves through"
|
||||
type = TileType.GENERAL
|
||||
|
||||
func update_appearance() -> void:
|
||||
if is_effect_active() && base_button:
|
||||
var style = StyleBoxFlat.new()
|
||||
var tile_color = Color(1, 0.4, 0) # Orange for fire
|
||||
var base_color = Color(0.8, 0.8, 0.8) if base_is_white else Color(0.2, 0.2, 0.2)
|
||||
|
||||
style.bg_color = Color(
|
||||
(base_color.r + tile_color.r) / 2,
|
||||
(base_color.g + tile_color.g) / 2,
|
||||
(base_color.b + tile_color.b) / 2
|
||||
)
|
||||
|
||||
# Thick border for danger
|
||||
style.border_width_left = 5
|
||||
style.border_width_right = 5
|
||||
style.border_width_top = 5
|
||||
style.border_width_bottom = 5
|
||||
style.border_color = tile_color
|
||||
|
||||
base_button.add_theme_stylebox_override("normal", style)
|
||||
|
||||
var hover_style = style.duplicate()
|
||||
hover_style.bg_color = tile_color.lightened(0.2)
|
||||
base_button.add_theme_stylebox_override("hover", hover_style)
|
||||
else:
|
||||
restore_base_appearance()
|
||||
|
|
@ -21,110 +21,110 @@ const EFFECT_TINT_COLOR = Color(0.3, 0.8, 0.3, 0.5) # Green tint for card effec
|
|||
var id: String = Utils.generate_guid()
|
||||
|
||||
func _ready():
|
||||
modulate = Color.WHITE if Item_Color == 0 else Color.BLACK
|
||||
modulate = Color.WHITE if Item_Color == 0 else Color.BLACK
|
||||
|
||||
func _init() -> void:
|
||||
self.texture = load("res://addons/Chess/Textures/WPawn.svg")
|
||||
var background_style = StyleBoxFlat.new()
|
||||
background_style.bg_color = Color.WHITE
|
||||
background_style.corner_radius_top_left = 2
|
||||
background_style.corner_radius_top_right = 2
|
||||
background_style.corner_radius_bottom_left = 2
|
||||
background_style.corner_radius_bottom_right = 2
|
||||
background_style.content_margin_left = 2
|
||||
background_style.content_margin_right = 2
|
||||
background_style.content_margin_top = 1
|
||||
background_style.content_margin_bottom = 1
|
||||
duration_label = Label.new()
|
||||
duration_label.add_theme_stylebox_override("normal", background_style)
|
||||
duration_label.add_theme_color_override("font_color", Color.BLACK)
|
||||
duration_label.position = Vector2(-20, -20) # Position above the piece
|
||||
add_child(duration_label)
|
||||
duration_label.hide()
|
||||
self.texture = load("res://addons/Chess/Textures/WPawn.svg")
|
||||
var background_style = StyleBoxFlat.new()
|
||||
background_style.bg_color = Color.WHITE
|
||||
background_style.corner_radius_top_left = 2
|
||||
background_style.corner_radius_top_right = 2
|
||||
background_style.corner_radius_bottom_left = 2
|
||||
background_style.corner_radius_bottom_right = 2
|
||||
background_style.content_margin_left = 2
|
||||
background_style.content_margin_right = 2
|
||||
background_style.content_margin_top = 1
|
||||
background_style.content_margin_bottom = 1
|
||||
duration_label = Label.new()
|
||||
duration_label.add_theme_stylebox_override("normal", background_style)
|
||||
duration_label.add_theme_color_override("font_color", Color.BLACK)
|
||||
duration_label.position = Vector2(-20, -20) # Position above the piece
|
||||
add_child(duration_label)
|
||||
duration_label.hide()
|
||||
|
||||
func update_appearance() -> void:
|
||||
# print("update_appearance")
|
||||
if !is_instance_valid(get_tree()) || !get_tree().get_root().has_node("Board"):
|
||||
return
|
||||
|
||||
var chess_game = get_tree().get_root().get_node("Board")
|
||||
if !chess_game.deckManager:
|
||||
return
|
||||
|
||||
var deck_manager = chess_game.deckManager
|
||||
var has_card = deck_manager.attached_cards.has(get_instance_id())
|
||||
# print("update_appearance")
|
||||
if !is_instance_valid(get_tree()) || !get_tree().get_root().has_node("Board"):
|
||||
return
|
||||
|
||||
var chess_game = get_tree().get_root().get_node("Board")
|
||||
if !chess_game.deckManager:
|
||||
return
|
||||
|
||||
var deck_manager = chess_game.deckManager
|
||||
var has_card = deck_manager.attached_cards.has(get_instance_id())
|
||||
|
||||
if has_card:
|
||||
# Apply tint while keeping the piece color
|
||||
var base_color = Color.WHITE if Item_Color == 0 else Color.BLACK
|
||||
modulate = base_color * EFFECT_TINT_COLOR
|
||||
|
||||
# Update duration display
|
||||
var card = deck_manager.attached_cards[get_instance_id()]
|
||||
if is_instance_valid(duration_label):
|
||||
duration_label.text = str(card.remaining_turns)
|
||||
duration_label.show()
|
||||
else:
|
||||
# Reset to normal color
|
||||
modulate = Color.WHITE if Item_Color == 0 else Color.BLACK
|
||||
if is_instance_valid(duration_label):
|
||||
duration_label.hide()
|
||||
|
||||
if has_card:
|
||||
# Apply tint while keeping the piece color
|
||||
var base_color = Color.WHITE if Item_Color == 0 else Color.BLACK
|
||||
modulate = base_color * EFFECT_TINT_COLOR
|
||||
|
||||
# Update duration display
|
||||
var card = deck_manager.attached_cards[get_instance_id()]
|
||||
if is_instance_valid(duration_label):
|
||||
duration_label.text = str(card.remaining_turns)
|
||||
duration_label.show()
|
||||
else:
|
||||
# Reset to normal color
|
||||
modulate = Color.WHITE if Item_Color == 0 else Color.BLACK
|
||||
if is_instance_valid(duration_label):
|
||||
duration_label.hide()
|
||||
|
||||
|
||||
|
||||
|
||||
func on_card_effect_changed() -> void:
|
||||
update_appearance()
|
||||
update_appearance()
|
||||
# Movement interface method that all pieces will implement
|
||||
# In Pawn.gd
|
||||
func getValidMoves(board_flow, current_location: String) -> Dictionary:
|
||||
var moves = {
|
||||
"regular_moves": [],
|
||||
"special_moves": []
|
||||
}
|
||||
var moves = {
|
||||
"regular_moves": [],
|
||||
"special_moves": []
|
||||
}
|
||||
|
||||
var loc = current_location.split("-")
|
||||
var x = int(loc[0])
|
||||
var y = int(loc[1])
|
||||
var loc = current_location.split("-")
|
||||
var x = int(loc[0])
|
||||
var y = int(loc[1])
|
||||
|
||||
# Movement direction based on color
|
||||
var direction = -1 if Item_Color == 0 else 1
|
||||
# Movement direction based on color
|
||||
var direction = -1 if Item_Color == 0 else 1
|
||||
|
||||
# Forward movement
|
||||
var forward = str(x) + "-" + str(y + direction)
|
||||
if is_valid_cell(board_flow, forward) && can_move_to_cell(board_flow, forward):
|
||||
moves.regular_moves.append(forward)
|
||||
|
||||
# Double move on first turn
|
||||
var double_forward = str(x) + "-" + str(y + (direction * 2))
|
||||
if Double_Start && is_valid_cell(board_flow, double_forward) && can_move_to_cell(board_flow, double_forward):
|
||||
moves.regular_moves.append(double_forward)
|
||||
# Forward movement
|
||||
var forward = str(x) + "-" + str(y + direction)
|
||||
if is_valid_cell(board_flow, forward) && can_move_to_cell(board_flow, forward):
|
||||
moves.regular_moves.append(forward)
|
||||
|
||||
# Double move on first turn
|
||||
var double_forward = str(x) + "-" + str(y + (direction * 2))
|
||||
if Double_Start && is_valid_cell(board_flow, double_forward) && can_move_to_cell(board_flow, double_forward):
|
||||
moves.regular_moves.append(double_forward)
|
||||
|
||||
# Diagonal captures
|
||||
for dx in [-1, 1]:
|
||||
var capture = str(x + dx) + "-" + str(y + direction)
|
||||
if is_valid_cell(board_flow, capture) && can_move_to_cell(board_flow, capture, true):
|
||||
moves.regular_moves.append(capture)
|
||||
|
||||
# En Passant
|
||||
var adjacent = str(x + dx) + "-" + str(y)
|
||||
if is_valid_cell(board_flow, adjacent) && is_valid_cell(board_flow, capture):
|
||||
var adjacent_cell = board_flow.get_node(adjacent)
|
||||
if adjacent_cell.get_child_count() == 1:
|
||||
var adjacent_piece = adjacent_cell.get_child(0)
|
||||
if adjacent_piece.name == "Pawn" && adjacent_piece.En_Passant && adjacent_piece.Item_Color != self.Item_Color:
|
||||
moves.special_moves.append([adjacent, capture])
|
||||
# Diagonal captures
|
||||
for dx in [-1, 1]:
|
||||
var capture = str(x + dx) + "-" + str(y + direction)
|
||||
if is_valid_cell(board_flow, capture) && can_move_to_cell(board_flow, capture, true):
|
||||
moves.regular_moves.append(capture)
|
||||
|
||||
# En Passant
|
||||
var adjacent = str(x + dx) + "-" + str(y)
|
||||
if is_valid_cell(board_flow, adjacent) && is_valid_cell(board_flow, capture):
|
||||
var adjacent_cell = board_flow.get_node(adjacent)
|
||||
if adjacent_cell.get_child_count() == 1:
|
||||
var adjacent_piece = adjacent_cell.get_child(0)
|
||||
if adjacent_piece.name == "Pawn" && adjacent_piece.En_Passant && adjacent_piece.Item_Color != self.Item_Color:
|
||||
moves.special_moves.append([adjacent, capture])
|
||||
|
||||
return moves
|
||||
return moves
|
||||
|
||||
# Helper method for all pieces
|
||||
func is_valid_cell(board_flow, location: String) -> bool:
|
||||
var node = board_flow.get_node_or_null(location)
|
||||
return node != null
|
||||
var node = board_flow.get_node_or_null(location)
|
||||
return node != null
|
||||
|
||||
# Helper for checking if cell is empty or contains enemy
|
||||
func can_move_to_cell(board_flow, location: String, is_capture: bool = false) -> bool:
|
||||
var node = board_flow.get_node(location)
|
||||
if is_capture:
|
||||
return node.get_child_count() == 1 && node.get_child(0).Item_Color != self.Item_Color
|
||||
return node.get_child_count() == 0
|
||||
var node = board_flow.get_node(location)
|
||||
if is_capture:
|
||||
return node.get_child_count() == 1 && node.get_child(0).Item_Color != self.Item_Color
|
||||
return node.get_child_count() == 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue