#include "CS_FrogAni.h"

CS_FrogAni::CS_FrogAni()
{
	ani.png = L"CS_CaveStoryMod";
	ani.hideLayerList.insert(1);
}

void CS_FrogAni::Step()
{
	//玩家靠近招手
	bool bHello = false;
	if (gameFunc->GetPlayerDistance)
	{
		auto wplayer = gameFunc->GetPlayerDistance(gameFunc->game, x, y).lock();
		if (wplayer)
		{
			if (x - 64 < wplayer->x && x + 64 > wplayer->x && y - 16 < wplayer->y && y + 16 > wplayer->y)
			{
				//招手动画
				bHello = true;
			}
		}
	}
	ani.image_index = bHello ? 1 : 0;
}

void CS_FrogAni::SetState(int stateID, int lr)
{
	this->lr = lr;
	this->stateID = stateID;
	switch (stateID)
	{
	case 1://失去了物品
		ani.hideLayerList.insert(0);
		ani.hideLayerList.erase(1);
		break;
	case 2://获得了物品
		ani.hideLayerList.erase(0);
		ani.hideLayerList.insert(1);
		break;
	}
	ani.sprite_index = lr == 0 ? L"mc_frog_l" : L"mc_frog_r";
}

void CS_FrogAni::SetState(std::wstring stateName, int lr)
{
	if (stateName == L"normal")
		SetState(0, lr);
	else if(stateName == L"lose_item")
		SetState(1, lr);
	else if (stateName == L"retrieve_item")
		SetState(2, lr);
}

std::shared_ptr<Entity> CreateCS_FrogAni()
{
	return std::make_shared<CS_FrogAni>();
}
