89 lines
2.5 KiB
C
89 lines
2.5 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* :::::::: */
|
|
/* parse.c :+: :+: */
|
|
/* +:+ */
|
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
|
/* +#+ */
|
|
/* Created: 2023/10/26 16:48:55 by houtworm #+# #+# */
|
|
/* Updated: 2023/10/27 19:56:28 by djonker ######## odam.nl */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "../cub3d.h"
|
|
#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);
|
|
}
|
|
|
|
t_varlist ft_parseconfigfile(t_varlist vl, char *filename)
|
|
{
|
|
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))
|
|
{
|
|
ft_checkline(&vl, line);
|
|
free(line);
|
|
}
|
|
free(line);
|
|
vl.map = ft_getmap();
|
|
return (vl);
|
|
}
|