aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_select_get.c
blob: d44fa88cc66c8e99031f7c9e7215ee3e0a6642bf (plain)
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
#include <libft.h>
#include <cub3d.h>
#include <stdint.h>

static uint8_t
ft_get_id(char **words)
{
	if (!ft_strncmp(words[0], "R", 1))
		return (0);
	if (!ft_strncmp(words[0], "NO", 2))
		return (1);
	if (!ft_strncmp(words[0], "SO", 2))
		return (2);
	if (!ft_strncmp(words[0], "EA", 2))
		return (3);
	if (!ft_strncmp(words[0], "WE", 2))
		return (4);
	if (!ft_strncmp(words[0], "S", 1))
		return (5);
	return (12);
}

uint8_t
ft_select_get(char **words, t_cub *clist)
{
	int		(*fun_ptr[7])(char**, t_cub*);
	uint8_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_colors;
	if ((id = ft_get_id(words)) == 12)
	{
		ft_free_words(words);
		return (12);
	}
	if ((*fun_ptr[id])(words, clist) < 0)
	{
		ft_free_words(words);
		return (ft_map_error(clist));
	}
	ft_free_words(words);
	return (id);
}