changed rgb deal, and improve memorybook with 2d

This commit is contained in:
hugogogo
2022-05-01 22:55:00 +02:00
parent 43852938c4
commit eb5f2db7fa
9 changed files with 60 additions and 54 deletions

View File

@@ -6,13 +6,13 @@
/* By: pblagoje <pblagoje@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/15 16:11:24 by pblagoje #+# #+# */
/* Updated: 2022/04/23 18:40:13 by pblagoje ### ########.fr */
/* Updated: 2022/05/01 22:53:25 by simplonco ### ########.fr */
/* */
/* ************************************************************************** */
#include "cube3d.h"
int check_colors(char **str)
static int check_colors(char **str)
{
int i;
int num;
@@ -29,7 +29,7 @@ int check_colors(char **str)
return (EXIT_SUCCESS);
}
int ft_strlen_2d(char **str)
static int ft_strlen_2d(char **str)
{
int i;
@@ -39,28 +39,16 @@ int ft_strlen_2d(char **str)
return (i);
}
void set_floor_rgb(t_txt *txt, char **rgb)
static void set_rgb(int *plan, char **rgb)
{
int i;
int r;
int g;
int b;
i = 0;
while (i < 3)
{
txt->rgb_floor[i] = ft_atoi(rgb[i]);
i++;
}
}
void set_ceiling_rgb(t_txt *txt, char **rgb)
{
int i;
i = 0;
while (i < 3)
{
txt->rgb_ceiling[i] = ft_atoi(rgb[i]);
i++;
}
r = ft_atoi(rgb[0]);
g = ft_atoi(rgb[1]);
b = ft_atoi(rgb[2]);
*plan = 0 << 24 | r << 16 | g << 8 | b;
}
void ft_free_2d(char **str)
@@ -76,28 +64,19 @@ void ft_free_2d(char **str)
free(str);
}
int check_rgb(t_txt *txt, char *element, char identifier)
int check_rgb(t_txt *txt, char *elem, char identifier)
{
char **rgb;
rgb = ft_split(element, ',');
if (!rgb || ft_strlen_2d(rgb) != 3 || \
element[ft_strlen(element) - 1] == ',')
{
ft_free_2d(rgb);
ft_putstr_fd("Error\nInvalid RGB code.\n", 2);
return (EXIT_FAILURE);
}
rgb = ft_split(elem, ',');
mb_add_2d((void**)rgb, ft_strlen_2d(rgb));
if (!rgb || ft_strlen_2d(rgb) != 3 || elem[ft_strlen(elem) - 1] == ',')
mb_exit("Error\nInvalid RGB code.\n", EXIT_FAILURE);
if ((identifier != 'F' && identifier != 'C') || check_colors(rgb))
{
ft_free_2d(rgb);
ft_putstr_fd("Error\nInvalid RGB code.\n", 2);
return (EXIT_FAILURE);
}
mb_exit("Error\nInvalid RGB code.\n", EXIT_FAILURE);
if (identifier == 'F')
set_floor_rgb(txt, rgb);
set_rgb(&txt->rgb_floor, rgb);
else
set_ceiling_rgb(txt, rgb);
ft_free_2d(rgb);
set_rgb(&txt->rgb_ceiling, rgb);
return (EXIT_SUCCESS);
}