diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_get_sprite_tex.c | 44 | ||||
-rw-r--r-- | src/ft_map_error.c | 4 | ||||
-rw-r--r-- | src/ft_parse_map.c | 3 |
3 files changed, 48 insertions, 3 deletions
diff --git a/src/ft_get_sprite_tex.c b/src/ft_get_sprite_tex.c new file mode 100644 index 0000000..5dbe4b4 --- /dev/null +++ b/src/ft_get_sprite_tex.c @@ -0,0 +1,44 @@ +#include <libft.h> +#include <cub3d.h> +#include <stdlib.h> + +static void +ft_check_empty_line(int fd, unsigned int linum, t_win *wlist) +{ + char *line; + + get_next_line(fd, &line); + if (*line) + { + ft_memdel(line); + ft_map_error(linum, wlist); + } + ft_memdel(line); +} + +int +ft_get_sprite_tex(int fd, t_win *wlist) +{ + char *line; + char **words; + size_t len; + + ft_check_empty_line(fd, 6, wlist); + get_next_line(fd, &line); + if (!(words = ft_split(line, ' '))) + return (ft_exit(5, wlist)); + if (!(*words) || ft_strcmp(*words, "S") + || !(*(words + 1)) || (*(words + 2))) + { + ft_free_words(words); + return (ft_map_error(7, wlist)); + } + ft_memdel(wlist->clist->sprite_path); + len = ft_strlen(*(words + 1)); + if (!(wlist->clist->sprite_path = (char*)malloc((len + 1) * sizeof(char)))) + return (-1); + ft_strlcpy(wlist->clist->sprite_path, *(words + 1), len + 1); + ft_free_words(words); + ft_memdel(line); + return (0); +} diff --git a/src/ft_map_error.c b/src/ft_map_error.c index 6af5438..2e8a9ff 100644 --- a/src/ft_map_error.c +++ b/src/ft_map_error.c @@ -3,9 +3,9 @@ #include <unistd.h> int -ft_map_error(unsigned int line, t_win *wlist) +ft_map_error(unsigned int linum, t_win *wlist) { ft_dprintf(STDERR_FILENO, "Error\n"); - ft_dprintf(STDERR_FILENO, "\033[1;31mMap error: line %d\033[0m\n", line); + ft_dprintf(STDERR_FILENO, "\033[1;31mMap error: line %d\033[0m\n", linum); return (ft_exit(1, wlist)); } diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 0a4aa45..011dfcf 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -48,6 +48,7 @@ ft_parse_map(const char *map_path, t_win *wlist) ft_exit(2, wlist); } ft_get_res(fd, wlist); - if (ft_get_tex(fd, wlist) < 0) + if (ft_get_tex(fd, wlist) < 0 || + ft_get_sprite_tex(fd, wlist) < 0) return ; } |