Skip to content

Commit

Permalink
[DONE] The team game can now be used with pictures or text.
Browse files Browse the repository at this point in the history
  • Loading branch information
Qosmio1\Antoine committed Jun 5, 2018
1 parent 3478ddb commit f621ffb
Show file tree
Hide file tree
Showing 11 changed files with 340 additions and 99 deletions.
15 changes: 12 additions & 3 deletions Classes/Engine/Include/CJsonParser_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inline void CJsonParser::ParseJson(RefJsonNode a_rJsonNode, T* a_pNode, bool a_b
// the object parameters
RefJsonNode rParams = a_rJsonNode["params"];

int x = 0, y = 0, width = 0, height = 0;
int x = 0, y = 0, width = 0, height = 0;
std::string id;
if (rParams.HasMember("x") && rParams.HasMember("y"))
{
Expand Down Expand Up @@ -225,6 +225,11 @@ inline void CJsonParser::ParseJson(RefJsonNode a_rJsonNode, T* a_pNode, bool a_b
{

RefJsonNode rTasks = rParams["tasks"];
bool useImages = false;
if (rParams.HasMember("useImages"))
{
useImages = rParams["useImages"].GetBool();
}

TTasksArray oTasksArray;

Expand All @@ -235,7 +240,11 @@ inline void CJsonParser::ParseJson(RefJsonNode a_rJsonNode, T* a_pNode, bool a_b
RefJsonNode rTask = rTasks[i];
std::array<std::string, 2> oTaskArray;
oTaskArray[0] = rTask[0].GetString();
oTaskArray[1] = rTask[1].GetString();
if(useImages){
oTaskArray[1] = NormalizePath(rTask[1].GetString());
} else {
oTaskArray[1] = rTask[1].GetString();
}

oTasksArray[i] = oTaskArray;

Expand All @@ -244,7 +253,7 @@ inline void CJsonParser::ParseJson(RefJsonNode a_rJsonNode, T* a_pNode, bool a_b
pEntity = new CTeamNode(oTasksArray,
m_pKernel,
IntToAnchor(rParams["anchor"].GetInt()),
width, height, x, y);
width, height, x, y,useImages);

}

Expand Down
5 changes: 3 additions & 2 deletions Classes/Engine/Include/CSpriteNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class CSpriteNode : public CEntityNode
virtual void Copy(CEntityNode* a_pSprite, bool a_bRecCopy = true) override;

virtual bool UseFile(const std::string& a_sFilename);

private:
protected:
virtual void Update() override;
private:
void DisplayNewImage();
};

Expand Down
9 changes: 8 additions & 1 deletion Classes/Engine/Include/CTeamNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,35 @@ class CTeamNode : public CGroupNode
int m_iPlayer1CurrentTask;
int m_iPlayer2CurrentTask;

bool bUseImages;

public:
CTeamNode(TTasksArray a_oTasksArray,
CKernel* a_pKernel,
EAnchor a_eAnchor,
int a_iWidth,
int a_iHeight,
int a_iXPosition,
int a_iYPosition);
int a_iYPosition,
bool a_bUseImages=false);

void Init() override;

void RandomizeTasksActions();
bool ValidateTask(const std::string& a_rAction);
void UpdateTask(const std::string& a_rNextTask);
void UpdateActions(const std::array<std::string, M_NB_TASK / 2>& a_rActions);
void TasksFinished();
bool UseImages();
#ifdef LUDOMUSE_EDITOR
TTasksArray GetTasks();
void SetTasks(TTasksArray a_oTasks);
void SetTask(int a_iIndex, const std::string& a_rTask);
void SetAction(int a_iIndex, const std::string& a_rAction);

virtual void ToJson(rapidjson::Value &a_rParent, rapidjson::Document::AllocatorType &a_rAllocator);
void SetUseImages(bool useImages);
void EditorUpdate();
#endif
private:
void SendTask(const std::string& a_rNextTask);
Expand Down
62 changes: 41 additions & 21 deletions Classes/Engine/Source/CKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,12 @@ void CKernel::ProcessMessage(const std::string& a_rMessage)
oActions[i] = vSplittedMessage[i + 3];
}
//std::iota(oActions.begin(), oActions.end(), vSplittedMessage.begin() + 3);

if(pTeamNode->UseImages()){
for (int i = 0; i < M_NB_TASK / 2; ++i)
{
std::replace( oActions[i].begin(), oActions[i].end(), ';', ':');
}
}
pTeamNode->UpdateActions(oActions);

}
Expand Down Expand Up @@ -1877,27 +1882,42 @@ void CKernel::ValidateTeamTask(SEvent a_rEvent, CEntityNode* a_pTarget)
std::vector<CNode*> oSenderChildren = a_rEvent.m_pSender->GetChildren();
if (oSenderChildren.size() > 0)
{
CLabelNode* pLabel = dynamic_cast<CLabelNode*>(oSenderChildren[0]);
if (pLabel)
{
std::string sAction = pLabel->GetText();
if (m_pLocalPlayer->m_iPlayerID == 0)
{
Desc<CNode> oTeamNode;
CFindTeamNodeVisitor oVisitor(oTeamNode);
oVisitor.Traverse(m_pBehaviorTree);
Desc<CNode> oTeamNode;
CFindTeamNodeVisitor oVisitor(oTeamNode);
oVisitor.Traverse(m_pBehaviorTree);
if (oTeamNode.IsValid())
{
CTeamNode* pTeamNode = static_cast<CTeamNode*>(oTeamNode.Get());

if (oTeamNode.IsValid())
{
CTeamNode* pTeamNode = static_cast<CTeamNode*>(oTeamNode.Get());
bool bSuccess = pTeamNode->ValidateTask(sAction);
}
}
else
{
SendNetworkMessage(std::string("kernel:TeamNode:ValidateTeamTask:") + sAction);
}
}

std::string sAction = "";

if (pTeamNode->UseImages()){
CSpriteNode* pSprite = dynamic_cast<CSpriteNode*>(a_rEvent.m_pSender);
if (pSprite)
{
sAction = pSprite->GetPath();
}
} else {
CLabelNode* pLabel = dynamic_cast<CLabelNode*>(oSenderChildren[0]);
if (pLabel)
{
sAction = pLabel->GetText();
}
}

if (sAction != ""){
if (m_pLocalPlayer->m_iPlayerID == 0)
{
pTeamNode->ValidateTask(sAction);
}
else
{
std::replace( sAction.begin(), sAction.end(), ':', ';');
SendNetworkMessage(std::string("kernel:TeamNode:ValidateTeamTask:") + sAction);
}
}
}
}
}

Expand Down
19 changes: 17 additions & 2 deletions Classes/Engine/Source/CSpriteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ CSpriteNode::CSpriteNode(const std::string& a_rFilename,

void CSpriteNode::Init()
{
std::cout << "FileName: " << m_sSpriteFilename << std::endl;
Sprite* pSprite = Sprite::create(CMacroManager::Instance()->CheckDefinition(m_sSpriteFilename));
//m_pCocosEntity->setPosition(Vec2(m_iXPosition, m_iYPosition));

Expand Down Expand Up @@ -65,10 +66,24 @@ void CSpriteNode::SetPath(const std::string &a_sPath)
{
//this->m_pCocosEntity = Sprite::create(a_sPath);
//CCameraFeedNode::DisplayPicture, this, LmJniCppFacade::getCurrentPicturePath()
m_sSpriteFilename = a_sPath;
ON_CC_THREAD(CSpriteNode::Update, this);
auto callback = [this, a_sPath](){
this->m_sSpriteFilename = a_sPath;
this->Update();
};
cocos2d::Director::getInstance()->getScheduler()->performFunctionInCocosThread(callback);
//ON_CC_THREAD(Sprite::setTexture,(Sprite*)m_pCocosEntity,a_sPath);
//((Sprite*)m_pCocosEntity)->setTexture(a_sPath);
//ON_CC_THREAD(, this);
}

void CSpriteNode::Update(){
if (m_pCocosEntity)
((Sprite*)m_pCocosEntity)->setTexture(m_sSpriteFilename);
/*else {
this->UnInit();
this->Init();
}*/
}
//void CSpriteNode::DisplayNewImage()
//{
// CSceneNode* pSceneNode = GetParentSceneNode();
Expand Down
Loading

0 comments on commit f621ffb

Please sign in to comment.