1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/* ************************************************************************** */
/* LE - / */
/* / */
/* ft_select_get.c .:: .:/ . .:: */
/* +:+:+ +: +: +:+:+ */
/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2020/02/02 17:19:33 by rbousset #+# ## ## #+# */
/* Updated: 2020/02/02 17:19:33 by rbousset ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
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))
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*);
int8_t id;
fun_ptr[0] = ft_get_res;
fun_ptr[1] = ft_get_tex_no;
fun_ptr[2] = ft_get_tex_so;
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_f_color;
fun_ptr[7] = ft_get_c_color;
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);
return (ft_map_error(clist));
}
ft_free_words(words);
return (id);
}
|