aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--inc/cub3d.h1
-rw-r--r--src/ft_get_colors.c48
-rw-r--r--src/ft_init_lists.c2
4 files changed, 52 insertions, 0 deletions
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 <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);
}