2023-10-26 16:57:23 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* :::::::: */
|
|
|
|
/* parse.c :+: :+: */
|
|
|
|
/* +:+ */
|
|
|
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
|
|
|
/* +#+ */
|
|
|
|
/* Created: 2023/10/26 16:48:55 by houtworm #+# #+# */
|
2023-10-27 20:07:11 +02:00
|
|
|
/* Updated: 2023/10/27 19:56:28 by djonker ######## odam.nl */
|
2023-10-26 16:57:23 +02:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "../cub3d.h"
|
2023-10-27 20:07:11 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int ft_settexture(t_varlist *vl, char *line)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("line: %s\n", line);
|
|
|
|
i = 0;
|
|
|
|
while (line[i] != '.')
|
|
|
|
i++;
|
|
|
|
if (ft_strncmp(line, "NO ", 3))
|
|
|
|
vl->northwt = ft_strdup(&line[i]);
|
|
|
|
if (ft_strncmp(line, "EA ", 3))
|
|
|
|
vl->eastwt = ft_strdup(&line[i]);
|
|
|
|
if (ft_strncmp(line, "SO ", 3))
|
|
|
|
vl->southwt = ft_strdup(&line[i]);
|
|
|
|
if (ft_strncmp(line, "WE ", 3))
|
|
|
|
vl->westwt = ft_strdup(&line[i]);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ft_setcolor(t_varlist *vl, char *line)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int r;
|
|
|
|
int g;
|
|
|
|
int b;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (line[i] < '0' || line[i] > '9')
|
|
|
|
i++;
|
|
|
|
r = ft_atoi(&line[i]);
|
|
|
|
while (line[i] >= '0' && line[i] <= '9')
|
|
|
|
i++;
|
|
|
|
while (line[i] < '0' || line[i] > '9')
|
|
|
|
i++;
|
|
|
|
g = ft_atoi(&line[i]);
|
|
|
|
while (line[i] >= '0' && line[i] <= '9')
|
|
|
|
i++;
|
|
|
|
while (line[i] < '0' || line[i] > '9')
|
|
|
|
i++;
|
|
|
|
b = ft_atoi(&line[i]);
|
|
|
|
if (line[0] == 'F')
|
|
|
|
vl->fcolor = (r << 24 | g << 16 | b << 8 | 255);
|
|
|
|
if (line[0] == 'C')
|
|
|
|
vl->ccolor = (r << 24 | g << 16 | b << 8 | 255);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ft_checkline(t_varlist *vl, char *line)
|
|
|
|
{
|
|
|
|
if ((line[0] == 'F' || line[0] == 'C') && line[1] == ' ')
|
|
|
|
ft_setcolor(vl, line);
|
|
|
|
else if ((!ft_strncmp(line, "NO ", 3) || !ft_strncmp(line, "EA ", 3) || !ft_strncmp(line, "SO ", 3) || !ft_strncmp(line, "WE ", 3)))
|
|
|
|
ft_settexture(vl, line);
|
|
|
|
return (0);
|
|
|
|
}
|
2023-10-26 16:57:23 +02:00
|
|
|
|
2023-10-26 17:40:01 +02:00
|
|
|
t_varlist ft_parseconfigfile(t_varlist vl, char *filename)
|
2023-10-26 16:57:23 +02:00
|
|
|
{
|
2023-10-26 17:40:01 +02:00
|
|
|
int fd;
|
|
|
|
char *line;
|
|
|
|
|
|
|
|
fd = open(filename, O_RDONLY);
|
|
|
|
if (fd == -1)
|
|
|
|
ft_errorexit("file does not exist", "parseconfigfile", 1);
|
|
|
|
while (get_next_line(fd, &line))
|
2023-10-26 16:57:23 +02:00
|
|
|
{
|
2023-10-27 20:07:11 +02:00
|
|
|
ft_checkline(&vl, line);
|
2023-10-26 17:40:01 +02:00
|
|
|
free(line);
|
2023-10-26 16:57:23 +02:00
|
|
|
}
|
2023-10-27 20:07:11 +02:00
|
|
|
free(line);
|
2023-10-27 15:18:02 +02:00
|
|
|
vl.map = ft_getmap();
|
2023-10-26 17:40:01 +02:00
|
|
|
return (vl);
|
2023-10-26 16:57:23 +02:00
|
|
|
}
|