#ifndef GAME_HPP
#define GAME_HPP

#include "config.h"

#include "module.hpp"
#include "options.hpp"
#include "config.hpp"

#include <stack>
#include <vector>
#include <list>

class Game : public Module 
{
private:
  Game();

  // commands
  void enter_dir();
  void go_back();
  void action_play();
  void options();
  void search_func();
  void exit();
  
  bool exit_loop;

  bool search_compare(const Entry& s);
  std::string get_name_from_file(const Entry& e);

  void print(const std::vector<Entry>& files);
  void print_game_element(const Entry& r, const Entry& position, int y);

#ifdef use_graphical_game
  std::string get_cover(const std::string& s);
  void graphical_print(const std::vector<Entry>& files);
#endif

  // playback
  void playgame(const Entry file);
#ifdef use_media
  void showcd(int count);
  void playpsx();
#endif

#ifdef use_media
  // dir
  std::string testdir(int *count);
#endif

  Entry addfile(const std::string& name, const MyPair& filetype);
  Entry add_dir(const std::string& filename);

  std::vector<Entry> rdir(const std::string& argv);
  std::vector<Entry> parse_dir(const std::list<std::string>& dirs);

  // for saving information about how you traverse a filesystem a stack is a
  // much better solution. The first element is the dirs and the next is the
  // position
  std::stack<std::pair<std::list<std::string>, int > > folders;

  std::vector<Entry> files;

#ifdef use_graphical_game
  int image_width;
  int image_height;
  int image_height_all_eks_text;

  // including text and space around image
  int image_width_all;
  int image_height_all;
  int image_height_all_search;

  int images_per_row;
  int rows;
  int rows_search;

  int y_start;
  
#endif

  class GameOpts : public Options 
  {
  public:
    GameOpts();
    ~GameOpts();

    std::vector<Option*> values() 
    {
      return val;
    }

  private:
    void read_dirs();

    Option *reload_p;
  };

  struct file_sort
  {
    bool operator()(const Entry& lhs, const Entry& rhs);
  };

public:
  // singleton
  static Game& get_instance();

  int files_size() { return files.size(); }

  void reset();

  void load_current_dirs();
  void read_dirs();
  
#ifdef use_media
  void determine_media();
#endif

  std::string mainloop();

  GameOpts opts;
};

#endif
