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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184 |
#include "gfCJigsawLogicComponent.h"
#include <fsCore/src/fsNRnd.h>
#include <fsCore/src/fsCVariableTable.h>
#include <fsAppCore/src/fsILevelBasedAppCoreMain.h>
#include <fsAppCore/src/fsCAppMessageDispatcher.h>
#include <gfHogCore/src/gfCHogEntityFactory.h>
#include <fsAppCore/src/fsILevelBasedAppCoreMain.h>
#include "components/gfCDrawOrderControllerComponent.h"
#include "components/gfIMinigameComponent.h"
#include "gfCJigsawComponentCutter.h"
#include "gfComponents/components/subScene/gfCSubSceneComponent.h"
#include "gfCJigsawDeckComponent.h"
#include "gfCJigsawDrawerComponent.h"
const fsCUniqueId gfCJigsawLogicComponent::mTypeId("gfCJigsawLogicComponent");
const fsStr gfCJigsawLogicComponent::mEntityPrefix("JIGLGC");
fsCEntity* const gfCJigsawLogicComponent::desktopGet()
{
return parentGet();
return fsILevelBasedAppCoreMain::instanceGet()->sceneGet()->firstEntityWithComponentsOfFamilyType<gfCJigsawComponentCutter>() ?
fsILevelBasedAppCoreMain::instanceGet()->sceneGet()->firstEntityWithComponentsOfFamilyType<gfCJigsawComponentCutter>() :
fsILevelBasedAppCoreMain::instanceGet()->sceneGet()->firstEntityWithComponentsOfFamilyType<gfCSubSceneComponent>();
}
void gfCJigsawLogicComponent::listenersRegisterDo()
{
gfIMinigameLogic::listenersRegisterDo();
fsCAppMessageDispatcher::instanceGet()->listenerRegister(fsILevelBasedAppCoreMain::mLevelInitialisedMsg, this);
}
void gfCJigsawLogicComponent::listenersDeregisterDo()
{
gfIMinigameLogic::listenersDeregisterDo();
fsCAppMessageDispatcher::instanceGet()->listenerDeregister(fsILevelBasedAppCoreMain::mLevelInitialisedMsg, this);
}
fsBool gfCJigsawLogicComponent::messageProcessDo(const fsCUniqueId& pMessageType,
const fsIMessageDispatcher::sMessageParameters& pParam)
{
if (pMessageType == fsILevelBasedAppCoreMain::mLevelInitialisedMsg)
{
helpImagesReposition();
}
return gfIMinigameLogic::messageProcessDo(pMessageType, pParam);
}
void gfCJigsawLogicComponent::helpImagesReposition()
{
if (auto previewImageEnt = fsILevelBasedAppCoreMain::instanceGet()->sceneGet()->entityNamed("jigsawPreviewImage")) {
auto pos = previewImageEnt->posGet();
if (mHelpImagePosition.x != fsS32Max) {
pos.x = mHelpImagePosition.x;
}
if (mHelpImagePosition.y != fsS32Max) {
pos.y = mHelpImagePosition.y;
}
previewImageEnt->posSet(pos);
}
if (auto ghostImageEnt = fsILevelBasedAppCoreMain::instanceGet()->sceneGet()->entityNamed("jigsawGhostImage")) {
auto pos = ghostImageEnt->posGet();
if (mGhostImagePosition.x != fsS32Max) {
pos.x = mGhostImagePosition.x;
}
if (mGhostImagePosition.y != fsS32Max) {
pos.y = mGhostImagePosition.y;
}
ghostImageEnt->posSet(pos);
}
}
void gfCJigsawLogicComponent::skipDo()
{
// auto gameEnts = fsILevelBasedAppCoreMain::instanceGet()->sceneGet()->
// childEntitiesWithComponentsOfFamilyType<gfCJigsawMinigameComponent>();
}
void gfCJigsawLogicComponent::drawOrderPreserve()
{
if (!parentGet()->componentGet<gfCDrawOrderControllerComponent>())
{
auto drawOrder = parentGet()->componentAdd<gfCDrawOrderControllerComponent>();
drawOrder->initialise();
}
}
void gfCJigsawLogicComponent::drawerInit(const fsCVariableTable& pVars)
{
auto drawerFilename= pVars.strGet("drawer");
if (!drawerFilename.emptyGet())
{
auto drawerEnt = parentGet()->entityFactoryGet()->emptyEntityCreate("drawerEnt");
auto drawer = drawerEnt->componentAdd<gfCJigsawDrawerComponent>();
drawer->initialiseFromVariableTable(pVars);
// fsILevelBasedAppCoreMain::instanceGet()->currentSubSceneGet()->parentGet()->childAdd(drawerEnt);
auto* const desktop = desktopGet();
desktop->childAdd(drawerEnt);
}
}
void gfCJigsawLogicComponent::deckInit(const fsCVariableTable& pVars)
{
auto jigsawDeckComponent = parentGet()->componentGet<gfCJigsawDeckComponent>();
if (!jigsawDeckComponent)
{
jigsawDeckComponent = parentGet()->componentAdd<gfCJigsawDeckComponent>();
}
jigsawDeckComponent->initialiseFromVariableTable(pVars);
}
void gfCJigsawLogicComponent::gamePiecesCollect()
{
auto gameEnts = parentGet()->childEntitiesWithComponentsOfFamilyType<gfCJigsawMinigameComponent>();
if (gameEnts.empty())
{ // tried local first for complex scenes where minigame objects are parented to different mini game logic controllers
gameEnts = grandparentGet()->childEntitiesWithComponentsOfFamilyType<gfCJigsawMinigameComponent>();
}
std::for_each(std::begin(gameEnts), std::end(gameEnts),
[&](fsCEntity* const ent)
{
mGamePieces.push_back(ent->componentGet<gfCJigsawMinigameComponent>());
mGamePieces.back()->gameLogicSet(this);
});
}
void gfCJigsawLogicComponent::helpImagesPositionsStore(const fsCVariableTable& pVars)
{
mHelpImagePosition.x = pVars.s32GetWithDefault("boxImagePosXOverride", fsS32Max);
mHelpImagePosition.y = pVars.s32GetWithDefault("boxImagePosYOverride", fsS32Max);
mGhostImagePosition.x = pVars.s32GetWithDefault("ghostImagePosXOverride", fsS32Max);
mGhostImagePosition.y = pVars.s32GetWithDefault("ghostImagePosYOverride", fsS32Max);
}
void gfCJigsawLogicComponent::initialiseFromVariableTableDo(const fsCVariableTable& pVars)
{
gfIMinigameLogic::initialiseFromVariableTableDo(pVars);
gamePiecesCollect();
drawerInit(pVars);
drawOrderPreserve();
deckInit(pVars);
helpImagesPositionsStore(pVars);
std::vector<fsCEntity*> minigameEnts;
grandparentGet()->forAllChildren(
[&minigameEnts](fsCEntity* const ent) -> void
{
if (auto* const comp = ent->firstComponentOfFamilyType<gfIMinigameComponent>())<--- Variable 'comp' is assigned a value that is never used.
{
minigameEnts.emplace_back(ent);
}
});
//std::shuffle(minigameEnts.begin(), minigameEnts.end(), fsNRnd::randomDeviceGet());
}
fsIComponent* gfCJigsawLogicComponent::create(fsCEntity* pParent)
{
return new gfCJigsawLogicComponent(pParent);
}
gfCJigsawLogicComponent::gfCJigsawLogicComponent(fsCEntity* pParent):
gfIMinigameLogic(pParent),
mGhostImagePosition(fsS32Max, fsS32Max),
mHelpImagePosition(fsS32Max, fsS32Max)
{
}
gfCJigsawLogicComponent::~gfCJigsawLogicComponent()
{
}
|