/* * File: game.c * Author: Arthur Brandao * * Created on 28 novembre 2018 */ #include #include #include "file.h" #include "game.h" /* --- Extern --- */ Game game[MAXGAME]; int nbGame = 0; /* --- Fonctions publiques --- */ JsonArray* list_map(){ char** result; int nbResult; JsonArray* ja; //Initialisation json ja = malloc(sizeof(JsonArray)); ini_array_encoder(ja); //Regarde les fichiers dans le dossier result = file_list(MAPDIR, &nbResult); for(int i = 0; i < nbResult; i++){ add_array_string(ja, result[i]); free(result[i]); } return ja; } JsonArray* list_game(){ JsonArray* ja; //Si il n' y a aucune game if(nbGame == 0){ return NULL; } //Initialisation json ja = malloc(sizeof(JsonArray)); ini_array_encoder(ja); //Ajoute chaque game for(int i = 0; i < nbGame; i++){ //Creation objet json JsonEncoder je; ini_encoder(&je); add_string(&je, "name", game[i].name); add_integer(&je, "nbPlayer", game[i].nbPlayer); add_string(&je, "map", game[i].mapName); //Ajout dans le tableau add_array_object(ja, &je); //Suppr encoder objet clean_json_encoder(&je); } return ja; } /** * Associe une map à une game * @param Game* La game à associé à la map * @param char* Le nom de la map */ void get_map(Game*, char*);