2019-04-23 01:42:19 -04:00
|
|
|
#ifndef Node_h_
|
|
|
|
#define Node_h_
|
|
|
|
|
2020-09-04 23:10:39 -04:00
|
|
|
#include <string>
|
2019-04-23 01:42:19 -04:00
|
|
|
#include <iostream>
|
|
|
|
|
2020-08-06 18:54:50 -04:00
|
|
|
#include "glm/vec2.hpp"
|
2019-05-04 03:25:35 -04:00
|
|
|
#include "json/json.hpp"
|
2019-05-03 02:09:48 -04:00
|
|
|
#include "SDL.h"
|
|
|
|
|
2019-05-02 06:45:41 -04:00
|
|
|
#include "filesystem.hpp"
|
|
|
|
|
2021-06-24 17:40:30 -04:00
|
|
|
class Game;
|
2019-05-03 02:09:48 -04:00
|
|
|
struct Delegate;
|
2019-05-07 03:33:54 -04:00
|
|
|
struct Display;
|
2020-08-19 03:29:46 -04:00
|
|
|
struct Input;
|
2021-06-26 20:25:03 -04:00
|
|
|
class Box;
|
2020-09-11 18:01:27 -04:00
|
|
|
struct Audio;
|
2019-04-23 01:42:19 -04:00
|
|
|
|
2021-06-24 17:40:30 -04:00
|
|
|
class Node
|
2019-04-23 01:42:19 -04:00
|
|
|
{
|
|
|
|
|
2021-06-24 17:40:30 -04:00
|
|
|
public:
|
|
|
|
|
2020-07-13 00:53:12 -04:00
|
|
|
Node *parent;
|
2020-09-04 23:10:39 -04:00
|
|
|
SDL_Texture* canvas = nullptr;
|
2020-07-21 01:09:34 -04:00
|
|
|
bool active = true;
|
2019-04-23 01:42:19 -04:00
|
|
|
|
2019-05-02 06:45:41 -04:00
|
|
|
Node();
|
2020-07-21 01:09:34 -04:00
|
|
|
Node(Node*);
|
2020-07-13 00:53:12 -04:00
|
|
|
void set_parent(Node*);
|
2020-08-19 03:29:46 -04:00
|
|
|
virtual void reset() { deactivate(); }
|
|
|
|
virtual void activate() { active = true; }
|
|
|
|
virtual void deactivate() { active = false; }
|
2020-09-04 23:10:39 -04:00
|
|
|
void set_canvas(SDL_Texture*);
|
|
|
|
SDL_Texture* get_canvas();
|
2020-07-17 22:58:23 -04:00
|
|
|
bool is_active() const;
|
2021-06-24 17:40:30 -04:00
|
|
|
const nlohmann::json& get_configuration() const;
|
2019-05-04 03:25:35 -04:00
|
|
|
nlohmann::json& get_configuration();
|
2019-05-18 17:39:47 -04:00
|
|
|
Delegate& get_delegate();
|
2020-08-19 03:29:46 -04:00
|
|
|
const Display& get_display() const;
|
2020-08-09 16:32:32 -04:00
|
|
|
const SDL_Renderer* get_renderer() const;
|
2020-08-06 18:54:50 -04:00
|
|
|
SDL_Renderer* get_renderer();
|
2020-08-19 03:29:46 -04:00
|
|
|
const SDL_Window* get_window() const;
|
2020-08-06 18:54:50 -04:00
|
|
|
SDL_Window* get_window();
|
2020-08-19 03:29:46 -04:00
|
|
|
const Input& get_input() const;
|
|
|
|
Input& get_input();
|
2020-09-11 18:01:27 -04:00
|
|
|
Audio& get_audio();
|
2020-08-09 16:32:32 -04:00
|
|
|
const Game* get_root() const;
|
2020-08-19 03:29:46 -04:00
|
|
|
Box get_window_box();
|
|
|
|
void suppress_input();
|
2020-07-22 00:53:40 -04:00
|
|
|
void suppress_input_temporarily(int = 0);
|
2020-08-19 03:29:46 -04:00
|
|
|
void unsuppress_input();
|
2021-06-24 17:40:30 -04:00
|
|
|
void log(const std::string&) const;
|
|
|
|
void debug(const std::string&) const;
|
|
|
|
const std::string get_branch_as_string() const;
|
|
|
|
virtual std::string get_class_name() const { return "Node"; };
|
2020-07-13 00:53:12 -04:00
|
|
|
virtual ~Node();
|
2019-04-23 01:42:19 -04:00
|
|
|
|
2020-07-27 14:19:11 -04:00
|
|
|
template<typename T = Game>
|
|
|
|
T* get_root()
|
|
|
|
{
|
2020-09-04 23:10:39 -04:00
|
|
|
if (parent == nullptr)
|
2020-07-27 14:19:11 -04:00
|
|
|
{
|
|
|
|
return static_cast<T*>(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return parent->get_root<T>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-23 01:42:19 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|