github to gitea
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_colors.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/25 18:41:26 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/10/07 10:06:32 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "cub.h"
|
||||
|
||||
int check_colors(t_textures *texture)
|
||||
{
|
||||
if (is_rgb(texture->floor))
|
||||
return (ft_error(ERROR_COL), 1);
|
||||
if (is_rgb(texture->ceiling))
|
||||
return (ft_error(ERROR_COL), 1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int is_rgb(int color[3])
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 3)
|
||||
{
|
||||
if (color[i] > 255 || color[i] < 0)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_file.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/22 15:07:29 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/10/07 10:11:50 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub.h"
|
||||
|
||||
int check_file(char *map_path, t_data_parsing *parsing)
|
||||
{
|
||||
if (!map_path)
|
||||
return (ft_error(ERROR_EMPT_PATH), 1);
|
||||
if (check_extension(map_path))
|
||||
return (1);
|
||||
parsing->fd_map = open(map_path, O_RDONLY);
|
||||
if (parsing->fd_map < 0)
|
||||
return (perror("Error\n"), 1);
|
||||
parsing->fd_map_dup = open(map_path, O_RDONLY);
|
||||
if (parsing->fd_map_dup < 0)
|
||||
return (perror("Error\n"), 1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int check_extension(char *map_path)
|
||||
{
|
||||
int len_map_path;
|
||||
|
||||
len_map_path = ft_strlen(map_path);
|
||||
if (len_map_path < 4)
|
||||
return (ft_error(ERROR_EXT), 1);
|
||||
if (ft_strcmp(map_path + len_map_path - 4, ".cub") != 0)
|
||||
return (ft_error(ERROR_EXT), 1);
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/22 15:07:29 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/10/07 10:11:50 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "cub.h"
|
||||
|
||||
int check_char_and_count(char c, int *p)
|
||||
{
|
||||
if (c == '1' || c == '0' || c == ' ' || c == '\n')
|
||||
return (0);
|
||||
else if (c == 'S' || c == 'N' || c == 'E' || c == 'W')
|
||||
{
|
||||
(*p)++;
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
return (2);
|
||||
}
|
||||
|
||||
int check_map_char(char **map)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int p;
|
||||
int ret;
|
||||
|
||||
i = 0;
|
||||
p = 0;
|
||||
while (map[i])
|
||||
{
|
||||
j = 0;
|
||||
while (map[i][j])
|
||||
{
|
||||
ret = check_char_and_count(map[i][j], &p);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (p != 1)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void find_player_pos(char **map, int *player)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
while (map[i])
|
||||
{
|
||||
j = 0;
|
||||
while (map[i][j])
|
||||
{
|
||||
if (map[i][j] == 'S' || map[i][j] == 'N' ||
|
||||
map[i][j] == 'E' || map[i][j] == 'W')
|
||||
{
|
||||
player[0] = j;
|
||||
player[1] = i;
|
||||
player[2] = map[i][j];
|
||||
return ;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int flood_fill(char **map_cp, int x, int y)
|
||||
{
|
||||
if (!map_cp || y < 0 || x < 0 || !map_cp[y] || !map_cp[y][x])
|
||||
return (1);
|
||||
if (map_cp[y][x] == 'v')
|
||||
return (0);
|
||||
if (map_cp[y][x] == '1')
|
||||
{
|
||||
map_cp[y][x] = 'v';
|
||||
return (0);
|
||||
}
|
||||
if (map_cp[y][x] == '0' || map_cp[y][x] == 'N' || map_cp[y][x] == 'S'
|
||||
|| map_cp[y][x] == 'E' || map_cp[y][x] == 'W')
|
||||
{
|
||||
map_cp[y][x] = 'v';
|
||||
if (flood_fill(map_cp, x + 1, y))
|
||||
return (1);
|
||||
if (flood_fill(map_cp, x - 1, y))
|
||||
return (1);
|
||||
if (flood_fill(map_cp, x, y + 1))
|
||||
return (1);
|
||||
if (flood_fill(map_cp, x, y - 1))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int rep_ex_wall(char **map_cp, int x, int y)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
if (y < 0 || x < 0)
|
||||
return (0);
|
||||
if (!map_cp[y])
|
||||
return (0);
|
||||
len = ft_strlen(map_cp[y]);
|
||||
if (x >= (int)len)
|
||||
return (0);
|
||||
if (map_cp[y][x] == '1')
|
||||
map_cp[y][x] = 'v';
|
||||
if (map_cp[y][x] == 'v')
|
||||
{
|
||||
map_cp[y][x] = 'c';
|
||||
rep_ex_wall(map_cp, x + 1, y);
|
||||
rep_ex_wall(map_cp, x - 1, y);
|
||||
rep_ex_wall(map_cp, x, y + 1);
|
||||
rep_ex_wall(map_cp, x, y - 1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_map_2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/22 15:07:29 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/10/07 12:09:03 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "cub.h"
|
||||
|
||||
int hasinvalidchar(char **map)
|
||||
{
|
||||
int y;
|
||||
int x;
|
||||
|
||||
y = 0;
|
||||
while (map[y])
|
||||
{
|
||||
x = 0;
|
||||
while (map[y][x])
|
||||
{
|
||||
if (map[y][x] != 'c' && map[y][x] != ' ' && map[y][x] != ' '
|
||||
&& map[y][x] != '\n')
|
||||
return (1);
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int validate_map(char **map, int *player)
|
||||
{
|
||||
int result;
|
||||
char **map_cp;
|
||||
|
||||
map_cp = ft_arrcpy(map);
|
||||
result = check_map_char(map);
|
||||
if (result == 1)
|
||||
return (free_char_array(map_cp), ft_error(ERROR_PLAYER), 1);
|
||||
if (result == 2)
|
||||
return (free_char_array(map_cp), ft_error(ERROR_CHAR), 1);
|
||||
find_player_pos(map, player);
|
||||
if (flood_fill(map_cp, player[0], player[1]))
|
||||
return (free_char_array(map_cp), ft_error(ERROR_NOT_CLOSE), 1);
|
||||
rep_ex_wall(map_cp, player[0], player[1]);
|
||||
if (hasinvalidchar(map_cp))
|
||||
return (free_char_array(map_cp), ft_error(ERROR_CHAR), 1);
|
||||
free_char_array(map_cp);
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/23 13:29:28 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/10/07 10:13:07 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub.h"
|
||||
|
||||
int get_map(t_data *data)
|
||||
{
|
||||
int nb_line;
|
||||
|
||||
nb_line = line_counter(data->parsing.fd_map);
|
||||
if (nb_line <= 0)
|
||||
return (ft_error(ERROR_EMPTY), 1);
|
||||
data->parsing.raw_map = ft_calloc(nb_line + 1, sizeof(char *));
|
||||
if (put_map_on_array(data))
|
||||
{
|
||||
free_char_array(data->parsing.raw_map);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int line_counter(int fd)
|
||||
{
|
||||
int nb_line;
|
||||
char *line;
|
||||
|
||||
line = NULL;
|
||||
nb_line = 0;
|
||||
line = get_next_line(fd);
|
||||
while (line != NULL)
|
||||
{
|
||||
nb_line++;
|
||||
free(line);
|
||||
line = get_next_line(fd);
|
||||
}
|
||||
free(line);
|
||||
line = get_next_line(-1);
|
||||
while (line != NULL)
|
||||
{
|
||||
free(line);
|
||||
line = get_next_line(-1);
|
||||
}
|
||||
get_next_line(-2);
|
||||
return (nb_line);
|
||||
}
|
||||
|
||||
char *clean_line(char *raw_line)
|
||||
{
|
||||
char *cleaned;
|
||||
|
||||
if (!raw_line)
|
||||
return (NULL);
|
||||
cleaned = ft_strtrim(raw_line, " \t\n\r");
|
||||
return (cleaned);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_map_2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/22 15:07:29 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/10/07 10:11:50 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "cub.h"
|
||||
|
||||
static int process_config_line(char *line, t_data *data, int *j)
|
||||
{
|
||||
char *cleaned;
|
||||
|
||||
cleaned = clean_line(line);
|
||||
if (get_texture_path(cleaned, data->texture, j))
|
||||
{
|
||||
free(line);
|
||||
free(cleaned);
|
||||
return (1);
|
||||
}
|
||||
free(cleaned);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void flush_remaining_lines(int fd)
|
||||
{
|
||||
char *line;
|
||||
|
||||
line = get_next_line(fd);
|
||||
while (line != NULL)
|
||||
{
|
||||
free(line);
|
||||
line = get_next_line(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static int handle_line(char *line, t_data *data, int *i, int *j)
|
||||
{
|
||||
if (is_config_line(line))
|
||||
{
|
||||
if (process_config_line(line, data, j))
|
||||
{
|
||||
flush_remaining_lines(-1);
|
||||
return (1);
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
else if (is_empty_line(line) && *i == 0)
|
||||
free(line);
|
||||
else
|
||||
data->parsing.raw_map[(*i)++] = line;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int put_map_on_array(t_data *data)
|
||||
{
|
||||
char *line;
|
||||
int i;
|
||||
int j[6];
|
||||
|
||||
ft_memset(j, 0, sizeof(j));
|
||||
i = 0;
|
||||
line = get_next_line(data->parsing.fd_map_dup);
|
||||
while (line != NULL)
|
||||
{
|
||||
if (handle_line(line, data, &i, j))
|
||||
return (1);
|
||||
line = get_next_line(data->parsing.fd_map_dup);
|
||||
}
|
||||
data->parsing.raw_map[i] = NULL;
|
||||
get_next_line(-2);
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_textures.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/24 12:37:11 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/10/07 10:13:41 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "cub.h"
|
||||
|
||||
int get_texture_path(char *line, t_textures *texture, int *j)
|
||||
{
|
||||
if (check_extension_2(line) && !is_color_line(line))
|
||||
return (ft_error(ERROR_NOT_XMP), 1);
|
||||
else if (is_texture_line(line) == 1 && j[0]++ == 0)
|
||||
texture->north = ft_strtrim(line + 2, " \t\n\r");
|
||||
else if (is_texture_line(line) == 2 && j[1]++ == 0)
|
||||
texture->south = ft_strtrim(line + 2, " \t\n\r");
|
||||
else if (is_texture_line(line) == 3 && j[2]++ == 0)
|
||||
texture->west = ft_strtrim(line + 2, " \t\n\r");
|
||||
else if (is_texture_line(line) == 4 && j[3]++ == 0)
|
||||
texture->east = ft_strtrim(line + 2, " \t\n\r");
|
||||
else if (is_color_line(line) == 1 && j[4]++ == 0)
|
||||
get_rgb_values(line, texture->floor);
|
||||
else if (is_color_line(line) == 2 && j[5]++ == 0)
|
||||
get_rgb_values(line, texture->ceiling);
|
||||
else
|
||||
return (ft_error(ERROR_DOUBLE), 2);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int is_valid_number(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!str || !*str)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (str[i] == ' ' || str[i] == '\t')
|
||||
i++;
|
||||
if (!str[i] || !(str[i] >= '0' && str[i] <= '9'))
|
||||
return (0);
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
i++;
|
||||
while (str[i] == ' ' || str[i] == '\t')
|
||||
i++;
|
||||
if (str[i] != '\0')
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int validate_and_convert_rgb(char **parts, int rgb[3])
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
while (++i < 3)
|
||||
{
|
||||
if (!is_valid_number(parts[i]))
|
||||
return (free_char_array(parts), 1);
|
||||
rgb[i] = ft_atoi(parts[i]);
|
||||
if (rgb[i] < 0 || rgb[i] > 255)
|
||||
return (free_char_array(parts), 1);
|
||||
}
|
||||
return (free_char_array(parts), 0);
|
||||
}
|
||||
|
||||
int get_rgb_values(char *line, int rgb[3])
|
||||
{
|
||||
char *start;
|
||||
char **parts;
|
||||
int i;
|
||||
|
||||
if (!line || !rgb)
|
||||
return (1);
|
||||
start = ft_strchr(line, ' ');
|
||||
if (!start)
|
||||
return (1);
|
||||
parts = ft_split(start + 1, ',');
|
||||
if (!parts)
|
||||
return (1);
|
||||
i = 0;
|
||||
while (parts[i])
|
||||
i++;
|
||||
if (i != 3)
|
||||
return (free_char_array(parts), 1);
|
||||
return (validate_and_convert_rgb(parts, rgb));
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* init_parsing.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/23 13:33:00 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/10/07 10:14:37 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "cub.h"
|
||||
|
||||
int init_parsing(t_data_parsing *parsing)
|
||||
{
|
||||
if (!parsing)
|
||||
return (ft_error(ERROR_INIT_PARS), 1);
|
||||
parsing->fd_map = 0;
|
||||
parsing->raw_map = NULL;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int init_textures(t_textures *textures)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!textures)
|
||||
return (ft_error(ERROR_INIT_TEX), 1);
|
||||
textures->north = NULL;
|
||||
textures->south = NULL;
|
||||
textures->east = NULL;
|
||||
textures->west = NULL;
|
||||
i = 0;
|
||||
while (i < 3)
|
||||
{
|
||||
textures->floor[i] = -1;
|
||||
textures->ceiling[i] = -1;
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int free_textures(t_textures *textures)
|
||||
{
|
||||
if (!textures)
|
||||
return (0);
|
||||
if (textures->north)
|
||||
free(textures->north);
|
||||
if (textures->south)
|
||||
free(textures->south);
|
||||
if (textures->east)
|
||||
free(textures->east);
|
||||
if (textures->west)
|
||||
free(textures->west);
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* line_detect.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/24 11:58:39 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/10/08 14:05:47 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub.h"
|
||||
|
||||
int check_extension_2(char *str)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = strlen(str);
|
||||
if (len < 4)
|
||||
return (1);
|
||||
return (ft_strcmp(str + len - 4, ".xpm"));
|
||||
}
|
||||
|
||||
int is_config_line(char *line)
|
||||
{
|
||||
char *trimmed;
|
||||
int result;
|
||||
|
||||
result = 0;
|
||||
if (!line)
|
||||
return (0);
|
||||
trimmed = ft_strtrim(line, " \t\n\r");
|
||||
if (!trimmed)
|
||||
return (0);
|
||||
if (ft_strncmp(trimmed, "NO ", 3) == 0
|
||||
|| ft_strncmp(trimmed, "SO ", 3) == 0
|
||||
|| ft_strncmp(trimmed, "WE ", 3) == 0
|
||||
|| ft_strncmp(trimmed, "EA ", 3) == 0
|
||||
|| ft_strncmp(trimmed, "F ", 2) == 0
|
||||
|| ft_strncmp(trimmed, "C ", 2) == 0)
|
||||
result = 1;
|
||||
free(trimmed);
|
||||
return (result);
|
||||
}
|
||||
|
||||
int is_empty_line(char *line)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (!line)
|
||||
return (1);
|
||||
while (line[i])
|
||||
{
|
||||
if (line[i] != ' ' && line[i] != '\t'
|
||||
&& line[i] != '\n' && line[i] != '\r')
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int is_color_line(char *line)
|
||||
{
|
||||
char *trimmed;
|
||||
int result;
|
||||
|
||||
result = 0;
|
||||
if (!line)
|
||||
return (0);
|
||||
trimmed = ft_strtrim(line, " \t\n\r");
|
||||
if (!trimmed)
|
||||
return (0);
|
||||
if (ft_strncmp(trimmed, "F ", 2) == 0)
|
||||
result = 1;
|
||||
else if (ft_strncmp(trimmed, "C ", 2) == 0)
|
||||
result = 2;
|
||||
free(trimmed);
|
||||
return (result);
|
||||
}
|
||||
|
||||
int is_texture_line(char *line)
|
||||
{
|
||||
char *trimmed;
|
||||
int result;
|
||||
|
||||
result = 0;
|
||||
if (!line)
|
||||
return (0);
|
||||
trimmed = ft_strtrim(line, " \t\n\r");
|
||||
if (!trimmed)
|
||||
return (0);
|
||||
if (ft_strncmp(trimmed, "NO ", 3) == 0)
|
||||
result = 1;
|
||||
else if (ft_strncmp(trimmed, "SO ", 3) == 0)
|
||||
result = 2;
|
||||
else if (ft_strncmp(trimmed, "WE ", 3) == 0)
|
||||
result = 3;
|
||||
else if (ft_strncmp(trimmed, "EA ", 3) == 0)
|
||||
result = 4;
|
||||
free(trimmed);
|
||||
return (result);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/22 14:17:58 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/10/26 02:10:59 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "cub.h"
|
||||
|
||||
int check_xpm_file(char *filepath)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (!filepath)
|
||||
return (1);
|
||||
fd = open(filepath, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return (1);
|
||||
close(fd);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int check_texture_file(t_textures *texture)
|
||||
{
|
||||
if (check_xpm_file(texture->north))
|
||||
return (ft_error(ERR_I_N), 1);
|
||||
if (check_xpm_file(texture->south))
|
||||
return (ft_error(ERR_I_S), 1);
|
||||
if (check_xpm_file(texture->east))
|
||||
return (ft_error(ERR_I_E), 1);
|
||||
if (check_xpm_file(texture->west))
|
||||
return (ft_error(ERR_I_W), 1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int parsing(t_data *data)
|
||||
{
|
||||
if (check_file(data->map_path, &data->parsing) == 1)
|
||||
return (1);
|
||||
if (get_map(data))
|
||||
{
|
||||
close(data->parsing.fd_map);
|
||||
close(data->parsing.fd_map_dup);
|
||||
return (1);
|
||||
}
|
||||
close(data->parsing.fd_map);
|
||||
close(data->parsing.fd_map_dup);
|
||||
get_next_line(-2);
|
||||
if (check_colors(data->texture) == 1)
|
||||
return (free_char_array(data->parsing.raw_map), 1);
|
||||
if (check_texture_file(data->texture) == 1)
|
||||
return (free_char_array(data->parsing.raw_map), 1);
|
||||
if (validate_map(data->parsing.raw_map, data->parsing.player))
|
||||
return (free_char_array(data->parsing.raw_map), 1);
|
||||
data->map = data->parsing.raw_map;
|
||||
data->parsing.raw_map = NULL;
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user