diff --git a/src/game/game.c b/src/game/game.c index 2d24ee7..5587840 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -20,13 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "game.h" -/* -public Map missionStatuses; - -public List mias; -public List targets; -public Map keys; -*/ +static void loadMetaInfo(void); void initGame(void) { @@ -36,6 +30,8 @@ void initGame(void) game.hearts = 10; game.timePlayed = 0; + + loadMetaInfo(); } void addRescuedMIA(char *name) @@ -85,6 +81,28 @@ void removeItem(char *name) { } +static void loadMetaInfo(void) +{ + cJSON *root; + char *text; + + text = readFile("data/meta/meta.json"); + + root = cJSON_Parse(text); + + game.totalKeys = cJSON_GetObjectItem(root, "totalKeys")->valueint; + game.totalTargets = cJSON_GetObjectItem(root, "totalTargets")->valueint; + game.totalMIAs = cJSON_GetObjectItem(root, "totalMIAs")->valueint; + game.totalHearts = cJSON_GetObjectItem(root, "totalHearts")->valueint; + game.totalCells = cJSON_GetObjectItem(root, "totalCells")->valueint; + + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Meta [keys=%d, targets=%d, mias=%d, hearts=%d, cells=%d]", game.totalKeys, game.totalTargets, game.totalMIAs, game.totalHearts, game.totalCells); + + cJSON_Delete(root); + + free(text); +} + void destroyGame(void) { } diff --git a/src/game/game.h b/src/game/game.h index bcaab26..5cfe87a 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -19,5 +19,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "../common.h" +#include "../json/cJSON.h" + +extern char *readFile(const char *filename); extern Game game; diff --git a/src/test/atlasTest.c b/src/test/atlasTest.c index f2f97d0..019a78e 100644 --- a/src/test/atlasTest.c +++ b/src/test/atlasTest.c @@ -28,6 +28,8 @@ static Texture *atlasTexture; void initAtlasTest(void) { + initGame(); + app.delegate.logic = &logic; app.delegate.draw = &draw; diff --git a/src/test/atlasTest.h b/src/test/atlasTest.h index 94d6067..13cb4c8 100644 --- a/src/test/atlasTest.h +++ b/src/test/atlasTest.h @@ -24,5 +24,6 @@ extern Atlas *getImageFromAtlas(char *filename); extern Texture *getTexture(const char *filename); extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center); extern void loadMapData(char *filename); +extern void initGame(void); extern App app;