gunkiss/src/Pudding.hpp

60 lines
2.0 KiB
C++
Raw Normal View History

2021-05-07 21:26:44 -04:00
#ifndef Pudding_h_
#define Pudding_h_
#include <string>
#include <iostream>
#include <memory>
#include <type_traits>
2021-05-07 21:26:44 -04:00
#include <filesystem>
#include <curl/curl.h>
#include "SDL.h"
2021-05-07 21:26:44 -04:00
#include "json/json.hpp"
#include "glm/vec2.hpp"
#include "Game.hpp"
#include "Sprite.hpp"
#include "Color.hpp"
#include "extension.hpp"
#include "Item.hpp"
2021-05-07 21:26:44 -04:00
class Pudding : public Game
2021-05-07 21:26:44 -04:00
{
private:
typedef Game super;
2021-05-07 21:26:44 -04:00
const std::string OPEN_FOOD_API_URL = "https://world.openfoodfacts.org/api/v0/product/";
const std::string NUTRONIX_API_URL = "https://trackapi.nutritionix.com/v2/search/item?upc=";
const std::string BARCODE_MONSTER_API_URL = "https://barcode.monster/api/";
const std::string BEST_BUY_API_URL_1 = "https://api.bestbuy.com/v1/products(upc=";
const std::string BEST_BUY_API_URL_2 = ")?format=json&apiKey=";
const std::string NUTRONIX_NOT_FOUND = "resource not found";
const std::string GIANTBOMB_API_URL = "https://www.giantbomb.com/api/release/?api_key=";
2021-05-07 21:26:44 -04:00
std::string current_barcode;
std::vector<Item> items;
2021-05-12 02:09:22 -04:00
int current_item_index;
2021-05-07 21:26:44 -04:00
void incorporate_open_food_api(Item&);
void incorporate_nutronix_api(Item&);
2021-05-11 23:51:33 -04:00
void incorporate_edamam_api(Item&);
void incorporate_best_buy_api(Item&);
void save_item_json(const nlohmann::json&, const Item&, const std::string&) const;
nlohmann::json json_from_url(const std::string&, const std::vector<std::string>& = {});
void curl_get_bytes(const std::string& url, std::vector<std::uint8_t>&, const std::vector<std::string>& = {});
static size_t curl_write_response(std::uint8_t*, size_t, size_t, std::vector<std::uint8_t>*);
std::shared_ptr<SDL_Texture> texture_from_image_url(const std::string&);
static void destroy_texture(SDL_Texture*);
public:
Pudding();
void respond(SDL_Event&);
void add_item(const std::string&);
2021-05-12 02:09:22 -04:00
void increment_item_index(int = 1);
Item& get_current_item();
2021-05-07 21:26:44 -04:00
void update();
virtual std::string get_class_name() const { return "Pudding"; }
2021-05-07 21:26:44 -04:00
};
#endif