From 719274d56e971b99f06b50b3138282675b62a64d Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 29 Jan 2018 21:15:40 -0500 Subject: Added sending of Pokédex seen and caught data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/main.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'source/main.c') diff --git a/source/main.c b/source/main.c index 2b4a02a..8b97e12 100644 --- a/source/main.c +++ b/source/main.c @@ -70,6 +70,11 @@ void fatalError(char *msg) exit(0); } +inline u32 getPokedexFlag(const u32* data, int i) +{ + return (data[i >> 5] >> (i & 31) & 1); +} + cJSON* getConfig() { FILE* fp = fopen("/gen3uploader.cfg", "r"); @@ -314,23 +319,38 @@ void* extractor(void* userdata) getMsgArr(pokedexCaught, 13); printf("Saw: "); + + cJSON* jSeen = cJSON_CreateArray(); for (int i=0; i<(13*32); i++) { - if (pokedexSeen[i >> 5] >> (i & 31) & 1) + if (getPokedexFlag(pokedexSeen, i)) { printf("#%d, ", i+1); + + if (!getPokedexFlag(pokedexCaught, i)) + { + cJSON_AddItemToArray(jSeen, cJSON_CreateNumber(i + 1)); + } } } + cJSON_AddItemToObject(root, "seen", jSeen); + printf("\nCaught: "); + + cJSON* jCaught = cJSON_CreateArray(); for (int i=0; i<(13*32); i++) { - if (pokedexCaught[i >> 5] >> (i & 31) & 1) + if (getPokedexFlag(pokedexCaught, i)) { printf("#%d, ", i+1); + + cJSON_AddItemToArray(jCaught, cJSON_CreateNumber(i + 1)); } } + cJSON_AddItemToObject(root, "caught", jCaught); + printf("\n"); sendMsg(1); -- cgit 1.4.1