class_name MainLevel
extends Node

func _get_tile_data(position: Vector2) -> Array[TileData]:
	var results: Array[TileData] = []
	for layer in self.get_children():
		if not (layer as TileMapLayer).enabled:
			continue
		var current_tile: Vector2i = layer.local_to_map(layer.to_local(position))
		var tile_data: TileData = layer.get_cell_tile_data(current_tile)
		if tile_data:
			results.push_back(tile_data)
	return results

func is_walkable_tile(position: Vector2) -> bool:
	var results = _get_tile_data(position)
	for tile_data in results:
		if (tile_data as TileData).get_custom_data("walkable"):
			return true
	return false

func is_death_tile(position: Vector2) -> bool:
	var is_death_tile = false
	var results = _get_tile_data(position)
	for tile_data in results:
		if (tile_data as TileData).get_custom_data("death"):
			is_death_tile = true
			break;
	if is_death_tile:
		for tile_data in results:
			if (tile_data as TileData).get_custom_data("walkable"):
				is_death_tile = false
				break;
	return is_death_tile
