diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-25 19:11:02 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-25 19:11:02 +0100 |
commit | 2c44469c6b14562b16f26f578d91102a4f6cdc02 (patch) | |
tree | d54bbdb6e0c04eb72fac6f327ef45ee8ea7ef243 /src | |
parent | Function to print the lists (diff) | |
download | 42-cub3d-2c44469c6b14562b16f26f578d91102a4f6cdc02.tar.gz 42-cub3d-2c44469c6b14562b16f26f578d91102a4f6cdc02.tar.bz2 42-cub3d-2c44469c6b14562b16f26f578d91102a4f6cdc02.tar.xz 42-cub3d-2c44469c6b14562b16f26f578d91102a4f6cdc02.tar.zst 42-cub3d-2c44469c6b14562b16f26f578d91102a4f6cdc02.zip |
not too bad
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_get_colors.c | 48 | ||||
-rw-r--r-- | src/ft_init_lists.c | 2 |
2 files changed, 50 insertions, 0 deletions
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 <libft.h> +#include <cub3d.h> +#include <stddef.h> + +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); } |