-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_texture_elements_utils.c
100 lines (92 loc) · 2.85 KB
/
check_texture_elements_utils.c
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
99
100
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_texture_elements_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jaesjeon <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/03 11:56:55 by jaesjeon #+# #+# */
/* Updated: 2022/11/03 11:56:57 by jaesjeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include "ft_string.h"
char *get_filename_from_path(char *filename)
{
while (1)
{
if (ft_strchr(filename, '/') == NULL)
break ;
filename = ft_strchr(filename, '/') + 1;
}
return (filename);
}
unsigned char get_texture_elements_flag_bit(int element_identifier)
{
if (element_identifier == EA)
return (EA_TEXTURE);
else if (element_identifier == WE)
return (WE_TEXTURE);
else if (element_identifier == SO)
return (SO_TEXTURE);
else if (element_identifier == NO)
return (NO_TEXTURE);
else if (element_identifier == F)
return (FLOOR_COLOR);
else if (element_identifier == C)
return (CEILING_COLOR);
else
return (ERROR);
}
int get_texture_element_identifier(char *key)
{
if (ft_strcmp(key, "EA"))
return (EA);
else if (ft_strcmp(key, "WE"))
return (WE);
else if (ft_strcmp(key, "SO"))
return (SO);
else if (ft_strcmp(key, "NO"))
return (NO);
else if (ft_strcmp(key, "F"))
return (F);
else if (ft_strcmp(key, "C"))
return (C);
else
return (ERROR);
}
void seperate_by_key_value(char **pair, char *line)
{
char *start;
while (*line && (*line == ' ' || *line == '\t' || *line == '\n'))
line++;
start = line;
while (*line && (*line != ' ' && *line != '\t'))
line++;
pair[KEY] = ft_substr(start, line);
while (*line && (*line == ' ' || *line == '\t' || *line == '\n'))
line++;
start = line;
while (*line != '\0' && *line != '\n')
line++;
pair[VALUE] = ft_substr(start, line);
}
unsigned char get_color_value(char **rgb_str)
{
int color_value;
color_value = -1;
while (**rgb_str && **rgb_str != ',')
{
if (**rgb_str < '0' || **rgb_str > '9')
exit_with_err("floor, ceiling color value error", E_PERM);
if (color_value == -1)
color_value = 0;
color_value = color_value * 10 + (**rgb_str - '0');
if (color_value > 255)
exit_with_err("floor, ceiling color value error", E_PERM);
(*rgb_str)++;
}
if (color_value < 0)
exit_with_err("floor, ceiling color value error", E_PERM);
return ((unsigned char)color_value);
}