Textures files created
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/25 19:47:02 by aortigos #+# #+# */
|
||||
/* Updated: 2025/12/04 10:34:18 by aortigos ### ########.fr */
|
||||
/* Updated: 2025/12/05 16:30:21 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -62,4 +62,19 @@ int check_dup(t_data *m);
|
||||
int check_first_last_line(char **map);
|
||||
int surrounded_by_one(char **map);
|
||||
|
||||
// textures.c
|
||||
int check_color_values(char **rgb);
|
||||
void ft_process_rgb_color(t_turelist *tmp, t_data *m);
|
||||
int color_ture(t_data *m, t_turelist *l_ture);
|
||||
int check_color_textures(char *line);
|
||||
int check_count_textures(t_data *m, int count);
|
||||
|
||||
// textures_utils.c
|
||||
int is_valid_texture(char *line);
|
||||
int count_comma(char *rgb);
|
||||
int check_pos_cf(char *l);
|
||||
int line_around_one(char *line);
|
||||
char *getlastline(char **map);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
70
src/parsing/textures.c
Normal file
70
src/parsing/textures.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* textures.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/05 15:42:28 by aortigos #+# #+# */
|
||||
/* Updated: 2025/12/05 16:06:21 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/cub3d.h"
|
||||
|
||||
int check_color_values(char **rgb)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
while (rgb[++i])
|
||||
if (ft_atoi(rgb[i]) > 255 || ft_atoi(rgb[i]) < 0)
|
||||
return (free2d(rgb), 0);
|
||||
return (free2d(rgb), 1);
|
||||
}
|
||||
|
||||
void ft_process_rgb_color(t_turelist *tmp, t_data *m)
|
||||
{
|
||||
if (!f_strncmp(tmp->name, "F", 2))
|
||||
m->ff = ft_split(tmp->value, ',');
|
||||
else if(!ft_strncmp(tmp->name, "C", 2))
|
||||
m->cc = ft_split(tmp->value, ',');
|
||||
return ;
|
||||
}
|
||||
|
||||
int color_ture(t_data *m, t_turelist *l_ture)
|
||||
{
|
||||
t_turelist *tmp;
|
||||
|
||||
m->cc = NULL;
|
||||
m->ff = NULL;
|
||||
tmp = l_ture;
|
||||
while (tmp)
|
||||
{
|
||||
if (!ft_strncmp(tmp->name, "F", 1) || !ft_strncmp(tmp->name, "C", 1))
|
||||
{
|
||||
if (!check_color_values(ft_split(tmp->value, ',')))
|
||||
return (ft_putstr_fd(ERR_MAP_RGB, 2), 0);
|
||||
ft_process_rgb_color(tmp, m);
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int check_color_textures(char *line)
|
||||
{
|
||||
while (ft_isspace(*line))
|
||||
line++;
|
||||
return ((!ft_strncmp(line, "EA", 2) || !ft_strncmp(line, "NO", 2)
|
||||
|| !ft_strncmp(line, "SO", 2) || !ft_strncmp(line, "WE", 2))
|
||||
|| (!ft_strncmp(line, "F", 1) || !ft_strncmp(line, "C", 1)));
|
||||
}
|
||||
|
||||
int check_count_textures(t_data *m, int count)
|
||||
{
|
||||
(void)m;
|
||||
if (count != 6)
|
||||
return (ft_putstr_fd(ERR_MAP_INV, 2), 0);
|
||||
return (1);
|
||||
}
|
||||
88
src/parsing/textures_utils.c
Normal file
88
src/parsing/textures_utils.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* textures_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/05 16:09:33 by aortigos #+# #+# */
|
||||
/* Updated: 2025/12/05 16:29:28 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../cub3d.h"
|
||||
|
||||
int is_valid_texture(char *line)
|
||||
{
|
||||
while (ft_isspace(*line))
|
||||
line++;
|
||||
if ((!ft_strncmp(line, "NO", 2) || !ft_strncmp(line, "SO", 2)
|
||||
|| !ft_strncmp(line, "WE", 2) || !ft_strncmp(line, "EA", 2))
|
||||
&& ft_isspace(line[2]))
|
||||
return (1);
|
||||
else if ((!ft_strncmp(line, "F", 1) || !ft_strncmp(line, "C", 1))
|
||||
&& ft_isspace(line[1]))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int count_comma(char *rgb)
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
|
||||
i = 0;
|
||||
count = 0;
|
||||
while (rgb[i])
|
||||
if (rgb[i++] == ',')
|
||||
count++;
|
||||
return (count);
|
||||
}
|
||||
|
||||
int check_pos_cf(char *l)
|
||||
{
|
||||
int i;
|
||||
int flag;
|
||||
|
||||
flag = 0;
|
||||
i = 0;
|
||||
while (ft_isspace(*l) || *l == 'C' || *l == 'F')
|
||||
{
|
||||
if (*l == 'C' || *l == 'F')
|
||||
flag++;
|
||||
l++;
|
||||
}
|
||||
if (flag != 1)
|
||||
return (0);
|
||||
if (!ft_isdigit(l[i]) || !ft_isdigit(l[(ft_strlen(l) - 1)]))
|
||||
return (0);
|
||||
while (l[i])
|
||||
{
|
||||
if ((!ft_isdigit(l[i]) && l[i] != ',') || (l[i] == ',' && l[i+1]
|
||||
&& l[i + 1] == ','))
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int line_around_one(char *line)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
while (line[++i])
|
||||
if (line[i] != '1' && line[i] != 32)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
char *getlastline(char **map)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (map[i + 1])
|
||||
i++;
|
||||
return (map[i]);
|
||||
}
|
||||
13
src/parsing/valid_map.c
Normal file
13
src/parsing/valid_map.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* valid_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/05 16:30:33 by aortigos #+# #+# */
|
||||
/* Updated: 2025/12/05 16:30:42 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/cub3d.h"
|
||||
Reference in New Issue
Block a user