42_solong/asset.c
Camille Chauvet d7256c47a5 kekw
2023-01-06 19:37:36 +01:00

75 lines
1.8 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* asset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 14:23:00 by cchauvet #+# #+# */
/* Updated: 2023/01/06 18:20:19 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "solong.h"
static void ft_freer(char **tab)
{
size_t i;
i = 0;
if (tab == NULL)
return ;
while (tab[i] != NULL)
{
free(tab[i]);
i++;
}
free(tab);
}
static void ft_freer_utimate(size_t len, ...)
{
va_list va;
size_t i;
i = 0;
va_start(va, len);
while (i < len)
{
ft_freer(va_arg(va, char **));
i++;
}
va_end(va);
}
int ft_gen_assets(void)
{
char **colors;
char **shapes;
size_t tab[2];
t_shape shape;
colors = ft_split(COLORS, '|');
shapes = ft_split(SHAPES, '|');
if (shapes == NULL && colors == NULL)
{
ft_freer_utimate(2, shapes, colors);
return (1);
}
tab[0] = -1;
while (colors[++tab[0]] != NULL)
{
tab[1] = -1;
while (shapes[++tab[1]] != NULL)
{
shape.color = colors[tab[0]];
shape.bcolor = BACKGROUND_COLOR;
shape.shape = shapes[tab[1]];
shape.size = CASE_SIZE;
free(ft_xpm_gen_file(shape));
}
}
ft_freer_utimate(2, shapes, colors);
return (0);
}