From c1f91998d9cf530d86b6e8d2ddfecf06cae43664 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 28 Jan 2020 16:32:37 +0100 Subject: Got sprite --- Makefile | 2 +- map/map_one.cub | 10 +++++++++- src/ft_get_res.c | 1 - src/ft_get_sprite.c | 23 ++++------------------- src/ft_get_sprite_tex.c | 29 ----------------------------- src/ft_get_tex.c | 4 ---- src/ft_select_get.c | 16 +++++++++------- 7 files changed, 23 insertions(+), 62 deletions(-) delete mode 100644 src/ft_get_sprite_tex.c diff --git a/Makefile b/Makefile index e622c4e..1707b67 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ SRCS_NAME += ft_parse_map.c SRCS_NAME += ft_select_get.c SRCS_NAME += ft_get_res.c SRCS_NAME += ft_get_tex.c -# SRCS_NAME += ft_get_sprite_tex.c +SRCS_NAME += ft_get_sprite.c # SRCS_NAME += ft_get_colors.c # SRCS_NAME += ft_get_map.c # SRCS_NAME += ft_check_empty_line.c diff --git a/map/map_one.cub b/map/map_one.cub index 70d8d5d..1d6ceed 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -14,9 +14,17 @@ NO ./path_to_the_north_texture SO ./path_to_the_south_texture -WE ./path_to_the_west_texture qweqwe +WE ./path_to_the_west_texture EA ./path_to_the_east_texture + + + + + + + + S ./path_to_the_sprite_texture F 220,100,0 C 225,30,0 diff --git a/src/ft_get_res.c b/src/ft_get_res.c index 42b3f19..850e82e 100644 --- a/src/ft_get_res.c +++ b/src/ft_get_res.c @@ -26,6 +26,5 @@ ft_get_res(char **words, t_cub *clist) ft_checkdigit(words[2], clist); clist->wlist->x_size = ft_atoi(words[1]); clist->wlist->y_size = ft_atoi(words[2]); - ft_free_words(words); return (0); } diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index 568e513..f1fa73f 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -1,29 +1,14 @@ #include #include -#include int -ft_get_sprite(int fd, t_cub *clist) +ft_get_sprite(char **words, t_cub *clist) { - char *line; - char **words; - - if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' '))) - { - ft_memdel(line); - return (ft_map_error(7, clist)); - } - if (!(*words) || ft_strcmp(*words, "S") || !words[1] || words[2]) - { - ft_free_words(words, line); - return (ft_map_error(7, clist)); - } + if (!(*words) || !words[1] || words[2]) + return (-1); ft_memdel(clist->sprite_path); if (!(clist->sprite_path = ft_strdup(*(words + 1)))) - { - ft_free_words(words, line); return (-1); - } - ft_free_words(words, line); + ft_printf("{%s}\n", clist->sprite_path); return (0); } diff --git a/src/ft_get_sprite_tex.c b/src/ft_get_sprite_tex.c deleted file mode 100644 index 8eb9481..0000000 --- a/src/ft_get_sprite_tex.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include - -int -ft_get_sprite(char **words, t_cub *clist) -{ - char *line; - char **words; - - if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' '))) - { - ft_memdel(line); - return (ft_map_error(7, clist)); - } - if (!(*words) || ft_strcmp(*words, "S") || !words[1] || words[2]) - { - ft_free_words(words, line); - return (ft_map_error(7, clist)); - } - ft_memdel(clist->sprite_path); - if (!(clist->sprite_path = ft_strdup(*(words + 1)))) - { - ft_free_words(words, line); - return (-1); - } - ft_free_words(words, line); - return (0); -} diff --git a/src/ft_get_tex.c b/src/ft_get_tex.c index a409a3c..3c0f305 100644 --- a/src/ft_get_tex.c +++ b/src/ft_get_tex.c @@ -10,7 +10,6 @@ ft_get_tex_no(char **words, t_cub *clist) ft_memdel(clist->no_tex_path); if (!(clist->no_tex_path = ft_strdup(*(words + 1)))) return (-1); - ft_free_words(words); return (0); } @@ -22,7 +21,6 @@ ft_get_tex_so(char **words, t_cub *clist) ft_memdel(clist->so_tex_path); if (!(clist->so_tex_path = ft_strdup(*(words + 1)))) return (-1); - ft_free_words(words); return (0); } @@ -34,7 +32,6 @@ ft_get_tex_ea(char **words, t_cub *clist) ft_memdel(clist->ea_tex_path); if (!(clist->ea_tex_path = ft_strdup(*(words + 1)))) return (-1); - ft_free_words(words); return (0); } @@ -46,6 +43,5 @@ ft_get_tex_we(char **words, t_cub *clist) ft_memdel(clist->we_tex_path); if (!(clist->we_tex_path = ft_strdup(*(words + 1)))) return (-1); - ft_free_words(words); return (0); } diff --git a/src/ft_select_get.c b/src/ft_select_get.c index 7b1b524..d44fa88 100644 --- a/src/ft_select_get.c +++ b/src/ft_select_get.c @@ -5,17 +5,17 @@ static uint8_t ft_get_id(char **words) { - if (!ft_strcmp(words[0], "R")) + if (!ft_strncmp(words[0], "R", 1)) return (0); - if (!ft_strcmp(words[0], "NO")) + if (!ft_strncmp(words[0], "NO", 2)) return (1); - if (!ft_strcmp(words[0], "SO")) + if (!ft_strncmp(words[0], "SO", 2)) return (2); - if (!ft_strcmp(words[0], "EA")) + if (!ft_strncmp(words[0], "EA", 2)) return (3); - if (!ft_strcmp(words[0], "WE")) + if (!ft_strncmp(words[0], "WE", 2)) return (4); - if (!ft_strcmp(words[0], "S")) + if (!ft_strncmp(words[0], "S", 1)) return (5); return (12); } @@ -23,7 +23,7 @@ ft_get_id(char **words) uint8_t ft_select_get(char **words, t_cub *clist) { - int (*fun_ptr[6])(char**, t_cub*); + int (*fun_ptr[7])(char**, t_cub*); uint8_t id; fun_ptr[0] = ft_get_res; @@ -32,6 +32,7 @@ ft_select_get(char **words, t_cub *clist) fun_ptr[3] = ft_get_tex_ea; fun_ptr[4] = ft_get_tex_we; fun_ptr[5] = ft_get_sprite; + fun_ptr[6] = ft_get_colors; if ((id = ft_get_id(words)) == 12) { ft_free_words(words); @@ -42,5 +43,6 @@ ft_select_get(char **words, t_cub *clist) ft_free_words(words); return (ft_map_error(clist)); } + ft_free_words(words); return (id); } -- cgit v1.2.3