mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
Continued parser
This commit is contained in:
parent
5bc41d1a1f
commit
1d16d66d89
5 changed files with 78 additions and 18 deletions
|
|
@ -6,11 +6,12 @@
|
|||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
|
||||
/* Updated: 2025/06/06 13:12:28 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/06/06 17:43:26 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/libft.h"
|
||||
#include "../includes/cub3d_consts.h"
|
||||
#include "../mlx/mlx.h"
|
||||
#include "../includes/maputils.h"
|
||||
#include <stdbool.h>
|
||||
|
|
@ -61,7 +62,7 @@ int main(int argc, char **argv)
|
|||
t_mapdata map;
|
||||
|
||||
if (argc < 2)
|
||||
return (ft_printf("Error: Missing cub3d filename\n"), 1);
|
||||
return (ft_printf("Error: Missing cub3d file\n"), 1);
|
||||
if (!check_cubfile(argv[1], &map))
|
||||
return (ft_printf("Error: Wrong map file. Reason: %s\n", map.error), 1);
|
||||
mlx = mlx_init();
|
||||
|
|
|
|||
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map_checker.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
|
||||
/* Updated: 2025/06/06 17:55:56 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/maputils.h"
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
|
@ -6,33 +18,32 @@
|
|||
void print_mapdata(const t_mapdata *data)
|
||||
{
|
||||
ft_printf(BOLD CYAN "=== Map Data ===\n" RESET);
|
||||
ft_printf(BOLD "Filename: " RESET "%s\n", data->filename ? data->filename : "(null)");
|
||||
ft_printf(BOLD "NO Texture: " RESET "%s\n", data->NO_texture ? data->NO_texture : "(null)");
|
||||
ft_printf(BOLD "SO Texture: " RESET "%s\n", data->SO_texture ? data->SO_texture : "(null)");
|
||||
ft_printf(BOLD "WE Texture: " RESET "%s\n", data->WE_texture ? data->WE_texture : "(null)");
|
||||
ft_printf(BOLD "EA Texture: " RESET "%s\n", data->EA_texture ? data->EA_texture : "(null)");
|
||||
|
||||
ft_printf(BOLD "Filename: " RESET "%s\n", data->filename);
|
||||
ft_printf(BOLD "NO Texture: " RESET "%s\n", data->NO_texture);
|
||||
ft_printf(BOLD "SO Texture: " RESET "%s\n", data->SO_texture);
|
||||
ft_printf(BOLD "WE Texture: " RESET "%s\n", data->WE_texture);
|
||||
ft_printf(BOLD "EA Texture: " RESET "%s\n", data->EA_texture);
|
||||
ft_printf(BOLD "Validity: " RESET);
|
||||
if (data->isvalid)
|
||||
ft_printf(GREEN "VALID\n" RESET);
|
||||
else
|
||||
ft_printf(RED "INVALID\n" RESET);
|
||||
|
||||
if (!data->isvalid && data->error[0] != '\0')
|
||||
{
|
||||
ft_printf(BOLD RED "Error: " RESET "%s\n", data->error);
|
||||
}
|
||||
|
||||
ft_printf(CYAN "=================\n" RESET);
|
||||
}
|
||||
|
||||
bool set_textures(char *line, t_mapdata *map)
|
||||
{
|
||||
char **tab;
|
||||
int i;
|
||||
int i;
|
||||
|
||||
tab = ft_split(line, ' ');
|
||||
i = 0;
|
||||
if (tab[0][0] == '1')
|
||||
return (false);
|
||||
if (tab[0] && tab[1])
|
||||
{
|
||||
if (!ft_strncmp(tab[0], "NO", 3) || !ft_strncmp(tab[0], "no", 3))
|
||||
|
|
@ -57,8 +68,8 @@ bool add_textures(int fd, t_mapdata *map)
|
|||
line = get_next_line(fd);
|
||||
while (line)
|
||||
{
|
||||
//ft_printf("%s", line);
|
||||
set_textures(line, map);
|
||||
if (!set_textures(line, map))
|
||||
return (free(line), false);
|
||||
free(line);
|
||||
line = get_next_line(fd);
|
||||
}
|
||||
|
|
@ -68,9 +79,9 @@ bool add_textures(int fd, t_mapdata *map)
|
|||
|
||||
bool check_filename(char *file)
|
||||
{
|
||||
int filename_size;
|
||||
int i;
|
||||
int j;
|
||||
int filename_size;
|
||||
int i;
|
||||
int j;
|
||||
char end[5];
|
||||
|
||||
filename_size = ft_strlen(file);
|
||||
|
|
@ -98,7 +109,9 @@ bool check_cubfile(char *file, t_mapdata *map)
|
|||
fd = open(file, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return (ft_strlcpy(map->error, "Can't open file", 16), false);
|
||||
add_textures(fd, map);
|
||||
if (!add_textures(fd, map))
|
||||
return (close(fd), ft_strlcpy(map->error,
|
||||
"Map started before all the textures", 37), false);
|
||||
close(fd);
|
||||
return (true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue