6
6
/* By: mvpee <[email protected] > +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2024/04/25 11:08:42 by mvpee #+# #+# */
9
- /* Updated: 2024/07/02 20:39:41 by mvpee ### ########.fr */
9
+ /* Updated: 2024/07/02 21:25:21 by mvpee ### ########.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
@@ -64,29 +64,33 @@ static void get_texture(t_data *data, t_img **image, char *line)
64
64
ft_free (3 , & str , & line , & temp );
65
65
}
66
66
67
- static void get_color (int * color , char * line )
67
+ static bool get_color (int * color , char * line )
68
68
{
69
69
char * * split ;
70
70
int i ;
71
71
int array [3 ];
72
72
73
- ft_memset (array , 0 , 3 );
73
+ ft_memset (array , -1 , 3 );
74
74
i = -1 ;
75
75
split = ft_split (line , ", " );
76
+ if (!split )
77
+ return (true);
76
78
if (split )
77
79
{
78
- while (++ i < 3 && split [i ])
80
+ while (++ i < 3 && split [i ] && ft_strlen ( split [ i ]) < 4 )
79
81
{
80
82
array [i ] = ft_atoi (split [i ]);
81
- if (array [i ] < 0 )
82
- array [i ] = 0 ;
83
- if (array [i ] > 255 )
84
- array [i ] = 255 ;
83
+ if (array [i ] < 0 || array [i ] > 255 || array [i ] == -1 )
84
+ return (true);
85
85
}
86
+ if (i != 3 )
87
+ return (true);
86
88
ft_free_matrix (1 , & split );
87
89
}
88
90
ft_free (1 , & line );
89
91
* color = get_rgba (array [0 ], array [1 ], array [2 ], 255 );
92
+ * color = get_correct_color ((u_int8_t * )color );
93
+ return (false);
90
94
}
91
95
92
96
bool check_file (t_data * data )
@@ -107,11 +111,15 @@ bool check_file(t_data *data)
107
111
else if (!ft_strncmp (data -> file [i ], "DO " , 3 ))
108
112
get_texture (data , & data -> door_image , data -> file [i ]);
109
113
else if (!ft_strncmp (data -> file [i ], "F " , 2 ))
110
- get_color (& data -> floor_color , ft_substr (data -> file [i ], 2 ,
111
- ft_strlen (data -> file [i ]) - 3 ));
114
+ {
115
+ if (get_color (& data -> floor_color , ft_substr (data -> file [i ], 2 , ft_strlen (data -> file [i ]) - 3 )))
116
+ return (ft_printf_fd (2 , RED FLOOR_COLOR RESET ), true);
117
+ }
112
118
else if (!ft_strncmp (data -> file [i ], "C " , 2 ))
113
- get_color (& data -> ceiling_color , ft_substr (data -> file [i ], 2 ,
114
- ft_strlen (data -> file [i ]) - 3 ));
119
+ {
120
+ if (get_color (& data -> ceiling_color , ft_substr (data -> file [i ], 2 , ft_strlen (data -> file [i ]) - 3 )))
121
+ return (ft_printf_fd (2 , RED CEILING_COLOR RESET ), true);
122
+ }
115
123
else if (ft_strlen (data -> file [i ]) > 1 )
116
124
data -> map = ft_splitjoin (data -> map , data -> file [i ]);
117
125
}
0 commit comments