「🚧」 test: testing things, might broke.
This commit is contained in:
@ -6,78 +6,12 @@
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/16 09:38:32 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/16 14:38:35 by madumerg ### ########.fr */
|
||||
/* Updated: 2024/09/28 17:06:14 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
|
||||
int check_dup_img(t_pars *pars)
|
||||
{
|
||||
if (!pars->no_png || !pars->so_png || !pars->we_png || !pars->ea_png)
|
||||
return (err_mess(NOT_FOUND));
|
||||
if (ft_strcmp(pars->no_png, pars->so_png) == 0 || \
|
||||
ft_strcmp(pars->no_png, pars->we_png) == 0 || \
|
||||
ft_strcmp(pars->no_png, pars->ea_png) == 0 || \
|
||||
ft_strcmp(pars->so_png, pars->we_png) == 0 || \
|
||||
ft_strcmp(pars->we_png, pars->ea_png) == 0)
|
||||
return (err_mess(DUP_IMG));
|
||||
return (0);
|
||||
}
|
||||
|
||||
int assign_img_two(char *sign, char *path, t_pars *pars)
|
||||
{
|
||||
if (ft_strcmp("WE", sign) == 0)
|
||||
{
|
||||
if (pars->we_png == NULL)
|
||||
pars->we_png = path;
|
||||
else
|
||||
return (err_mess(DUP_ACR));
|
||||
}
|
||||
else if (ft_strcmp("EA", sign) == 0)
|
||||
{
|
||||
if (pars->ea_png == NULL)
|
||||
pars->ea_png = path;
|
||||
else
|
||||
return (err_mess(DUP_ACR));
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int assign_img(char *sign, char *path, t_pars *pars)
|
||||
{
|
||||
if (ft_strcmp("NO", sign) == 0)
|
||||
{
|
||||
if (pars->no_png == NULL)
|
||||
pars->no_png = path;
|
||||
else
|
||||
return (err_mess(DUP_ACR));
|
||||
}
|
||||
else if (ft_strcmp("SO", sign) == 0)
|
||||
{
|
||||
if (pars->so_png == NULL)
|
||||
pars->so_png = path;
|
||||
else
|
||||
return (err_mess(DUP_ACR));
|
||||
}
|
||||
if (assign_img_two(sign, path, pars) == 1)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int check_texture(char *sign, char *path, t_pars *pars)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = -1;
|
||||
fd = open(path, O_RDONLY, 0644);
|
||||
if (fd < 0)
|
||||
return (err_mess(ERR_IMG));
|
||||
if (assign_img(sign, path, pars) == 1)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int detect_info(char **tab, t_pars *pars)
|
||||
{
|
||||
if (ft_strcmp("NO", tab[0]) == 0 && count_tab(tab) == 2)
|
||||
@ -88,10 +22,10 @@ int detect_info(char **tab, t_pars *pars)
|
||||
return (check_texture(tab[0], tab[1], pars));
|
||||
else if (ft_strcmp("EA", tab[0]) == 0 && count_tab(tab) == 2)
|
||||
return (check_texture(tab[0], tab[1], pars));
|
||||
else if (ft_strcmp("F", tab[0]) == 0)
|
||||
check_format_rgb(tab);
|
||||
else if (ft_strcmp("C", tab[0]) == 0)
|
||||
check_format_rgb(tab);
|
||||
else if (ft_strcmp("F", tab[0]) == 0 && count_tab(tab) == 2)
|
||||
return (check_format_rgb("F", tab, pars));
|
||||
else if (ft_strcmp("C", tab[0]) == 0 && count_tab(tab) == 2)
|
||||
return (check_format_rgb("C", tab, pars));
|
||||
else
|
||||
return (err_mess(NOT_FOUND));
|
||||
return (0);
|
||||
|
99
src/parsing/check_image.c
Normal file
99
src/parsing/check_image.c
Normal file
@ -0,0 +1,99 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_image.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/19 10:44:07 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/28 20:14:47 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
|
||||
int check_dup_img(t_pars *pars)
|
||||
{
|
||||
if (!pars->no_png || !pars->so_png || !pars->we_png || !pars->ea_png)
|
||||
return (err_mess(NOT_FOUND));
|
||||
if (ft_strcmp(pars->no_png, pars->so_png) == 0 || \
|
||||
ft_strcmp(pars->no_png, pars->we_png) == 0 || \
|
||||
ft_strcmp(pars->no_png, pars->ea_png) == 0 || \
|
||||
ft_strcmp(pars->so_png, pars->we_png) == 0 || \
|
||||
ft_strcmp(pars->we_png, pars->ea_png) == 0)
|
||||
return (err_mess(DUP_IMG));
|
||||
return (0);
|
||||
}
|
||||
|
||||
int assign_img_two(char *sign, char *path, t_pars *pars)
|
||||
{
|
||||
if (ft_strcmp("WE", sign) == 0)
|
||||
{
|
||||
if (pars->we_png == NULL)
|
||||
pars->we_png = path;
|
||||
else
|
||||
return (err_mess(DUP_ACR));
|
||||
}
|
||||
else if (ft_strcmp("EA", sign) == 0)
|
||||
{
|
||||
if (pars->ea_png == NULL)
|
||||
pars->ea_png = path;
|
||||
else
|
||||
return (err_mess(DUP_ACR));
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int assign_img(char *sign, char *path, t_pars *pars)
|
||||
{
|
||||
if (ft_strcmp("NO", sign) == 0)
|
||||
{
|
||||
if (pars->no_png == NULL)
|
||||
pars->no_png = path;
|
||||
else
|
||||
return (err_mess(DUP_ACR));
|
||||
}
|
||||
else if (ft_strcmp("SO", sign) == 0)
|
||||
{
|
||||
if (pars->so_png == NULL)
|
||||
pars->so_png = path;
|
||||
else
|
||||
return (err_mess(DUP_ACR));
|
||||
}
|
||||
if (assign_img_two(sign, path, pars) == 1)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int format_img(char *img)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = ft_strlen(img) - 1;
|
||||
if (img[len] == 'g' && img[len - 1] == 'n' && \
|
||||
img[len - 2] == 'p' && img[len - 3] == '.')
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int check_texture(char *sign, char *path, t_pars *pars)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = -1;
|
||||
fd = open(path, O_RDONLY, 0644);
|
||||
if (fd < 0)
|
||||
return (err_mess(ERR_IMG));
|
||||
if (format_img(path) == 1)
|
||||
{
|
||||
close(fd);
|
||||
return (err_mess(WRONG_F_IMG));
|
||||
}
|
||||
if (assign_img(sign, path, pars) == 1)
|
||||
{
|
||||
close(fd);
|
||||
return (1);
|
||||
}
|
||||
close(fd);
|
||||
return (0);
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/11 11:24:13 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/12 12:57:24 by madumerg ### ########.fr */
|
||||
/* Updated: 2024/09/28 15:48:38 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,13 +14,13 @@
|
||||
|
||||
int err_not_close(char after, char before, char down, char up)
|
||||
{
|
||||
if (after == ' ' || after == '\0')
|
||||
if (after == ' ' || after == '\0' || after == '\n')
|
||||
return (1);
|
||||
else if (before == ' ' || before == '\0')
|
||||
else if (before == ' ' || before == '\0' || before == '\n')
|
||||
return (1);
|
||||
else if (down == ' ' || down == '\0')
|
||||
else if (down == ' ' || down == '\0' || down == '\n')
|
||||
return (1);
|
||||
else if (up == ' ' || up == '\0')
|
||||
else if (up == ' ' || up == '\0' || up == '\n')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
@ -39,6 +39,8 @@ int check_map_close(char **map)
|
||||
int x;
|
||||
|
||||
y = 0;
|
||||
if (last_first_line(map) == 1)
|
||||
return (1);
|
||||
while (map[y])
|
||||
{
|
||||
x = 0;
|
||||
@ -56,31 +58,6 @@ int check_map_close(char **map)
|
||||
return (0);
|
||||
}
|
||||
|
||||
int count_player(char **map)
|
||||
{
|
||||
int y;
|
||||
int x;
|
||||
int cpt;
|
||||
|
||||
cpt = 0;
|
||||
y = 0;
|
||||
while (map[y])
|
||||
{
|
||||
x = 0;
|
||||
while (map[y][x])
|
||||
{
|
||||
if (map[y][x] == 'N' || map[y][x] == 'S' || \
|
||||
map[y][x] == 'E' || map[y][x] == 'W')
|
||||
cpt++;
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
if (cpt != 1)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int check_char_map(char **map)
|
||||
{
|
||||
int y;
|
||||
|
@ -6,21 +6,78 @@
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/16 09:36:07 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/16 14:59:30 by madumerg ### ########.fr */
|
||||
/* Updated: 2024/09/28 17:08:01 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
|
||||
int check_format_rgb(char **tab)
|
||||
int check_nb_color(char *r, char *g, char *b)
|
||||
{
|
||||
int i = 0;
|
||||
while (tab[i])
|
||||
printf(".%s.\n", tab[i++]);
|
||||
if (ft_strlen(r) > 3 || ft_strlen(g) > 3 || ft_strlen(b) > 3 || \
|
||||
ft_atoi(r) > 255 || ft_atoi(g) > 255 || ft_atoi(b) > 255)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int create_argb(int a, int r, int g, int b)
|
||||
int save_color(char *tab, t_pars *pars, int j)
|
||||
{
|
||||
return (a << 24 | r << 16 | g << 8 | b);
|
||||
char *r;
|
||||
char *g;
|
||||
char *b;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (tab[i] != ',')
|
||||
i++;
|
||||
r = ft_strndup_color(tab, 0, i);
|
||||
i += 1;
|
||||
j = i;
|
||||
while (tab[i] != ',')
|
||||
i++;
|
||||
g = ft_strndup_color(tab, j, i);
|
||||
i += 1;
|
||||
j = i;
|
||||
while (tab[i])
|
||||
i++;
|
||||
b = ft_strndup_color(tab, j, i);
|
||||
if (check_nb_color(r, g, b) == -1)
|
||||
return (-1);
|
||||
pars->color = create_argb(ft_atoi(r), ft_atoi(g), ft_atoi(b));
|
||||
return (0);
|
||||
}
|
||||
|
||||
int count_precise_char(char *str, char c)
|
||||
{
|
||||
int ct;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
ct = 0;
|
||||
while (str[i])
|
||||
{
|
||||
if (str[i] == c)
|
||||
ct++;
|
||||
i++;
|
||||
}
|
||||
if (ct != 2)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int check_format_rgb(char *sign, char **tab, t_pars *pars)
|
||||
{
|
||||
if (count_tab(tab) > 2)
|
||||
return (err_mess(NOT_FOUND));
|
||||
if (check_char_color(tab[1]) == 1)
|
||||
return (err_mess(INVALID_CHAR));
|
||||
if (count_precise_char(tab[1], ',') == 1)
|
||||
return (err_mess(WRONG_F_RGB));
|
||||
if (save_color(tab[1], pars, 0) == -1)
|
||||
return (err_mess(ERR_COLOR));
|
||||
if (ft_strcmp(sign, "F") == 0)
|
||||
pars->f_color = pars->color;
|
||||
else if (ft_strcmp(sign, "C") == 0)
|
||||
pars->c_color = pars->color;
|
||||
return (0);
|
||||
}
|
||||
|
69
src/parsing/color_utils.c
Normal file
69
src/parsing/color_utils.c
Normal file
@ -0,0 +1,69 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* color_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/18 19:44:37 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/28 17:32:06 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
|
||||
int check_dup_color(t_pars *pars)
|
||||
{
|
||||
if (pars->c_color < 0 || pars->f_color < 0)
|
||||
return (err_mess(NOT_FOUND));
|
||||
if (pars->c_color == pars->f_color)
|
||||
return (err_mess(DUP_COLOR));
|
||||
return (0);
|
||||
}
|
||||
|
||||
int create_argb(int r, int g, int b)
|
||||
{
|
||||
return (r << 16 | g << 8 | b);
|
||||
}
|
||||
|
||||
char *ft_strndup_color(char *src, int start, int end)
|
||||
{
|
||||
int size;
|
||||
char *dest;
|
||||
int i;
|
||||
|
||||
size = start;
|
||||
i = 0;
|
||||
dest = ft_calloc(sizeof(char), ft_strlen(src) + 1);
|
||||
if (dest == NULL)
|
||||
return (NULL);
|
||||
while (size < end)
|
||||
{
|
||||
dest[i] = src[size];
|
||||
size++;
|
||||
i++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
|
||||
int valid_char_color(char c)
|
||||
{
|
||||
if (c == ',' || (c >= '0' && c <= '9'))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int check_char_color(char *tab)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (tab[i])
|
||||
{
|
||||
if (valid_char_color(tab[i]) == 1)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
64
src/parsing/find_player.c
Normal file
64
src/parsing/find_player.c
Normal file
@ -0,0 +1,64 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* find_player.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/17 14:57:11 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/19 09:55:38 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
|
||||
int search_letter(char **map, int i, char l)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
y = 0;
|
||||
while (map[y])
|
||||
{
|
||||
x = 0;
|
||||
while (map[y][x])
|
||||
{
|
||||
if (map[y][x] == l)
|
||||
{
|
||||
if (i == 0)
|
||||
return (x);
|
||||
else if (i == 1)
|
||||
return (y);
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int count_player(char **map, t_pars *pars, int ct)
|
||||
{
|
||||
int y;
|
||||
int x;
|
||||
|
||||
y = 0;
|
||||
while (map[y])
|
||||
{
|
||||
x = 0;
|
||||
while (map[y][x])
|
||||
{
|
||||
if (map[y][x] == 'N' || map[y][x] == 'S' || \
|
||||
map[y][x] == 'E' || map[y][x] == 'W')
|
||||
{
|
||||
pars->l_player = map[y][x];
|
||||
ct++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
if (ct != 1)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
// convertir tt les whites spaces en simple espace sur les 6 1ere lignes
|
||||
|
||||
//check si .png
|
||||
WARNIIIIIINNNNNNNNNNNNNGGG TESTER LES MALLOC A NULL
|
||||
|
||||
//faire search player
|
||||
utiliser la ft pour couleur
|
||||
|
||||
|
||||
no so
|
||||
no we
|
||||
no ea
|
||||
|
||||
so we
|
||||
so ea
|
||||
|
||||
we ea
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/12 12:44:52 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/16 14:58:26 by madumerg ### ########.fr */
|
||||
/* Updated: 2024/09/28 20:40:30 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,7 +15,10 @@
|
||||
int all_data_verif(char **tab, t_pars *pars)
|
||||
{
|
||||
if (detect_info(tab, pars) == 1)
|
||||
{
|
||||
free_tab(tab);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -31,10 +34,13 @@ int check_info(char **l, t_pars *pars)
|
||||
while (l[i])
|
||||
{
|
||||
tab = ft_split(l[i], ' ');
|
||||
if (tab == NULL)
|
||||
return (1);
|
||||
if (all_data_verif(tab, pars) == 1)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
free_tab(tab);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -43,49 +49,67 @@ int verif_info_file(char *av, t_pars *pars)
|
||||
char **map;
|
||||
char **f_part;
|
||||
|
||||
(void)pars;
|
||||
map = parse_map(av);
|
||||
map = parse_file(av, 0, 1);
|
||||
if (map == NULL)
|
||||
return (err_mess(CRASH));
|
||||
f_part = info_map(map);
|
||||
if (check_info(f_part, pars) == 1)
|
||||
if (f_part == NULL)
|
||||
{
|
||||
free_tab(map);
|
||||
return (err_mess(CRASH));
|
||||
}
|
||||
if (check_info(f_part, pars) == 1 || check_dup_img(pars) == 1 || \
|
||||
check_dup_color(pars) == 1)
|
||||
{
|
||||
free_tab(map);
|
||||
return (1);
|
||||
}
|
||||
if (all_skip(map, pars) == 1)
|
||||
return (1);
|
||||
// if (check_dup_img(pars) == 1)
|
||||
// return (1);
|
||||
// if (verif_all_map(map) == 1)
|
||||
// return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int verif_all_map(char **map)
|
||||
int verif_all_map(char **map, t_pars *pars)
|
||||
{
|
||||
if (check_char_map(map) == 1)
|
||||
pars->map = alloc_map(map, longest_line(map));
|
||||
free_tab(map);
|
||||
if (pars->map == NULL)
|
||||
return (err_mess(CRASH));
|
||||
if (check_char_map(pars->map) == 1)
|
||||
return (err_mess(WRONG_CHAR));
|
||||
if (count_player(map) == 1)
|
||||
if (count_player(pars->map, pars, 0) == 1)
|
||||
return (err_mess(ERR_PLAYER));
|
||||
if (check_map_close(map) == 1)
|
||||
if (check_map_close(pars->map) == 1)
|
||||
return (err_mess(NOT_CLOSE));
|
||||
pars->coor.x = search_letter(pars->map, 0, pars->l_player);
|
||||
pars->coor.y = search_letter(pars->map, 1, pars->l_player);
|
||||
return (0);
|
||||
}
|
||||
|
||||
char **parse_map(char *map)
|
||||
char **parse_file(char *map, int ct, int i)
|
||||
{
|
||||
int fd;
|
||||
char **parse_map;
|
||||
char *save;
|
||||
char *join;
|
||||
|
||||
fd = open(map, O_RDONLY);
|
||||
save = get_next_line(fd);
|
||||
join = ft_calloc(1, 1);
|
||||
if (!join)
|
||||
if (fd < 0)
|
||||
return (NULL);
|
||||
while (save != NULL)
|
||||
ct = count_line_file(fd);
|
||||
fd = open(map, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return (NULL);
|
||||
parse_map = ft_calloc(sizeof(char *), ct + 1);
|
||||
if (!parse_map)
|
||||
{
|
||||
join = ft_strjoin(join, save);
|
||||
free(save);
|
||||
save = get_next_line(fd);
|
||||
close(fd);
|
||||
return (NULL);
|
||||
}
|
||||
parse_map = ft_split(join, '\n');
|
||||
free(join);
|
||||
close(fd);
|
||||
parse_map[0] = get_next_line(fd);
|
||||
while (i <= ct)
|
||||
{
|
||||
parse_map[i] = get_next_line(fd);
|
||||
i++;
|
||||
}
|
||||
close (fd);
|
||||
return (parse_map);
|
||||
}
|
||||
|
Reference in New Issue
Block a user