#pragma once
#include "global.h"
#include "Entity.h"
struct MyView;
class GamePxa;
//前置声明
struct MyMapLayer;
//游戏地图资源加载器
class GameMap
{
public:
	virtual ~GameMap();
	void Init(MyView* pView, GamePxa* pGamePxa, void* pScriptCmd = nullptr);
	void GetMapSize(int** ppMapW, int** ppMapH);
	std::wstring GetMapFileName();
	std::list<MyMapLayer>* GetLayerList();
	MyMapLayer* GetMapLayer(const wchar_t* layerName);
	lua_State** GetScriptLPtr();
	MyView* GetView();
	void LoadMap(const wchar_t* mapfileName);//载入游戏地图
	void LoadMapXML(const wchar_t* xml);//载入xml游戏地图
	const wchar_t* GetMapShowName();//取地图显示名
	void ReloadLanguage();//重新载入语言
	void CMP(std::wstring layerNameCopyFrom, std::wstring layerNameCopyTo, std::vector<LONG>* pPosArr = nullptr);
	void FullLight();//将所有的图层的天光置1
	void ReloadGameMapScript();
private:
	MyView* pView = nullptr;
	GamePxa* pGamePxa = nullptr;
	void* scriptCmd = nullptr;
	std::wstring mapfileName;//地图文件
	std::wstring mapName;//地图显示名
	int mapW, mapH;//地图尺寸
	std::list<MyMapLayer> layerList;//排序好的图层列表
	std::unordered_map<std::wstring, MyMapLayer*> queryMapLayer;
	lua_State* scriptL = nullptr;
};
//地图图层
struct MyMapLayer :
	public MapLayer
{
	bool bLoad = true;
	std::unordered_map<LONG, LONG> step_pxm;
	std::vector<EntityLoad> step_pxe;
	//实体运行的地图缓存
	std::vector<LONG> pxmArr;//数组版的pxm数据
	std::map<LONG, LONG> updatedPxmArr;//更新的pxm
	int pxmArr_w = 0;
	int pxmArr_h = 0;
	void UpdatePxmArr(int pxaArr_w);//把step_pxm的数据更新到pxmArr中
	//帧数跳跃
	int jumpFrame_counter = 0;
	//绘制
	float loopBk_x = 0, loopBk_y = 0;//循环背景层的绘制动画
	float loopBk_last_x = 0, loopBk_last_y = 0;//循环背景层的绘制动画
	float loopBk_dx = 0, loopBk_dy = 0;
	bool operator <(const MyMapLayer& r) const;
};
