42_solong/mandatory/asset.c

56 lines
1.7 KiB
C
Raw Permalink Normal View History

2023-01-06 13:37:36 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* asset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 14:23:00 by cchauvet #+# #+# */
2023-01-19 07:41:58 -05:00
/* Updated: 2023/01/18 17:32:05 by cchauvet ### ########.fr */
2023-01-06 13:37:36 -05:00
/* */
/* ************************************************************************** */
#include "solong.h"
2023-01-13 10:10:11 -05:00
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);
}
2023-01-11 13:10:28 -05:00
int ft_gen_assets(t_data *data)
2023-01-06 13:37:36 -05:00
{
char **colors;
size_t i;
2023-01-06 13:37:36 -05:00
colors = ft_split(COLORS, '|');
if (colors == NULL)
2023-01-06 13:37:36 -05:00
return (1);
i = 0;
2023-01-11 13:10:28 -05:00
while (i < NB_COLORS)
2023-01-06 13:37:36 -05:00
{
2023-01-13 10:10:11 -05:00
data->assets[i] = ft_gen_asset(colors[i], CASE_SIZE, data);
if (data->assets[i] == NULL)
return (1);
i++;
2023-01-06 13:37:36 -05:00
}
2023-01-16 12:38:47 -05:00
data->assets[NB_COLORS] = ft_gen_asset(colors[i],
2023-01-19 07:41:58 -05:00
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE, data);
2023-01-16 12:38:47 -05:00
if (data->assets[NB_COLORS] == NULL)
return (1);
ft_freer_tab_ultimate(1, colors);
2023-01-06 13:37:36 -05:00
return (0);
}