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()