42_cube3D/map/parsing_header2.c

54 lines
1.0 KiB
C
Raw Normal View History

2023-05-03 07:09:06 -04:00
#include "./parsing_private.h"
static int set_texture(t_map *map, int token, const char *key, char *value)
{
if (map->img[token - 1] != NULL)
{
ft_eprintf("redefinition of %s", key);
return (1);
}
map->img[token - 1] = value;
return (0);
}
static int set_color(long long *color, const char *key, char *value)
{
if (*color != -1)
{
ft_eprintf("redefinition of %s", key);
return (1);
}
if (ft_atoul_check(value))
{
ft_eprintf("%s is to high", value);
return (1);
}
*color = ft_atoul(value);
return (0);
}
int header_is_valid(char ***header, t_map *map)
{
size_t i;
int token;
map->color_bot = -1;
map->color_top = -1;
i = 0;
while (i < ft_tablen((const void **) header))
{
token = get_token(header[i][0]);
if (token > 0 && token < 5
&& set_texture(map, token, header[i][0], header[i][1]))
return (0);
else if ((token == 5 && set_color(&map->color_bot,
header[i][0], header[i][1]))
|| (token == 6 && set_color(&map->color_top,
header[i][0], header[i][1])))
return (0);
i++;
}
return (1);
}