#pragma once

#include "GameCore.h"
#include <vector>

using namespace std;

typedef struct texture {
    LPDIRECT3DTEXTURE9 direct3dTexture;
    bool* mask;
} texture;

/*
typedef map<int, texture*> TextureMap;
typedef map<int, bool> TextureWalkableMap;
typedef map<int, bool>::iterator TextureWalkableMapIterator;
typedef map<int, texture*>::iterator TextureMapIterator;
typedef map<int, char*> MaskMap;
typedef map<int, char*>::iterator MaskMapIterator;
*/

typedef vector<texture*> TextureVector;
typedef vector<bool> TextureWalkableVector;
typedef vector<bool>::iterator TextureWalkableVectorIterator;
typedef vector<texture*>::iterator TextureVectorIterator;
typedef vector<char*> MaskVector;
typedef vector<char*>::iterator MaskVectorIterator;

class TextureManager
{
public:
	TextureManager();
	~TextureManager();

	// load textures from a file
	HRESULT loadTexturesFromFile( char* fileName );
    HRESULT loadMasks( char* fileName );

	// return a texture given a texture id
	LPDIRECT3DTEXTURE9 getTexture( int textureId );

	// set D3D extravaganza
	void setD3DDevice( LPDIRECT3DDEVICE9 pd3dDevice );

	bool getWalkability( int textureId, RECT* collideRect, bool mainCharacter );
private:
    int clipYToTile( int oldY );
    int clipXToTile( int oldX );
	LPDIRECT3DTEXTURE9 loadTexture( char* textureName );  // load a texture into map/ memory
	TextureVector textures;			// map of all textures
    MaskVector masks;
	TextureWalkableVector textureWalkable;
	LPDIRECT3DDEVICE9 pd3dDevice;   // D3D device
};
