/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   game_manager_utils.c                               :+:    :+:            */
/*                                                     +:+                    */
/*   By: qmennen <qmennen@student.codam.nl>           +#+                     */
/*                                                   +#+                      */
/*   Created: 2025/05/27 15:22:15 by qmennen       #+#    #+#                 */
/*   Updated: 2025/06/04 17:51:00 by whaffman      ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include "game_manager.h"

void	game_manager_select(t_game_manager *manager)
{
	int	selected_option;

	selected_option = (*manager->active_menu)->selected_option;
	(*manager->active_menu)->items[selected_option]->act(
		(*manager->active_menu)->items[selected_option], manager);
}

void	game_manager_handle_input(t_game_manager *manager)
{
	if (get_key_down(manager->game, MLX_KEY_ENTER))
	{
		game_manager_select(manager);
		return ;
	}
	if (get_key_up(manager->game, MLX_KEY_DOWN))
	{
		(*manager->active_menu)->selected_option++;
		if ((*manager->active_menu)->selected_option >= (*manager->active_menu)
			->num_options)
			(*manager->active_menu)->selected_option = 0;
	}
	if (get_key_up(manager->game, MLX_KEY_UP))
	{
		(*manager->active_menu)->selected_option--;
		if ((*manager->active_menu)->selected_option < 0)
			(*manager->active_menu)->selected_option = (*manager->active_menu)->num_options - 1;
	}
}
