73 lines
No EOL
2.1 KiB
GDScript
73 lines
No EOL
2.1 KiB
GDScript
class_name Tile
|
|
extends Resource
|
|
|
|
enum TileType {
|
|
GENERAL, # Affects any unit
|
|
SPECIFIC, # Affects specific unit type
|
|
GLOBAL # Affects all units of a color while active
|
|
}
|
|
|
|
enum TileOwner {
|
|
PLAYER, # White player
|
|
ENEMY, # Black player
|
|
GAME # Neutral/game-owned
|
|
}
|
|
var game: ChessGame
|
|
var tile_name: String = ""
|
|
var description: String = ""
|
|
var duration: int = -1 # -1 for permanent tiles
|
|
var remaining_turns: int = 0
|
|
var tile_owner: TileOwner = TileOwner.GAME
|
|
var type: TileType = TileType.GENERAL
|
|
var target_piece_type: String = "" # For SPECIFIC type tiles
|
|
var base_button: Button # Reference to the tile button
|
|
var base_is_white: bool # Original tile color
|
|
var passable: bool = true
|
|
var jumpable: bool = true
|
|
signal effect_expired
|
|
|
|
func _init(button: Button, is_white: bool, d: int) -> void:
|
|
base_button = button
|
|
base_is_white = is_white
|
|
remaining_turns = d
|
|
|
|
func is_effect_active() -> bool:
|
|
return duration == -1 || remaining_turns > 0
|
|
|
|
func update_duration() -> void:
|
|
if duration != -1:
|
|
remaining_turns -= 1
|
|
if remaining_turns <= 0:
|
|
effect_expired.emit()
|
|
|
|
func can_affect_piece(piece: Pawn) -> bool:
|
|
match type:
|
|
TileType.SPECIFIC:
|
|
return piece.name == target_piece_type
|
|
TileType.GLOBAL, TileType.GENERAL:
|
|
# Check owner alignment
|
|
match tile_owner:
|
|
TileOwner.PLAYER:
|
|
return piece.Item_Color == 1 # White
|
|
TileOwner.ENEMY:
|
|
return piece.Item_Color == 0 # Black
|
|
TileOwner.GAME:
|
|
return true
|
|
return false
|
|
|
|
func apply_effect(piece: Pawn = null) -> void:
|
|
# Override in child classes
|
|
pass
|
|
|
|
func remove_effect(piece: Pawn = null) -> void:
|
|
# Override in child classes
|
|
pass
|
|
|
|
func update_appearance() -> void:
|
|
restore_base_appearance()
|
|
|
|
func restore_base_appearance() -> void:
|
|
if base_button:
|
|
var style = StyleBoxFlat.new()
|
|
style.bg_color = Utils.LIGHT_CELL if base_is_white else Utils.DARK_CELL
|
|
base_button.add_theme_stylebox_override("normal", style) |