/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.c                                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: qmennen <qmennen@student.codam.nl>         +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2025/04/15 16:01:29 by qmennen           #+#    #+#             */
/*   Updated: 2025/06/04 18:53:54 by qmennen          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "cub3d.h"

int	main(int argc, char **argv)
{
	t_game_manager		*manager;
	t_game				*game;

	errno = 0;
	game = NULL;
	if (!valid_arguments(argc, argv))
		return (EXIT_FAILURE);
	if (!initialize_cub3d(&game, argv[1]))
	{
		perror("initialize_cub3d");
		game_free(game);
		return (EXIT_FAILURE);
	}
	manager = game_manager_create(game, START_STATE);
	manager->menu = create_main_menu(manager);
	manager->end_screen = create_end_screen(manager);
	manager->active_menu = &manager->menu;
	mlx_key_hook(game->screen->mlx, keyhandle, manager);
	mlx_loop_hook(game->screen->mlx, game_manager_update, manager);
	mlx_loop(game->screen->mlx);
	game_manager_destroy(manager);
	return (EXIT_SUCCESS);
}
