#ifndef TILEBASE_HPP
#define TILEBASE_HPP

#include "../render/textures.hpp"
#include <unordered_map>
#include <vector>
#include <array>

// Forward declarations
struct Chunk;
struct Layer;
struct Map;

struct Tile {
  ID id;
  ID spriteid;
  int animationframe;
  std::vector<int> inventory;
  Chunk* owner; // pointer instead of reference

  void Draw();
  void Update(float deltatime);
  Tile(ID Id, ID spriteId, Chunk* owner);
  Tile(); // default constructor (needed for containers)
};

struct Chunk {
  raylib::Vector2 position;
  Tile tiles[64]; // dynamic instead of fixed array
  Layer* owner;

  void Draw();

  Chunk(Layer* Owner);
  Chunk(); // default constructor
};

struct Vector2Hash {
  std::size_t operator()(const Vector2& v) const noexcept;
};

struct Vector2Eq {
  bool operator()(const Vector2& a, const Vector2& b) const noexcept;
};

struct Layer {
  std::unordered_map<Vector2, Chunk, Vector2Hash, Vector2Eq> chunks;
  ID id;
  bool DEBUG;
  Map* owner;

  void Draw();

  Layer(ID Id, Map* Owner);
  Layer(); // default constructor
};

struct Map {
  std::array<Layer, 4> layers; // ground/water/void/decoration
  int worldtime;
  bool DEBUG;

  Map();
  void Draw();
};

#endif // !TILEBASE_HPP

