From 7f2a0b4a0e637ee7e1c4fae8914b59b9e3ccd4c9 Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Tue, 16 May 2023 12:47:04 +0000 Subject: [PATCH] fix: missing key --- map/parsing.c | 2 +- map/parsing_body.c | 2 +- map/parsing_header2.c | 45 +++++++++++++++++++++++++++++++++++-------- map/parsing_meta.c | 2 +- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/map/parsing.c b/map/parsing.c index 17f9f47..a5e0af6 100644 --- a/map/parsing.c +++ b/map/parsing.c @@ -75,9 +75,9 @@ int map_parsing(const char *path, t_map *map) char ***header; size_t header_size; + ft_bzero(map, sizeof(t_map)); if (parsing_meta(path)) return (1); - ft_bzero(map, sizeof(t_map)); file_content = read_map(path); if (file_content == NULL) { diff --git a/map/parsing_body.c b/map/parsing_body.c index cc223de..4977dc3 100644 --- a/map/parsing_body.c +++ b/map/parsing_body.c @@ -154,7 +154,7 @@ int body_is_valid(t_map *map) } else if (error == 2) { - ft_eprintf("map: spawn position: not define"); + ft_eprintf("map: spawn position: not defined"); return (0); } map->direction = map->map[(int) map->ply_y][(int) map->ply_x]; diff --git a/map/parsing_header2.c b/map/parsing_header2.c index f0a9fcd..5b657ec 100644 --- a/map/parsing_header2.c +++ b/map/parsing_header2.c @@ -1,4 +1,5 @@ #include "./parsing_private.h" +#include "map.h" static int set_texture(t_map *map, int token, const char *key, char *value) { @@ -66,6 +67,25 @@ static int set_color(long long *color, const char *key, char *value) return (*color == -1); } +int check_header_is_complete(t_map *map) +{ + if (map->img_path[0] == NULL) + ft_eprintf("map: incomplete: Nord texture is missing"); + else if (map->img_path[0] == NULL) + ft_eprintf("map: incomplete: WEST texture is missing"); + else if (map->img_path[0] == NULL) + ft_eprintf("map: incomplete: SOUTH texture is missing"); + else if (map->img_path[0] == NULL) + ft_eprintf("map: incomplete: EAST texture is missing"); + else if (map->color_bot == -1) + ft_eprintf("map: incomplete: floor color is missing"); + else if (map->color_top == -1) + ft_eprintf("map: incomplete: roof color is missing"); + else + return (0); + return (1); +} + int header_is_valid(char ***header, t_map *map) { size_t i; @@ -80,15 +100,24 @@ int header_is_valid(char ***header, t_map *map) 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, + if (token > 0 && token < 5) + { + if (set_texture(map, token, header[i][0], header[i][1])) + return (1); + } + else if (token == 5) + { + if (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); + return (1); + } + else if (token == 6) + { + if (set_color(&map->color_top, + header[i][0], header[i][1])) + return (1); + } i++; } - return (!map->img_path[0] || !map->img_path[1] || !map->img_path[2]|| !map->img_path[3] || map->color_top == -1 || map->color_bot == -1); + return (check_header_is_complete(map)); } diff --git a/map/parsing_meta.c b/map/parsing_meta.c index 7424a94..b58589d 100644 --- a/map/parsing_meta.c +++ b/map/parsing_meta.c @@ -8,7 +8,7 @@ static int name_check(const char *path) if (len < 4 || (ft_strcmp(".cub", path + len - 4) != 0)) { - ft_eprintf("map: name doesn't finished by .cub"); + ft_eprintf("map: name doesn't finish by .cub"); return (1); } return (0);