42_solong/asset.c
Camille Chauvet f84f98fe21 CA MARCHE
2023-01-13 16:10:11 +01:00

56 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* asset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 14:23:00 by cchauvet #+# #+# */
/* Updated: 2023/01/13 16:03:54 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "solong.h"
static void *ft_gen_asset(char *color, size_t case_size, t_data *data)
{
t_square square;
char *name;
int dimmension;
void *img;
square.color = color;
square.size = case_size;
name = ft_xpm_gen_file(square);
if (name == NULL)
return (NULL);
img = mlx_xpm_file_to_image(data->mlx,
name, &dimmension, &dimmension);
free(name);
return (img);
}
int ft_gen_assets(t_data *data)
{
char **colors;
size_t i;
colors = ft_split(COLORS, '|');
if (colors == NULL)
return (1);
i = 0;
while (i < NB_COLORS)
{
data->assets[i] = ft_gen_asset(colors[i], CASE_SIZE, data);
if (data->assets[i] == NULL)
return (1);
data->assets[i + NB_COLORS] = ft_gen_asset(colors[i],
WINDOW_SIZE, data);
if (data->assets[i + NB_COLORS] == NULL)
return (1);
i++;
}
ft_freer_tab_ultimate(1, colors);
return (0);
}