aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-01-24 18:35:49 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-01-24 18:35:49 +0100
commita8444907257b7a46b7b2cb9ee49c20fe82b8789e (patch)
treeff904d583d20e78330b751e3624deb9f0cc4d329
parentGot east texture (diff)
download42-cub3d-a8444907257b7a46b7b2cb9ee49c20fe82b8789e.tar.gz
42-cub3d-a8444907257b7a46b7b2cb9ee49c20fe82b8789e.tar.bz2
42-cub3d-a8444907257b7a46b7b2cb9ee49c20fe82b8789e.tar.xz
42-cub3d-a8444907257b7a46b7b2cb9ee49c20fe82b8789e.tar.zst
42-cub3d-a8444907257b7a46b7b2cb9ee49c20fe82b8789e.zip
Correct
Diffstat (limited to '')
-rw-r--r--Makefile1
-rw-r--r--inc/cub3d.h3
-rw-r--r--src/ft_get_sprite_tex.c44
-rw-r--r--src/ft_map_error.c4
-rw-r--r--src/ft_parse_map.c3
5 files changed, 51 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 3798958..cdffb1a 100644
--- a/Makefile
+++ b/Makefile
@@ -24,6 +24,7 @@ SRCS_NAME += ft_drawsquare.c
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_free_words.c
SRCS_NAME += ft_map_error.c
SRCS_NAME += ft_init_winlx.c
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 909dcf8..e837a34 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -47,8 +47,9 @@ int ft_exit(uint8_t exit_code, t_win *wlist);
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);
void ft_free_words(char **words);
-int ft_map_error(unsigned int line, t_win *wlist);
+int ft_map_error(unsigned int linum, t_win *wlist);
int ft_init_winlx(t_win *wlist);
#endif
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 ;
}