ChessBuilder/Systems/Tile.gd
2025-02-01 23:07:39 -06:00

99 lines
No EOL
3.1 KiB
GDScript

@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