2021-05-07 21:26:44 -04:00
|
|
|
#ifndef Pudding_h_
|
|
|
|
#define Pudding_h_
|
|
|
|
|
2021-06-26 20:25:57 -04:00
|
|
|
#include <stdlib.h>
|
2021-05-07 21:26:44 -04:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
2021-06-24 17:53:58 -04:00
|
|
|
#include <memory>
|
2021-05-11 16:50:28 -04:00
|
|
|
#include <type_traits>
|
2021-05-07 21:26:44 -04:00
|
|
|
#include <filesystem>
|
2021-05-11 16:50:28 -04:00
|
|
|
#include <curl/curl.h>
|
|
|
|
#include "SDL.h"
|
2021-05-07 21:26:44 -04:00
|
|
|
#include "json/json.hpp"
|
|
|
|
#include "glm/vec2.hpp"
|
2021-06-26 20:25:57 -04:00
|
|
|
#include "opencv2/core.hpp"
|
|
|
|
#include "opencv2/videoio.hpp"
|
|
|
|
#include "opencv2/highgui.hpp"
|
2021-06-28 16:30:12 -04:00
|
|
|
#include "opencv2/imgproc.hpp"
|
2021-06-26 20:25:57 -04:00
|
|
|
#include "zbar.h"
|
2021-05-07 21:26:44 -04:00
|
|
|
#include "Game.hpp"
|
|
|
|
#include "Color.hpp"
|
|
|
|
#include "extension.hpp"
|
2021-05-11 16:50:28 -04:00
|
|
|
#include "Item.hpp"
|
2021-05-07 21:26:44 -04:00
|
|
|
|
2021-06-24 17:53:58 -04:00
|
|
|
class Pudding : public Game
|
2021-05-07 21:26:44 -04:00
|
|
|
{
|
|
|
|
|
2021-06-24 17:53:58 -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=";
|
2021-05-11 16:50:28 -04:00
|
|
|
const std::string BARCODE_MONSTER_API_URL = "https://barcode.monster/api/";
|
2021-06-24 17:53:58 -04:00
|
|
|
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=";
|
2021-05-11 16:50:28 -04:00
|
|
|
const std::string NUTRONIX_NOT_FOUND = "resource not found";
|
2021-06-24 17:53:58 -04:00
|
|
|
const std::string GIANTBOMB_API_URL = "https://www.giantbomb.com/api/release/?api_key=";
|
2021-06-28 16:30:12 -04:00
|
|
|
std::string current_barcode, previous_barcode, current_config_barcode, current_camera_barcode;
|
2021-05-11 16:50:28 -04:00
|
|
|
std::vector<Item> items;
|
2021-06-28 16:30:12 -04:00
|
|
|
int current_item_index = 0;
|
2021-06-26 20:25:57 -04:00
|
|
|
cv::VideoCapture capture;
|
|
|
|
cv::Mat capture_frame;
|
2021-06-28 16:30:12 -04:00
|
|
|
zbar::ImageScanner image_scanner;
|
2021-07-02 22:51:59 -04:00
|
|
|
GLuint vbo, world_program, video_capture_texture_id;
|
2021-05-07 21:26:44 -04:00
|
|
|
|
2021-07-02 22:51:59 -04:00
|
|
|
void load_gl_context();
|
2021-05-11 16:50:28 -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&);
|
2021-06-24 17:53:58 -04:00
|
|
|
void incorporate_best_buy_api(Item&);
|
|
|
|
void save_item_json(const nlohmann::json&, const Item&, const std::string&) const;
|
2021-05-11 16:50:28 -04:00
|
|
|
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>*);
|
2021-06-24 17:53:58 -04:00
|
|
|
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();
|
2021-06-24 17:53:58 -04:00
|
|
|
virtual std::string get_class_name() const { return "Pudding"; }
|
2021-05-07 21:26:44 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|