#include #include #include #include #include #include #include "include/image.h" #include "include/main.h" #include "include/level_struct.h" typedef void (*fct_parcours_t)(xmlNodePtr); void afficher_noeud(xmlNodePtr noeud); void parcours_prefixe(xmlNodePtr noeud, fct_parcours_t f); void parcours_postfixe(xmlNodePtr noeud, fct_parcours_t f); int LoadLevel(char *file, struct level *lvl, SDL_Surface *screen, SDL_Rect *dest) { xmlDocPtr doc; xmlNodePtr racine; xmlKeepBlanksDefault(0); doc = xmlParseFile(file); if (doc == NULL) { fprintf(stderr, "Invalid XML\n"); return EXIT_FAILURE; } racine = xmlDocGetRootElement(doc); if (racine == NULL) { fprintf(stderr, "XML, like a virgin\n"); xmlFreeDoc(doc); return EXIT_FAILURE; } printf("root %s\n", racine->name); lvl->background = SDL_LoadBMP ("ressources/lvl/montagne.bmp"); if (lvl->background == NULL) { printf("Impossible de charger %s: %s\n", file, SDL_GetError ()); return 1; } parcours_postfixe(racine, afficher_noeud); lvl->screen = screen; lvl->rect.x = dest->x; lvl->rect.y = dest->y; lvl->rect.w = dest->w; lvl->rect.h = dest->h; xmlFreeDoc(doc); return 0; } void UpdateLevel(struct level *lvl, SDL_Rect *dest) { SDL_BlitSurface(lvl->background, dest, lvl->screen, dest); SDL_UpdateRect(lvl->screen, dest->x, dest->y, dest->w, dest->h); } void ModifLevel(struct level *lvl, int x, int y) { lvl->rect.x = x; lvl->rect.y = y; } void FreeLevel(struct level *lvl) { } void parcours_prefixe(xmlNodePtr noeud, fct_parcours_t f) { xmlNodePtr n; for (n = noeud; n != NULL; n = n->next) { f(n); if ((n->type == XML_ELEMENT_NODE) && (n->children != NULL)) { parcours_prefixe(n->children, f); } } } void parcours_postfixe(xmlNodePtr noeud, fct_parcours_t f) { xmlNodePtr n; for (n = noeud; n != NULL; n = n->next) { if ((n->type == XML_ELEMENT_NODE) && (n->children != NULL)) { parcours_postfixe(n->children, f); } f(n); } } void afficher_noeud(xmlNodePtr noeud) { if (noeud->type == XML_ELEMENT_NODE) { xmlChar *chemin = xmlGetNodePath(noeud); if (noeud->children != NULL && noeud->children->type == XML_TEXT_NODE) { xmlChar *contenu = xmlNodeGetContent(noeud); printf("%s -> %s\n", chemin, contenu); xmlFree(contenu); } else { printf("%s\n", chemin); } xmlFree(chemin); } }