From 2c44469c6b14562b16f26f578d91102a4f6cdc02 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 25 Jan 2020 19:11:02 +0100 Subject: not too bad --- Makefile | 1 + inc/cub3d.h | 1 + src/ft_get_colors.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/ft_init_lists.c | 2 ++ 4 files changed, 52 insertions(+) create mode 100644 src/ft_get_colors.c diff --git a/Makefile b/Makefile index 36647ee..f826999 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ SRCS_NAME += ft_parse_map.c SRCS_NAME += ft_get_res.c SRCS_NAME += ft_get_tex.c SRCS_NAME += ft_get_sprite_tex.c +SRCS_NAME += ft_get_colors.c SRCS_NAME += ft_check_empty_line.c SRCS_NAME += ft_free_words.c SRCS_NAME += ft_map_error.c diff --git a/inc/cub3d.h b/inc/cub3d.h index be40e49..ead1b52 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -48,6 +48,7 @@ void ft_drawsquare(t_win *wlist, int a, int b); int ft_get_res(int fd, t_win *wlist); int ft_get_tex(int fd, t_win *wlist); int ft_get_sprite_tex(int fd, t_win *wlist); +int ft_get_colors(int fd, t_win *wlist); void ft_check_empty_line(int fd, unsigned int linum, t_win *wlist); diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c new file mode 100644 index 0000000..8ef0678 --- /dev/null +++ b/src/ft_get_colors.c @@ -0,0 +1,48 @@ +#include +#include +#include + +static int +ft_get_f_color(char **words, t_win *wlist) +{ + char **num; + + if (!(*words) || ft_strcmp(*words, "F") || !words[1] || words[2]) + return (-1); + if (!(num = ft_split(words[1], ','))) + return (-1); + if (!num[0] || !num[1] || !num[2] || num[3]) + { + ft_free_words(num, NULL); + return (-1); + } + wlist->clist->f_color = ft_atoi(num[0]); + wlist->clist->f_color *= 1000; + wlist->clist->f_color += ft_atoi(num[1]); + wlist->clist->f_color *= 1000; + wlist->clist->f_color += ft_atoi(num[2]); + ft_free_words(num, NULL); + return (0); +} + +int +ft_get_colors(int fd, t_win *wlist) +{ + char *line; + char **words; + + if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' '))) + { + ft_memdel(line); + return (ft_map_error(8, wlist)); + } + if (ft_get_f_color(words, wlist) < 0) + { + ft_free_words(words, line); + return (ft_map_error(8, wlist)); + } + ft_free_words(words, line); + /* if (ft_get_c_color(words, wlist) < 0) */ + /* return (-1); */ + return (0); +} diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 799204b..6bec697 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -30,5 +30,7 @@ t_cub !(clist->we_tex_path = (char*)ft_calloc(1, 1)) || !(clist->sprite_path = (char*)ft_calloc(1, 1))) return (NULL); + clist->f_color = 0; + clist->c_color = 0; return (clist); } -- cgit v1.2.3