fix: map parsing error

This commit is contained in:
mcolonna 2024-10-17 17:59:41 +02:00
parent 88c3d128fd
commit aaf2b0adc8
2 changed files with 9 additions and 11 deletions

View file

@ -6,7 +6,7 @@
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/03 15:05:13 by mc #+# #+# */
/* Updated: 2024/10/15 17:23:40 by mcolonna ### ########.fr */
/* Updated: 2024/10/17 17:58:23 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -43,11 +43,6 @@ bool read_color_parameter(const char *name, t_color *dest,
bool read_string_parameter(const char *name, const char **dest,
t_stream *stream, bool *redefined);
/// @brief Set the map to initial values. Every texture becomes NULL
/// and every color becomes 0xFF000000.
/// @param dest Map to reset.
void reset_map(t_map *dest);
/// @brief Read a map-formatted string.
/// If an error occurs, write an error message on stderr.
/// @param dest Will be set to the map.

View file

@ -6,7 +6,7 @@
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/03 15:02:09 by mc #+# #+# */
/* Updated: 2024/10/17 16:09:31 by mcolonna ### ########.fr */
/* Updated: 2024/10/17 17:59:05 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -75,7 +75,7 @@ bool read_string_parameter(const char *name, const char **dest,
return (!err);
}
void reset_map(t_map *dest)
static void read_map2(t_map *dest, bool *err, bool *rdf)
{
dest->cases = NULL;
dest->color_ceiling = 0xFF000000;
@ -84,18 +84,20 @@ void reset_map(t_map *dest)
dest->texture_west = NULL;
dest->texture_north = NULL;
dest->texture_south = NULL;
*err = false;
*rdf = false;
}
bool read_map(t_map *dest, t_stream *stream)
{
bool err;
bool rdf;
int old_stream_i;
reset_map(dest);
err = false;
rdf = false;
read_map2(dest, &err, &rdf);
while (!rdf && !err && stream->str[stream->i])
{
old_stream_i = stream->i;
if ((read_expected_string("\n", stream, &err), err)
&& !read_string_parameter("NO", &dest->texture_north, stream, &rdf)
&& !read_string_parameter("SO", &dest->texture_south, stream, &rdf)
@ -104,6 +106,7 @@ bool read_map(t_map *dest, t_stream *stream)
&& !read_color_parameter("F", &dest->color_floor, stream, &rdf)
&& !read_color_parameter("C", &dest->color_ceiling, stream, &rdf))
{
stream->i = old_stream_i;
err = !read_map_description(dest, stream);
break ;
}