|
|
@ -6,7 +6,7 @@ |
|
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
|
/* Created: 2022/05/21 19:22:50 by narnaud #+# #+# */ |
|
|
|
/* Updated: 2022/05/23 14:50:48 by narnaud ### ########.fr */ |
|
|
|
/* Updated: 2022/05/23 16:54:20 by narnaud ### ########.fr */ |
|
|
|
/* */ |
|
|
|
/* ************************************************************************** */ |
|
|
|
|
|
|
@ -19,42 +19,53 @@ void get_map_datas(t_env *env, char *line) |
|
|
|
int i; |
|
|
|
|
|
|
|
i = 0; |
|
|
|
lst_e = malloc(sizeof(*lst_e)); |
|
|
|
lst_e->next = NULL; |
|
|
|
map_y = malloc(ft_strlen(line) * sizeof(char)); |
|
|
|
map_y = malloc((ft_strlen(line)) * sizeof(char)); |
|
|
|
while (*line) |
|
|
|
{ |
|
|
|
if (!ft_isspace(*line)) |
|
|
|
{ |
|
|
|
if (*line == '\n') |
|
|
|
break ; |
|
|
|
else if (!ft_isspace(*line)) |
|
|
|
map_y[i] = *line; |
|
|
|
i++; |
|
|
|
} |
|
|
|
else |
|
|
|
map_y[i] = '0'; |
|
|
|
line++; |
|
|
|
i++; |
|
|
|
} |
|
|
|
map_y[i] = '\0'; |
|
|
|
env->deep++; |
|
|
|
if (!env->raw_map) |
|
|
|
env->raw_map = ft_slst_new(map_y); |
|
|
|
else |
|
|
|
{ |
|
|
|
lst_e->content = map_y; |
|
|
|
ft_slst_add_back(&(env->raw_map), lst_e); |
|
|
|
} |
|
|
|
lst_e = malloc(sizeof(*lst_e)); |
|
|
|
lst_e->next = NULL; |
|
|
|
lst_e->content = map_y; |
|
|
|
ft_slst_add_back(&(env->raw_map), lst_e); |
|
|
|
} |
|
|
|
|
|
|
|
int rgb_to_int(char *rgb) |
|
|
|
int rgb_to_int(char **rgb) |
|
|
|
{ |
|
|
|
int ret; |
|
|
|
int i; |
|
|
|
int c; |
|
|
|
char **colors; |
|
|
|
|
|
|
|
ret = 0; |
|
|
|
colors = ft_split(rgb, ','); |
|
|
|
rgb++; |
|
|
|
colors = ft_split(*rgb, ','); |
|
|
|
c = 0; |
|
|
|
i = 0; |
|
|
|
while (c < 3) |
|
|
|
{ |
|
|
|
ret |= ft_atoi(colors[c]) << (8 * (2 - c)); |
|
|
|
c++; |
|
|
|
if (colors[i]) |
|
|
|
{ |
|
|
|
ret |= ft_atoi(colors[i]) << (8 * (2 - c)); |
|
|
|
c++; |
|
|
|
i++; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ft_free_split(colors); |
|
|
|
rgb++; |
|
|
|
i = 0; |
|
|
|
colors = ft_split(*rgb, ','); |
|
|
|
} |
|
|
|
} |
|
|
|
ft_free_split(colors); |
|
|
|
return (ret); |
|
|
@ -64,23 +75,26 @@ void register_data(t_env *env, char *line) |
|
|
|
{ |
|
|
|
char **elem; |
|
|
|
|
|
|
|
if (*line && *line != '\n' && env->step > 5) |
|
|
|
{ |
|
|
|
get_map_datas(env, line); |
|
|
|
return ; |
|
|
|
} |
|
|
|
elem = ft_split(line, ' '); |
|
|
|
if (!elem[0] || !elem[1]) |
|
|
|
return ; |
|
|
|
if (!ft_strncmp(elem[0],"NO", 3)) |
|
|
|
env->wallTexture[0] = ft_strdup(elem[1]); |
|
|
|
env->wallTexture[0] = ft_strtrim(elem[1], "\n"); |
|
|
|
else if (!ft_strncmp(elem[0],"SO", 3)) |
|
|
|
env->wallTexture[1] = ft_strdup(elem[1]); |
|
|
|
env->wallTexture[1] = ft_strtrim(elem[1], "\n"); |
|
|
|
else if (!ft_strncmp(elem[0],"WE", 3)) |
|
|
|
env->wallTexture[2] = ft_strdup(elem[1]); |
|
|
|
env->wallTexture[2] = ft_strtrim(elem[1], "\n"); |
|
|
|
else if (!ft_strncmp(elem[0],"EA", 3)) |
|
|
|
env->wallTexture[3] = ft_strdup(elem[1]); |
|
|
|
env->wallTexture[3] = ft_strtrim(elem[1], "\n"); |
|
|
|
else if (!ft_strncmp(elem[0],"F", 2)) |
|
|
|
env->floorColor = rgb_to_int(elem[1]); |
|
|
|
env->floorColor = rgb_to_int(elem); |
|
|
|
else if (!ft_strncmp(elem[0],"C", 2)) |
|
|
|
env->ceilColor = rgb_to_int(elem[1]); |
|
|
|
else if (env->step > 5) |
|
|
|
get_map_datas(env, line); |
|
|
|
env->ceilColor = rgb_to_int(elem); |
|
|
|
else |
|
|
|
env->step--; |
|
|
|
env->step++; |
|
|
@ -101,14 +115,14 @@ t_env *parse_envFile(char *filename) |
|
|
|
line = get_next_line(fd); |
|
|
|
while (line) |
|
|
|
{ |
|
|
|
register_data(ret, line); |
|
|
|
printf("%s", line); |
|
|
|
register_data(ret, line); |
|
|
|
free(line); |
|
|
|
line = get_next_line(fd); |
|
|
|
} |
|
|
|
if (ret->step < 7) |
|
|
|
if (ret->step < 6) |
|
|
|
return (NULL); |
|
|
|
printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n"); |
|
|
|
printf("\n*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n"); |
|
|
|
printf("%s\n", ret->wallTexture[0]); |
|
|
|
printf("%s\n", ret->wallTexture[1]); |
|
|
|
printf("%s\n", ret->wallTexture[2]); |
|
|
|