//  DescriptionHere - game.h
//  Created by John Ryland (jryland@xiaofrog.com), 29/10/2017
//  Copyright (c) 2017 InvertedLogic
//  All rights reserved.
#pragma once
#include "board.h"
#include "gameDB.h"

struct BoardEvent
{
  enum BoardEventType
  {
    None = 0,
    Removed = 1,
    Added = 2,
    Moved = 3,
    Swapped = 4,
    NoMoreMoves = 5,
    ScoredPoints = 6,
  };

  BoardEventType type;
  int itemIndex;
  int newItemIndex;
  int x, y;
  int newX, newY; // for moved
  int delay;
  int value;
  int points;

  bool userInit;
  int frame;
  int frames;
};

struct Tile
{
  TileTypeID tileTypeId;  // index to look up tiletype (for now it is just used as the sprite index in sprite sheet)
  int  x, y;              // current position on the board
  int  newX, newY;        // position to animate towards

  BoardEvent::BoardEventType type; // determines the way it might animate
  // user data for the animation
  bool userInit;
  int frame;
  int frames;
};

struct Game
{
  inline int width() { return m_board.m_width; }
  inline int height() { return m_board.m_height; }
  GameDB  m_gameDB;
  float   m_time;
  int     m_score;
  int     m_tileTypes;
  Board   m_board;
  std::vector<BoardEvent> m_events;
  std::vector<Tile> m_tiles;  // this is really the things in the tiles. need a better name for this.
  std::vector<int> m_boardTileMap;
};

struct Input
{
  // a mouse drag from startTile to endTile - eg: swapping to tiles
  int startTileX, startTileY;
  int endTileX, endTileY;
};

bool createNewGame(Game& a_game, int a_width, int a_height, int a_numTileTypes);
void destroyGame(Game& a_game);
bool processInput(Game& a_game, const Input& a_input);
void updateTiles(Game& a_game);
bool checkForMoreMatches(Game& a_game);

// Swap the tiles
bool swapTiles(Game& a_game, int x1, int y1, int x2, int y2);

// TODO:
//  Need something to input moves
//  Then callbacks or from a given input then step by frames the animation of items
//  Then need to get an enumeration of the items and positions and state etc for rendering
//  Also need to give a game state and score etc - has finished, no moves left, time over etc
//  Boosters, lives

