63 lines
1.5 KiB
C++
63 lines
1.5 KiB
C++
#pragma once
|
|
#include "Asset/AssetManager.h"
|
|
#include "EngineFrame/Component/Canvas.h"
|
|
#include "EngineFrame/Component/Sprite.h"
|
|
class GameMap;
|
|
class Tile : public Canvas
|
|
{
|
|
|
|
public:
|
|
struct ImgKey
|
|
{
|
|
std::string img;
|
|
int index;
|
|
|
|
bool operator<(const ImgKey &other) const
|
|
{
|
|
if (img != other.img)
|
|
{
|
|
return img < other.img; // 字符串按字典序比较
|
|
}
|
|
return index < other.index; // 字符串相同则比较index
|
|
}
|
|
};
|
|
struct DrawInfo
|
|
{
|
|
ImgKey sprite_;
|
|
glm::vec2 pos;
|
|
};
|
|
|
|
using TileInfoBody = std::variant<int, std::string>;
|
|
using TileInfo = std::unordered_map<std::string, TileInfoBody>;
|
|
|
|
private:
|
|
/**父对象地图 */
|
|
GameMap *m_parentMap;
|
|
/**绘制精灵集 */
|
|
std::map<ImgKey, RefPtr<Sprite>> m_imgMap;
|
|
/**绘制队列 */
|
|
std::vector<DrawInfo> m_drawQueue;
|
|
|
|
/**基础地板宽度 */
|
|
float m_BasicTileWidth = 0;
|
|
/**基础地板高度 */
|
|
float m_BasicTileHeight = 0;
|
|
/**Ex地板高度 */
|
|
float m_ExTileHeight = 0;
|
|
|
|
/**横向地板数量 */
|
|
int m_Tile_X_Count = 0;
|
|
/**纵向最大偏移 */
|
|
float m_tileY = 0;
|
|
|
|
public:
|
|
Tile(GameMap *parentMap, std::vector<std::string> normal, std::vector<std::string> ex);
|
|
~Tile();
|
|
|
|
void InitTile(std::string Path, int Index);
|
|
void InitExTile(std::string Path, int Index);
|
|
void InitInfo(std::string Path, TileInfo &m_data);
|
|
|
|
void DrawTile();
|
|
};
|