15static bool is_find_element(
const char *element)
19 ft_eprintf(
"%s%s\n", ERR_PROMPT, EMSG_EMPTY_CUB);
25static int parse_element(
26 const char *element,
t_parse *parse, t_type_elem type,
t_game *game)
28 static t_parse_elem func[3] = {parse_tex, parse_fc, parse_map};
29 static const int bit[3] = {BIT_INIT_TEX, BIT_INIT_FC, BIT_INIT_MAP};
30 const int tex_bit = BIT_NORTH | BIT_WEST | BIT_EAST | BIT_SOUTH;
32 if (check_duplicate_info(parse->flag, bit[type], element) != EXIT_SUCCESS)
33 return (EXIT_FAILURE);
34 if (func[type](element, parse) != EXIT_SUCCESS)
36 if (check_for_not_matching_bit(parse->flag, tex_bit) != 0x00)
37 destroy_texture_image(game->mlx, game->texture, parse->flag);
38 if (is_hit_flag(parse->flag, BIT_INIT_MAP) ==
true)
39 free_double_pointer(game->map.data);
40 return (EXIT_FAILURE);
42 return (EXIT_SUCCESS);
45static int check_missing_cub_contents(
int flag)
48 const int success_bit = BIT_NORTH | BIT_WEST | BIT_EAST | BIT_SOUTH
49 | BIT_F | BIT_C | BIT_MAP;
50 const char *key[8] = {
"NO",
"WE",
"EA",
"SO",
"F",
"C", NULL,
"MAP"};
54 missing_bit = check_for_not_matching_bit(flag, success_bit);
55 if (missing_bit != 0x00)
59 while (bit <= BIT_MAP)
61 if (missing_bit & bit)
62 ft_eprintf(
"%s%s: %s\n", ERR_PROMPT, key[i], EMSG_ENTRY_MISS);
66 return (EXIT_FAILURE);
68 return (EXIT_SUCCESS);
74int parse_cubfile(
t_parse *parse,
t_game *game,
const char *element)
79 element = find_next_element(element);
80 if (is_find_element(element) ==
false)
81 return (EXIT_FAILURE);
82 while (element != NULL)
84 type = get_type_element(element);
85 if (type == ENUM_ELEMENT_ERR)
87 put_error_msg(element, EMSG_ENTRY_INVAL);
88 return (EXIT_FAILURE);
90 if (parse_element(element, parse, type, game) != EXIT_SUCCESS)
91 return (EXIT_FAILURE);
94 element = find_next_element(element);
96 if (check_missing_cub_contents(parse->flag) != EXIT_SUCCESS)
97 return (EXIT_FAILURE);
98 return (EXIT_SUCCESS);