#pragma once
#include "image/sprite.hpp"
//! хранилище для спрайтов
class BankSprite {
protected:
  Sprite* pSprite = nullptr;
  index_t MAX = 0;
public:
  BankSprite() = default;
  BankSprite(const BankSprite&) = delete;
  BankSprite& operator=(const BankSprite&) = delete;
  explicit constexpr BankSprite(index_t size) { init(size); }
  ~BankSprite() { free(); }
  void init(index_t size);
  void free();
  Sprite& operator[](index_t i);
  const Sprite& operator[](index_t i) const;
};
void BankSprite::init(index_t size) {
  free();
  MAX = size;
  pSprite = new Sprite[MAX];
}
void BankSprite::free() {
  zdelete_arr(pSprite);
  MAX = 0;
}
Sprite& BankSprite::operator[](index_t i) {
  #ifdef DEBUG
  IFERROR( !pSprite, "BankSprite[] -> data is null");
  if (i >= MAX)
    a83::error("BankSprite[] -> index overflow. Index(" + a83::n2s(i) + ")");
  #endif
  return pSprite[i];
}
const Sprite& BankSprite::operator[](index_t i) const {
  #ifdef DEBUG
  IFERROR( !pSprite, "BankSprite[] const -> data is null");
  if (i >= MAX)
    a83::error("BankSprite[] const -> index overflow. Index("+ a83::n2s(i) + ")");
  #endif
  return pSprite[i];
}