/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   initialize.c                                       :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: qmennen <qmennen@student.codam.nl>         +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2025/04/22 17:08:26 by qmennen           #+#    #+#             */
/*   Updated: 2025/06/04 19:51:13 by qmennen          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "cub3d.h"

t_sprite	make_sprite(t_sprite_lib *def, double x, double y)
{
	t_sprite	sprite;

	ft_memset(&sprite, 0, sizeof(t_sprite));
	sprite.texture = def->texture;
	sprite.n_frames = sprite.texture->width / sprite.texture->height;
	sprite.animation_speed = 10;
	sprite.pos.x = x;
	sprite.pos.y = y;
	sprite.type = def->type;
	return (sprite);
}

static int	init_temp(t_game **game)
{
	mlx_texture_t	*hud_texture;

	hud_texture = mlx_load_png("./assets/hud/cam_overlay.png");
	(*game)->screen->hud = mlx_texture_to_image((*game)->screen->mlx,
			hud_texture);
	mlx_delete_texture(hud_texture);
	return (SUCCESS);
}

int	initialize_cub3d(t_game **game, const char *mapfile)
{
	if (!game_create(game))
		return (FAILURE);
	if (!player_create(game))
		return (FAILURE);
	if (!map_create(game, mapfile))
		return (FAILURE);
	if (!texture_load(*game))
		return (FAILURE);
	if (!shader_init(game))
		return (FAILURE);
	if (!screen_create(game))
		return (FAILURE);
	if (!load_uniforms(game))
		return (FAILURE);
	if (!keyboard_create(game))
		return (FAILURE);
	if (!init_temp(game))
		return (FAILURE);
	if (!screen_display((*game)->screen))
		return (FAILURE);
	return (SUCCESS);
}
