1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "gfCAnagramController.h"

#include <fsAppCore/src/fsCLocalisedStrings.h>
#include <fsAppCore/src/fsCEntityFactory.h>
#include <fsAppCore/src/fsCAppMessageDispatcher.h>

#include <gfComponents/components/subScene/gfCSubSceneComponent.h>

#include "../gfCMinigameWordComponent.h"

#include "gfCAnagramComponent.h"
#include "gfComponents/gfIPickListEntryGui.h"

const fsCUniqueId gfCAnagramController::mTypeId("fsCAnagramController");
const fsStr gfCAnagramController::mEntityPrefix("AGM");


void gfCAnagramController::listenersRegisterDo()
{
	fsIMessageListenerComponent::listenersRegisterDo();
	fsCAppMessageDispatcher::instanceGet()->listenerRegister(gfIPickListEntryGui::mAddedEntryToPickListdMsg, this);
}

void gfCAnagramController::listenersDeregisterDo()
{
	fsIMessageListenerComponent::listenersDeregisterDo();
	fsCAppMessageDispatcher::instanceGet()->listenerDeregister(gfIPickListEntryGui::mAddedEntryToPickListdMsg, this);
}

void gfCAnagramController::nextAnagramInit(const fsStr& pAnagram)
{
	fsAnagram next = *std::find_if(mAnagrams.begin(), mAnagrams.end(),
	                               [&pAnagram](fsAnagram& anagram)<--- Parameter 'anagram' can be declared as reference to const
	                               {
		                               return anagram.mSolution == pAnagram;
	                               });

	gfCAnagramComponent::sAnagramInitMsgParam params;
	params.mAnagram = next.mAnagram;
	params.mAnagramSolution = next.mSolution;
	params.mTileSet = mTileSet;
	fsCAppMessageDispatcher::instanceGet()->messageDispatch(gfCAnagramComponent::mAnagramInitMsg, params);
}

fsBool gfCAnagramController::messageProcessDo(const fsCUniqueId& pMessageType,
                                              const fsIMessageDispatcher::sMessageParameters& pParam)
{
	if (gfIPickListEntryGui::mAddedEntryToPickListdMsg == pMessageType)
	{
		fsIMessageDispatcher::sStrMessageParam param = static_cast<const fsIMessageDispatcher::sStrMessageParam&>(pParam
		);
		nextAnagramInit(param.mStr);
	}
	return false;
}

void gfCAnagramController::deserialiseDo()
{
	fsIMessageListenerComponent::deserialiseDo();
}

void gfCAnagramController::serialiseDo()
{
	fsIMessageListenerComponent::serialiseDo();
}

fsCEntity* const gfCAnagramController::mainSceneEntGet() const
{
	return static_cast<fsCEntity*>(parentGet()->firstChildEntityWithComponentsOfFamilyType<gfCSubSceneComponent>());
}

void gfCAnagramController::collectableAnagramsCreate()
{
	for (auto anagram = mAnagrams.begin(); anagram != mAnagrams.end(); ++anagram)
	{
		fsCEntity* ent = parentGet()->entityFactoryGet()->entityConstruct(
			gfCMinigameWordComponent::mWordSearchWordPrefix + (*anagram).mSolution);
		parentGet()->childAdd(ent);
	}
}

void gfCAnagramController::anagramsStringsCreateFromLevelFile(const fsCVariableTable& pVars)
{
	const fsStr anagramKey = gfCAnagramComponent::mAnagramPrefix + "Q";
	const fsStr anagramSolutionKey = gfCAnagramComponent::mAnagramPrefix + "A";
	fsS32 currAnagram = 1;
	fsStr anagram = pVars.strGet(anagramKey + currAnagram);
	fsStr anagramSolution = pVars.strGet(anagramSolutionKey + currAnagram);
	while (!anagram.emptyGet() && !anagramSolution.emptyGet())
	{
		mAnagrams.push_back(fsAnagram(
			fsCLocalisedStrings::localisedStringGet(anagram),
			fsCLocalisedStrings::localisedStringGet(anagramSolution)
		));
		++currAnagram;
		anagram = pVars.strGet(anagramKey + currAnagram);
		anagramSolution = pVars.strGet(anagramSolutionKey + currAnagram);
	}
	std::reverse(mAnagrams.begin(), mAnagrams.end());
}

void gfCAnagramController::initialiseFromVariableTableDo(const fsCVariableTable& pVars)
{
	mTileSet = pVars.strGet("tileSet");
	anagramsStringsCreateFromLevelFile(pVars);

	collectableAnagramsCreate();
}

fsIComponent* gfCAnagramController::create(fsCEntity* pParent)
{
	return new gfCAnagramController(pParent);
}

gfCAnagramController::gfCAnagramController(fsCEntity* const pParent) :
	fsIMessageListenerComponent(pParent),
	mTileSet("")
{
}

gfCAnagramController::~gfCAnagramController()
{
}

gfCAnagramController::fsAnagram::fsAnagram(const fsStr& pAnagram, const fsStr& pSolution) :
	mAnagram(pAnagram),
	mSolution(pSolution)
{
	mAnagram.downcase();
	mSolution.downcase();
}