diff --git a/includes/Cub3D.h b/includes/Cub3D.h index 7633333..9654a95 100644 --- a/includes/Cub3D.h +++ b/includes/Cub3D.h @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/02/13 16:30:59 by apommier #+# #+# */ -/* Updated: 2022/06/13 23:22:21 by apommier ### ########.fr */ +/* Updated: 2022/06/14 01:04:15 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -95,6 +95,7 @@ typedef struct s_data { char **double_map; map_info map; player player; + int err; } t_data; char *transform_map(char **double_map, t_data *img); @@ -114,4 +115,4 @@ void ft_error(char *error_msg); void print_player(player player, t_data *img); void print_map(map_info map, t_data *img); -#endif \ No newline at end of file +#endif diff --git a/srcs/parsing/check_color_texture.c b/srcs/parsing/check_color_texture.c index f34e597..d8c0e46 100644 --- a/srcs/parsing/check_color_texture.c +++ b/srcs/parsing/check_color_texture.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/11 01:00:17 by apommier #+# #+# */ -/* Updated: 2022/06/13 20:50:12 by apommier ### ########.fr */ +/* Updated: 2022/06/14 01:04:04 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,7 +58,7 @@ char *transform_map(char **double_map, t_data *img) //printf("index= %d\n", index); index++; } - + } img->map.simple_map = map; //printf("map = -%s-\n", map); @@ -139,4 +139,4 @@ int check_texture_color(char **tab, t_data *img) index++; } return (next); -} \ No newline at end of file +} diff --git a/srcs/parsing/parse_map.c b/srcs/parsing/parse_map.c index 098f929..1ab0a2f 100644 --- a/srcs/parsing/parse_map.c +++ b/srcs/parsing/parse_map.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/10 17:54:25 by sadjigui #+# #+# */ -/* Updated: 2022/06/13 20:51:12 by apommier ### ########.fr */ +/* Updated: 2022/06/14 01:03:43 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -90,7 +90,7 @@ int reverse_comp(char *s1, char *s2) return (0); } -void inter_map(char **split, char **tmp) +void inter_map(char **split, char **tmp, t_data *img) { int i; int j; @@ -101,7 +101,12 @@ void inter_map(char **split, char **tmp) j = 0; while(split[i][j]) { - if (ft_isalnum(split[i][j])) + if (split[i][j] == '3') + { + img->map.error = -1; + printf("%s %d\n", "-------------------------------------------", img->map.error); + } + else if (split[i][j] != ' ') tmp[i + 1][j + 1] = split[i][j]; j++; } @@ -176,7 +181,7 @@ void check_border(char **tab, t_data *img) j = 0; while (tab[i][j]) { - if (tab[i][j] == '0') + if (tab[i][j] == '0' || tab[i][j] == 'W' || tab[i][j] == 'N' || tab[i][j] == 'S' || tab[i][j] == 'E') close_or_not(tab, i, j, img); j++; } @@ -206,14 +211,53 @@ void check_zero_one(char **split, t_data *img) i++; } tmp[i] = NULL; - inter_map(split, tmp); + inter_map(split, tmp, img); + if (img->map.error == -1) + return; check_border(tmp, img); check_inner(tmp, img); free_tab(tmp); } +// typedef struct s_global +// { +// int err; +// } t_global; + +int is_in_charset(char c, char *charset) +{ + while (*charset) + { + if (c == *charset) + return (1); + charset++; + } + return (0); +} + +int detect_map_line(char *line) +{ + int i; + + i = 0; + if (!line) + return (0); + if (*line == '\0') + return (0); + while (line[i]) + { + if (is_in_charset(line[i], " 01NSEW\n") == 0) + return (0); + i++; + } + return (1); +} + char **isafile(char **av, t_data *img) { + // t_global g; + img->err = 0; + int fd; char *line; char *str; @@ -227,6 +271,11 @@ char **isafile(char **av, t_data *img) ft_exit("Error: File doesn't exist\n"); while ((line = get_next_line(fd)) != NULL) { + if (line[0] != '\n' && img->err == 0) + if (detect_map_line(line)) + img->err = 1; + if (line[0] == '\n' && img->err == 1) + img->err = 2; tmp = ft_strjoin(str, line); if (str != NULL) free(str); @@ -235,11 +284,15 @@ char **isafile(char **av, t_data *img) free(line); line = NULL; } + if (img->err == 2) + { + // free(line); + free(str); + ft_exit("Error\nBad texture file\n"); + } split = ft_split(str, '\n'); - //printf("this is it\n"); - //print_double_fd(split, 1); - free(line); free(str); + free(line); close(fd); int pass = 0; pass = check_texture_color(split, img); @@ -266,7 +319,8 @@ int check_map(char **av, t_data *img) img->map.max = img->map.x; else img->map.max = img->map.y; - + printf("----------------- d = %d", img->map.error); + if (img->map.error != 0) { error_msg(img);