diff options
author | Rudy Bousset <rbousset@z2r5p2.le-101.fr> | 2020-03-12 17:48:43 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r5p2.le-101.fr> | 2020-03-12 17:48:43 +0100 |
commit | 88cd7098410c7ab80baecc6c2a4d5da99e10162f (patch) | |
tree | 0090da4d5ca1e58466cf4c32a0c38ef0ee894287 /src/ft_get_sprite.c | |
parent | removed junk (diff) | |
download | 42-cub3d-88cd7098410c7ab80baecc6c2a4d5da99e10162f.tar.gz 42-cub3d-88cd7098410c7ab80baecc6c2a4d5da99e10162f.tar.bz2 42-cub3d-88cd7098410c7ab80baecc6c2a4d5da99e10162f.tar.xz 42-cub3d-88cd7098410c7ab80baecc6c2a4d5da99e10162f.tar.zst 42-cub3d-88cd7098410c7ab80baecc6c2a4d5da99e10162f.zip |
kk
Diffstat (limited to 'src/ft_get_sprite.c')
-rw-r--r-- | src/ft_get_sprite.c | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index a158940..902ab87 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -75,28 +75,71 @@ void } } +static int8_t + ft_get_sprite_id(char *word) +{ + int8_t ret; + char ref[8][3]; + + ft_sprintf(ref[0], "S"); + ft_sprintf(ref[1], "S2"); + ft_sprintf(ref[2], "S3"); + ft_sprintf(ref[3], "S4"); + ft_sprintf(ref[4], "S5"); + ft_sprintf(ref[5], "S6"); + ft_sprintf(ref[6], "S7"); + ft_sprintf(ref[7], "S8"); + ret = 0; + while (ft_strncmp(word, ref[ret], 3) && ref[ret][0]) + ret++; + return (ret); +} + +static int8_t + ft_check_sprite_amount(int8_t id, t_cub *clist) +{ + int8_t i; + + i = 0; + while (i < id) + { + if (!clist->mlist.sprite_path[i][0]) + return (-1); + i++; + } + return (0); +} + int8_t ft_get_sprite(char **words, t_cub *clist) { + int8_t id; + if (!(*words) || !words[1] || words[2]) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS); + ft_sprintf(clist->errmsg, FT_ERR_ARGS); return (-1); } if (ft_check_ext(*(words + 1), ".xpm") < 0) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM); + ft_sprintf(clist->errmsg, FT_ERR_NOT_A_XPM); + return (-1); + } + id = ft_get_sprite_id(words[0]); + if (ft_check_sprite_amount(id, clist) < 0) + { + ft_sprintf(clist->errmsg, FT_ERR_SPRITE_DUMB); return (-1); } - ft_memdel((void**)&clist->mlist.sprite_path); - if (!(clist->mlist.sprite_path = ft_strdup(*(words + 1)))) + ft_memdel((void**)&clist->mlist.sprite_path[id]); + if (!(clist->mlist.sprite_path[id] = ft_strdup(*(words + 1)))) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE); + ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE); return (-1); } - if (ft_check_not_found(clist->mlist.sprite_path) < 0) + if (ft_check_not_found(clist->mlist.sprite_path[id]) < 0) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_SP); + ft_sprintf(clist->errmsg, FT_ERR_RD_SP); return (-1); } return (0); |