This commit is contained in:
Camille Chauvet
2023-05-05 11:51:11 +00:00
15 changed files with 235 additions and 136 deletions

View File

@ -10,6 +10,8 @@ typedef struct s_map
void *img[4];
long long color_bot;
long long color_top;
size_t size_x;
size_t size_y;
double ply_x;
double ply_y;
char direction;

BIN
map/parsing.o Normal file

Binary file not shown.

View File

@ -1,7 +1,5 @@
#include "map.h"
#include "parsing_private.h"
#include <stddef.h>
#include <stdlib.h>
char **get_body(const char **file_content, size_t header_size)
{
@ -75,38 +73,11 @@ static int map_is_in_one_part(const char **body)
return (0);
}
static char **map_cpy(const char **body)
{
size_t i;
char **copy;
copy = malloc((ft_tablen((const void **) body) + 1) * sizeof(char *));
if (copy == NULL)
return (NULL);
i = 0;
while (body[i] != NULL)
{
copy[i] = ft_strdup(body[i]);
if (copy[i] == NULL)
{
ft_cancel((void **) copy, i);
return (NULL);
}
i++;
}
copy[i] = NULL;
return (copy);
}
static int map_surround(const char **body)
{
char **copy;
size_t y;
size_t x;
copy = map_cpy(body);
if (copy == NULL)
return (1);
y = 0;
while (body[y] != NULL)
{
@ -127,7 +98,6 @@ static int map_surround(const char **body)
}
y++;
}
ft_freer_tab_ultimate(1, copy);
return (0);
}
@ -154,6 +124,23 @@ static int body_contain_normal_char(const char **body)
return (1);
}
void get_size(const char **body, t_map *map)
{
size_t y;
size_t x;
map->size_x = 0;
y = 0;
while (body[y] != NULL)
{
x = ft_strlen(body[y]);
if (x > map->size_x)
map->size_x = x;
y++;
}
map->size_y = y;
}
int body_is_valid(const char **body, t_map *map)
{
int error;
@ -185,5 +172,6 @@ int body_is_valid(const char **body, t_map *map)
}
if (body_contain_normal_char(body) == 0)
return (0);
get_size(body, map);
return (1);
}