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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166 | #include "gfCAnagramComponent.h"
#include <fsAppCore/src/fsCEntity.h>
#include <fsRenderer/src/components/fsCSpriteComponent.h>
#include <fsAppCore/src/fsCAppMessageDispatcher.h>
#include <fsAppCore/src/fsCEntityFactory.h>
#include "../gfCMinigameLetterTileComponent.h"
#include "../gfCMinigameWordComponent.h"
const fsCUniqueId gfCAnagramComponent::mTypeId("fsCAnagramComponent");
const fsCUniqueId gfCAnagramComponent::mAnagramInitMsg("anagramInitMsg");
const fsStr gfCAnagramComponent::mAnagramPrefix("AGM-");
void gfCAnagramComponent::swap(fsCEntity* const pFlipTile)
{
const fsPoint firstPos = pFlipTile->posGet();
pFlipTile->posSet(mFlipper->posGet());
mFlipper->posSet(firstPos);
mFlipper->componentGet<gfCMinigameLetterTileComponent>()->tint(fsSColour4B::fsWHITE());
//
// mFlipper->componentAdd< fsCStraightLineTrailComponent>();
// pFlipTile->componentAdd< fsCStraightLineTrailComponent>();
//
// mFlipper->componentGet<fsCStraightLineTrailComponent>()->initialise(mFlipper->posGet(), pFlipTile->posGet(), 1000, false);
// pFlipTile->componentGet<fsCStraightLineTrailComponent>()->initialise(pFlipTile->posGet(), mFlipper->posGet(), 1000, false);
mFlipper = nullptr;
}
fsStr gfCAnagramComponent::sanatizeAnagram(const fsStr& pAnagram) const
{
fsStr anagram = pAnagram;
fsStr spaceFreeAnagram("");
while (!anagram.emptyGet())
{
spaceFreeAnagram += anagram.chomp(" ");
}
return spaceFreeAnagram;
}
fsStr gfCAnagramComponent::currentAnagramStateGet()
{
std::sort(mTileEntities.begin(), mTileEntities.end(),
[](fsCEntity* const pEntA, fsCEntity* const pEntB)
{
return pEntA->posGet().x < pEntB->posGet().x;
});
fsStr anagram("");
for (fsCEntity* ent : mTileEntities)
{
anagram += ent->componentGet<gfCMinigameLetterTileComponent>()->letterGet();<--- Consider using std::accumulate algorithm instead of a raw loop.
}
return sanatizeAnagram(anagram);
}
void gfCAnagramComponent::intialise(const fsStr& pAnagram, const fsStr& pSolution, const fsStr& pTileSet)
{
for (fsCEntity* const tile : mTileEntities)
{
tile->destroy();
}
mTileEntities.clear();
// Anagram data is authored as English/ASCII letters, so one tile per byte is expected here.
for (fsS32 curr = 0; curr < pAnagram.lengthGet(); ++curr)
{
fsCEntity* tileEnt = parentGet()->entityFactoryGet()->emptyEntityCreate(
fsStr("tile-") + (static_cast<fsS32>(mTileEntities.size())));
gfCMinigameLetterTileComponent* const letter = tileEnt->componentAdd<gfCMinigameLetterTileComponent>();<--- Variable 'letter' can be declared as pointer to const<--- Variable 'letter' is assigned a value that is never used.
fsStr currChar;
currChar += static_cast<fsChar>(pAnagram[curr]);
// letter->initialise(pTileSet, tileEnt, currChar, mTileEntities.size());
tileEnt->posSet(fsPoint(
-pAnagram.lengthGet() * tileEnt->componentGet<fsCSpriteComponent>()->widthGet() / 2 +
tileEnt->componentGet<fsCSpriteComponent>()->widthGet() * curr,
-40
));
parentGet()->parentGet()->childAdd(tileEnt);
mTileEntities.push_back(tileEnt);
}
}
void gfCAnagramComponent::deserialiseDo()
{
fsIMessageListenerComponent::deserialiseDo();
}
void gfCAnagramComponent::serialiseDo()
{
fsIMessageListenerComponent::serialiseDo();
}
void gfCAnagramComponent::listenersRegisterDo()
{
fsIMessageListenerComponent::listenersRegisterDo();
// fsCAppMessageDispatcher::instanceGet()->listenerRegister(gfCMinigameLetterTileComponent::mTileMouseUpMsg, this);
fsCAppMessageDispatcher::instanceGet()->listenerRegister(mAnagramInitMsg, this);
}
void gfCAnagramComponent::listenersDeregisterDo()
{
fsIMessageListenerComponent::listenersDeregisterDo();
// fsCAppMessageDispatcher::instanceGet()->listenerDeregister(gfCMinigameLetterTileComponent::mTileMouseUpMsg, this);
fsCAppMessageDispatcher::instanceGet()->listenerDeregister(mAnagramInitMsg, this);
}
fsBool gfCAnagramComponent::messageProcessDo(const fsCUniqueId& pMessageType,
const fsIMessageDispatcher::sMessageParameters& pParam)
{
if (mAnagramInitMsg == pMessageType)
{
const sAnagramInitMsgParam& params = static_cast<const sAnagramInitMsgParam&>(pParam);
intialise(params.mAnagram, params.mAnagramSolution, params.mTileSet);
}
// else if (gfCMinigameLetterTileComponent::mTileMouseUpMsg == pMessageType)
{
// fsCEntity * const flipTile = static_cast<const gfCMinigameLetterTileComponent::sTileMessageParam&>(pParam).mEnt;
// if (!mFlipper)
// {
// mFlipper = flipTile;
// mFlipper->componentGet<gfCMinigameLetterTileComponent>()->tint(true);
// }
// else
// {
// swap(flipTile);
// broadcastAnagramState();
// }
return true;
}
return false;<--- Consecutive return, break, continue, goto or throw statements are unnecessary. [+]Consecutive return, break, continue, goto or throw statements are unnecessary. The second statement can never be executed, and so should be removed.
}
fsBool gfCAnagramComponent::broadcastAnagramState()
{
return false;
// gfCMinigameLetterTileComponent::sTileMessageParam params;
// params.mStr = currentAnagramStateGet();
// params.mSelection = nullptr;
//
// return (fsCAppMessageDispatcher::instanceGet()->messageDispatch(gfCMinigameWordComponent::mWordSearchWordCollectedMsg, params));
}
void gfCAnagramComponent::initialiseFromVariableTableDo(const fsCVariableTable& pVars)
{
initialiseFromVariableTable(pVars);
}
fsIComponent* gfCAnagramComponent::create(fsCEntity* pParent)
{
return new gfCAnagramComponent(pParent);
}
gfCAnagramComponent::gfCAnagramComponent(fsCEntity* const pParent) :
fsIMessageListenerComponent(pParent),
mFlipper(nullptr)
{
}
gfCAnagramComponent::~gfCAnagramComponent()
{
}
|