diff options
author | Rudy Bousset <rbousset@z2r5p2.le-101.fr> | 2020-02-03 19:15:09 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r5p2.le-101.fr> | 2020-02-03 19:15:09 +0100 |
commit | 127ef13e2e69ec2609faa4b4938fd03fe7dae1a6 (patch) | |
tree | 3bfeee18a5e605274811b438c244b7c2dd40cf2c | |
parent | Reverted main (diff) | |
download | 42-cub3d-127ef13e2e69ec2609faa4b4938fd03fe7dae1a6.tar.gz 42-cub3d-127ef13e2e69ec2609faa4b4938fd03fe7dae1a6.tar.bz2 42-cub3d-127ef13e2e69ec2609faa4b4938fd03fe7dae1a6.tar.xz 42-cub3d-127ef13e2e69ec2609faa4b4938fd03fe7dae1a6.tar.zst 42-cub3d-127ef13e2e69ec2609faa4b4938fd03fe7dae1a6.zip |
commit
-rw-r--r-- | src/ft_select_get.c | 72 |
1 files changed, 52 insertions, 20 deletions
diff --git a/src/ft_select_get.c b/src/ft_select_get.c index 448223e..0594415 100644 --- a/src/ft_select_get.c +++ b/src/ft_select_get.c @@ -15,33 +15,60 @@ #include <cub3d.h> #include <stdint.h> -static uint8_t - ft_get_id(char **words) +static int8_t +ft_check_exists_one(int8_t ret, t_cub *clist) { + if (ret == 0 && (clist->wlist->x_size != -1 || clist->wlist->y_size != -1)) + ret = -1; + else if (ret == 1 && (clist->no_tex_path[0])) + ret = -1; + else if (ret == 2 && (clist->so_tex_path[0])) + ret = -1; + else if (ret == 3 && (clist->ea_tex_path[0])) + ret = -1; + else if (ret == 4 && (clist->we_tex_path[0])) + ret = -1; + else if (ret == 5 && (clist->sprite_path[0])) + ret = -1; + else if (ret == 6 && (clist->f_color != -1)) + ret = -1; + else if (ret == 7 && (clist->c_color != -1)) + ret = -1; + return (ret); +} + +static int8_t + ft_get_id(char **words, t_cub *clist) +{ + int8_t ret; + if (!ft_strncmp(words[0], "R", 2)) - return (0); - if (!ft_strncmp(words[0], "NO", 3)) - return (1); - if (!ft_strncmp(words[0], "SO", 3)) - return (2); - if (!ft_strncmp(words[0], "EA", 3)) - return (3); - if (!ft_strncmp(words[0], "WE", 3)) - return (4); - if (!ft_strncmp(words[0], "S", 2)) - return (5); - if (!ft_strncmp(words[0], "F", 2)) - return (6); - if (!ft_strncmp(words[0], "C", 2)) - return (7); - return (12); + ret = 0; + else if (!ft_strncmp(words[0], "NO", 3)) + ret = 1; + else if (!ft_strncmp(words[0], "SO", 3)) + ret = 2; + else if (!ft_strncmp(words[0], "EA", 3)) + ret = 3; + else if (!ft_strncmp(words[0], "WE", 3)) + ret = 4; + else if (!ft_strncmp(words[0], "S", 2)) + ret = 5; + else if (!ft_strncmp(words[0], "F", 2)) + ret = 6; + else if (!ft_strncmp(words[0], "C", 2)) + ret = 7; + else + ret = 12; + ret = ft_check_exists_one(ret, clist); + return (ret); } uint8_t ft_select_get(char **words, t_cub *clist) { int (*fun_ptr[8])(char**, t_cub*); - uint8_t id; + int8_t id; fun_ptr[0] = ft_get_res; fun_ptr[1] = ft_get_tex_no; @@ -51,11 +78,16 @@ uint8_t fun_ptr[5] = ft_get_sprite; fun_ptr[6] = ft_get_f_color; fun_ptr[7] = ft_get_c_color; - if ((id = ft_get_id(words)) == 12) + if ((id = ft_get_id(words, clist)) == 12) { ft_free_words(words); return (12); } + if (id < 0) + { + ft_free_words(words); + return (-1); + } if ((*fun_ptr[id])(words, clist) < 0) { ft_free_words(words); |