From a6929e15e1fd48c5133e511134b2dcf332072a84 Mon Sep 17 00:00:00 2001
From: Maelys <maelysdumergue@gmail.com>
Date: Mon, 16 Sep 2024 15:09:07 +0200
Subject: [PATCH] sixty_percent

---
 Makefile                     |  2 +
 ea_texture.png               |  0
 includes/cub3d.h             |  5 +-
 includes/mess_err.h          |  7 ++-
 includes/parsing.h           | 42 ++++++++++------
 map.cub                      | 17 +++----
 no_texture.png               |  0
 so_texture.png               |  0
 src/cub3d.c                  | 25 +++++----
 src/parsing/check_id_text.c  | 98 ++++++++++++++++++++++++++++++++++++
 src/parsing/check_rgb.c      | 26 ++++++++++
 src/parsing/memo_parsing     | 14 +++++-
 src/parsing/principal_pars.c | 39 +++++++++++---
 src/utils/parse_utils.c      | 50 +++++++++++++++---
 we_texture.png               |  0
 15 files changed, 270 insertions(+), 55 deletions(-)
 create mode 100644 ea_texture.png
 create mode 100644 no_texture.png
 create mode 100644 so_texture.png
 create mode 100644 we_texture.png

diff --git a/Makefile b/Makefile
index 5676f07..978d505 100644
--- a/Makefile
+++ b/Makefile
@@ -20,6 +20,8 @@ SRCS = src/utils/mess_error.c \
 	   src/utils/parse_utils.c \
 	   src/parsing/check_map.c \
 	   src/parsing/check_arg.c \
+	   src/parsing/check_id_text.c \
+	   src/parsing/check_rgb.c \
 	   src/parsing/principal_pars.c \
 	   src/cub3d.c
 
diff --git a/ea_texture.png b/ea_texture.png
new file mode 100644
index 0000000..e69de29
diff --git a/includes/cub3d.h b/includes/cub3d.h
index 5b688b1..14d4b4c 100644
--- a/includes/cub3d.h
+++ b/includes/cub3d.h
@@ -6,14 +6,15 @@
 /*   By: madumerg <madumerg@42angouleme.fr>         +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/09/04 17:01:05 by madumerg          #+#    #+#             */
-/*   Updated: 2024/09/12 12:54:48 by madumerg         ###   ########.fr       */
+/*   Updated: 2024/09/15 20:43:25 by madumerg         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #ifndef CUB3D_H
 # define CUB3D_H
 
-# include "../libft/includes/libft.h"
+# include "libft.h"
+# include "ft_printf.h"
 # include "mess_err.h"
 # include <stdlib.h>
 # include <math.h>
diff --git a/includes/mess_err.h b/includes/mess_err.h
index 0ffd9a1..bb5bf2e 100644
--- a/includes/mess_err.h
+++ b/includes/mess_err.h
@@ -6,7 +6,7 @@
 /*   By: madumerg <madumerg@42angouleme.fr>         +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/09/04 21:59:56 by madumerg          #+#    #+#             */
-/*   Updated: 2024/09/11 14:18:39 by madumerg         ###   ########.fr       */
+/*   Updated: 2024/09/16 12:18:42 by madumerg         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -23,3 +23,8 @@
 #define WRONG_CHAR "Invalid character in the map"
 
 //for permission
+
+#define ERR_IMG "Problem with image"
+#define DUP_ACR "There is a duplicate acronym"
+#define DUP_IMG "There is a duplicate image"
+#define NOT_FOUND "Information searched is not complete"
diff --git a/includes/parsing.h b/includes/parsing.h
index 490f354..e83c17e 100644
--- a/includes/parsing.h
+++ b/includes/parsing.h
@@ -6,7 +6,7 @@
 /*   By: madumerg <madumerg@42angouleme.fr>         +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/09/12 12:49:16 by madumerg          #+#    #+#             */
-/*   Updated: 2024/09/12 16:58:29 by madumerg         ###   ########.fr       */
+/*   Updated: 2024/09/16 14:23:15 by madumerg         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -21,32 +21,46 @@ typedef struct s_coord
 
 typedef struct s_pars
 {
-	int	f_color;
-	int	c_color;
+	int		f_color;
+	int		c_color;
 	t_coord	coor;
+	char	*no_png;
+	char	*so_png;
+	char	*we_png;
+	char	*ea_png;
 }	t_pars;
 
 //check_arg.c
-int	check_err_arg(int ac, char **av);
-int	check_format_file(char *file);
+int		check_err_arg(int ac, char **av);
+int		check_format_file(char *file);
+
+//check_id_text.c
+int		check_texture(char *sign, char *path, t_pars *pars);
+int		detect_info(char **tab, t_pars *pars);
+int		check_dup_img(t_pars *pars);
 
 //check_map.c
-int	err_not_close(char after, char before, char down, char up);
-int	actual_char(char actual);
-int	check_map_close(char **map);
-int	count_player(char **map);
-int	check_char_map(char **map);
+int		err_not_close(char after, char before, char down, char up);
+int		actual_char(char actual);
+int		check_map_close(char **map);
+int		count_player(char **map);
+int		check_char_map(char **map);
+
+//check_rgb.c
+int		check_format_rgb(char **tab);
 
 //principal_pars.c
-int	verif_info_map(char *av);
-int	verif_all_map(char **map);
+int		verif_info_file(char *av, t_pars *pars);
+int		verif_all_map(char **map);
 char	**parse_map(char *map);
 
 //mess_error.c in utils
-int	err_mess(char *str);
+int		err_mess(char *str);
 
 //parse_utils.c
 char	**info_map(char **file);
 void	convert_white_s(char *str);
-int	verif_char(char c);
+int		verif_char(char c);
+int		count_tab(char **tab);
+int		space_line(char *line);
 #endif
diff --git a/map.cub b/map.cub
index ecf31f3..692671a 100644
--- a/map.cub
+++ b/map.cub
@@ -1,14 +1,9 @@
-NO ./path_to_the_north_texture
-
-SO ./path_to_the_south_texture
-
-WE ./path_to_the_west_texture
-
-EA ./path_to_the_east_texture
-
-
-F 220,100,0
-C 225,30,0
+NO ./no_texture.png
+SO ./so_texture.png
+WE ./we_texture.png
+EA ./ea_texture.png
+F	 220       ,      100,        0
+C								 225,		 30, 0
 
 11111
 1001S1  
diff --git a/no_texture.png b/no_texture.png
new file mode 100644
index 0000000..e69de29
diff --git a/so_texture.png b/so_texture.png
new file mode 100644
index 0000000..e69de29
diff --git a/src/cub3d.c b/src/cub3d.c
index 38e72ef..5c6a003 100644
--- a/src/cub3d.c
+++ b/src/cub3d.c
@@ -6,25 +6,24 @@
 /*   By: madumerg <madumerg@42angouleme.fr>         +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/09/04 16:58:27 by madumerg          #+#    #+#             */
-/*   Updated: 2024/09/12 16:56:30 by madumerg         ###   ########.fr       */
+/*   Updated: 2024/09/16 13:54:52 by madumerg         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "cub3d.h"
-#include "libft.h"
-#include "parsing.h"
 
 t_pars	init_pars(void)
 {
 	t_pars	new;
 
-	new = ft_calloc(sizeof(t_pars));
-	if (!new)
-		return (NULL);
-	new->f_color = 0;
-	new->c_color = 0;
-	new->coor->x = 0;
-	new->coor->y = 0
+	new.f_color = 0;
+	new.c_color = 0;
+	new.coor.x = 0;
+	new.coor.y = 0;
+	new.no_png = NULL;
+	new.so_png = NULL;
+	new.we_png = NULL;
+	new.ea_png = NULL;
 	return (new);
 }
 
@@ -32,10 +31,10 @@ int	main(int ac, char **av)
 {
 	t_pars	pars;
 
-	pars = init_pars(void);
+	pars = init_pars();
 	if (check_err_arg(ac, av) == 1)
 		return (1);
-	if (verif_info_map(av[1], &pars) == 1)
-		return (1);
+	if (verif_info_file(av[1], &pars) == 1)
+		printf("main\n");
 	return (0);
 }
diff --git a/src/parsing/check_id_text.c b/src/parsing/check_id_text.c
index e69de29..568c814 100644
--- a/src/parsing/check_id_text.c
+++ b/src/parsing/check_id_text.c
@@ -0,0 +1,98 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   check_id_text.c                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: madumerg <madumerg@42angouleme.fr>         +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/09/16 09:38:32 by madumerg          #+#    #+#             */
+/*   Updated: 2024/09/16 14:38:35 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)
+		return (check_texture(tab[0], tab[1], pars));
+	else if (ft_strcmp("SO", tab[0]) == 0 && count_tab(tab) == 2)
+		return (check_texture(tab[0], tab[1], pars));
+	else if (ft_strcmp("WE", tab[0]) == 0 && count_tab(tab) == 2)
+		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
+		return (err_mess(NOT_FOUND));
+	return (0);
+}
diff --git a/src/parsing/check_rgb.c b/src/parsing/check_rgb.c
index e69de29..2065b47 100644
--- a/src/parsing/check_rgb.c
+++ b/src/parsing/check_rgb.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   check_rgb.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: madumerg <madumerg@42angouleme.fr>         +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/09/16 09:36:07 by madumerg          #+#    #+#             */
+/*   Updated: 2024/09/16 14:59:30 by madumerg         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "cub3d.h"
+
+int	check_format_rgb(char **tab)
+{
+	int	i = 0;
+	while (tab[i])
+		printf(".%s.\n", tab[i++]);
+	return (0);
+}
+
+int	create_argb(int a, int r, int g, int b)
+{
+	return (a << 24 | r << 16 | g << 8 | b);
+}
diff --git a/src/parsing/memo_parsing b/src/parsing/memo_parsing
index b240277..0b9fe59 100644
--- a/src/parsing/memo_parsing
+++ b/src/parsing/memo_parsing
@@ -1,6 +1,18 @@
 	// convertir tt les whites spaces en simple espace sur les 6 1ere lignes
 
+	//check si .png
 	WARNIIIIIINNNNNNNNNNNNNGGG TESTER LES MALLOC A NULL
 
-	//faire struct de coor
+	//faire search player
 	utiliser la ft pour couleur
+
+
+	no so
+	no we
+	no ea
+
+	so we
+	so ea
+
+	we ea
+
diff --git a/src/parsing/principal_pars.c b/src/parsing/principal_pars.c
index 52a38eb..f8042f8 100644
--- a/src/parsing/principal_pars.c
+++ b/src/parsing/principal_pars.c
@@ -6,28 +6,53 @@
 /*   By: madumerg <madumerg@42angouleme.fr>         +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/09/12 12:44:52 by madumerg          #+#    #+#             */
-/*   Updated: 2024/09/12 16:49:20 by madumerg         ###   ########.fr       */
+/*   Updated: 2024/09/16 14:58:26 by madumerg         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "cub3d.h"
 
-int	check_info(char **l)
+int	all_data_verif(char **tab, t_pars *pars)
 {
-	
+	if (detect_info(tab, pars) == 1)
+		return (1);
+	return (0);
 }
 
-int	verif_info_map(char *av)
+int	check_info(char **l, t_pars *pars)
+{
+	char	**tab;
+	int		i;
+
+	i = 0;
+	tab = ft_calloc(sizeof(char *), 6);
+	if (!tab)
+		return (1);
+	while (l[i])
+	{
+		tab = ft_split(l[i], ' ');
+		if (all_data_verif(tab, pars) == 1)
+			return (1);
+		i++;
+	}
+	return (0);
+}
+
+int	verif_info_file(char *av, t_pars *pars)
 {
 	char	**map;
 	char	**f_part;
 
+	(void)pars;
 	map = parse_map(av);
 	f_part = info_map(map);
-	if (check_info(f_part) == 1)
-		return (1);
-	if (verif_all_map(map) == 1)
+	if (check_info(f_part, 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)
diff --git a/src/utils/parse_utils.c b/src/utils/parse_utils.c
index 6890f1c..3f173eb 100644
--- a/src/utils/parse_utils.c
+++ b/src/utils/parse_utils.c
@@ -6,27 +6,50 @@
 /*   By: madumerg <madumerg@42angouleme.fr>         +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/09/11 14:20:54 by madumerg          #+#    #+#             */
-/*   Updated: 2024/09/12 16:20:31 by madumerg         ###   ########.fr       */
+/*   Updated: 2024/09/16 14:55:36 by madumerg         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "cub3d.h"
 
+int	space_line(char *line)
+{
+	int	i;
+
+	i = 0;
+	convert_white_s(line);
+	while (line[i])
+	{
+		if (line[i] == ' ' || (line[i] >= 9 && line[i] <= 13))
+			i++;
+		else
+			break ;
+	}
+	if (line[i] != '\0')
+		return (1);
+	return (0);
+}
+
 char	**info_map(char **file)
 {
 	char	**f_part;
-	int	i;
-	int	j;
+	int		i;
+	int		j;
 
 	i = 0;
 	j = 0;
 	f_part = ft_calloc(6, sizeof(char *));
 	if (!f_part)
 		return (NULL);
-	while (i < 6)
+	while (i >= j)
 	{
-		f_part[j] = file[i];
-		j++;
+		if (j == 6)
+			break ;
+		if (space_line(file[i]) == 1)
+		{
+			f_part[j] = file[i];
+			j++;
+		}
 		i++;
 	}
 	return (f_part);
@@ -52,3 +75,18 @@ int	verif_char(char c)
 		return (1);
 	return (0);
 }
+
+int	count_tab(char **tab)
+{
+	int	i;
+	int	ct;
+
+	i = 0;
+	ct = 0;
+	while (tab[i])
+	{
+		i++;
+		ct++;
+	}
+	return (ct);
+}
diff --git a/we_texture.png b/we_texture.png
new file mode 100644
index 0000000..e69de29