|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Core\Plugins\Gui; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\Model\Gui\Manialink; |
|
6
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManialinkFactoryContext; |
|
7
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManialinkFactoryInterface; |
|
8
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface; |
|
9
|
|
|
use eXpansion\Framework\Core\Model\Gui\Window; |
|
10
|
|
|
use eXpansion\Framework\Core\Model\UserGroups\Group; |
|
11
|
|
|
use eXpansion\Framework\Core\Plugins\GuiHandler; |
|
12
|
|
|
use eXpansion\Framework\Core\Plugins\UserGroups\Factory; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class ManialiveFactory allow the creation of manialinks. |
|
16
|
|
|
* |
|
17
|
|
|
* @package eXpansion\Framework\Core\Plugins\Gui |
|
18
|
|
|
* @author Oliver de Cramer |
|
19
|
|
|
*/ |
|
20
|
|
|
class ManialinkFactory implements ManialinkFactoryInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var GuiHandler */ |
|
23
|
|
|
protected $guiHandler; |
|
24
|
|
|
|
|
25
|
|
|
/** @var Factory */ |
|
26
|
|
|
protected $groupFactory; |
|
27
|
|
|
|
|
28
|
|
|
/** @var ActionFactory */ |
|
29
|
|
|
protected $actionFactory; |
|
30
|
|
|
|
|
31
|
|
|
/** @var string */ |
|
32
|
|
|
protected $name; |
|
33
|
|
|
|
|
34
|
|
|
/** @var string */ |
|
35
|
|
|
protected $className; |
|
36
|
|
|
|
|
37
|
|
|
/** @var Group[] */ |
|
38
|
|
|
protected $groups = []; |
|
39
|
|
|
|
|
40
|
|
|
/** @var float|int */ |
|
41
|
|
|
protected $sizeX; |
|
42
|
|
|
|
|
43
|
|
|
/** @var float|int */ |
|
44
|
|
|
protected $sizeY; |
|
45
|
|
|
|
|
46
|
|
|
/** @var float|int */ |
|
47
|
|
|
protected $posX; |
|
48
|
|
|
|
|
49
|
|
|
/** @var float|int */ |
|
50
|
|
|
protected $posY; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* ManialinkFactory constructor. |
|
54
|
|
|
* |
|
55
|
|
|
* @param $name |
|
56
|
|
|
* @param $sizeX |
|
57
|
|
|
* @param $sizeY |
|
58
|
|
|
* @param null $posX |
|
59
|
|
|
* @param null $posY |
|
60
|
|
|
* @param ManialinkFactoryContext $context |
|
61
|
|
|
*/ |
|
62
|
4 |
|
public function __construct( |
|
63
|
|
|
$name, |
|
64
|
|
|
$sizeX, |
|
65
|
|
|
$sizeY, |
|
66
|
|
|
$posX = null, |
|
67
|
|
|
$posY = null, |
|
68
|
|
|
ManialinkFactoryContext $context |
|
69
|
|
|
) { |
|
70
|
4 |
|
if (is_null($posX)) { |
|
71
|
4 |
|
$posX = $sizeX / -2; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
4 |
|
if (is_null($posY)) { |
|
75
|
4 |
|
$posY = $sizeY / 2; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
4 |
|
$this->guiHandler = $context->getGuiHandler(); |
|
79
|
4 |
|
$this->groupFactory = $context->getGroupFactory(); |
|
80
|
4 |
|
$this->actionFactory = $context->getActionFactory(); |
|
81
|
4 |
|
$this->className = $context->getClassName(); |
|
82
|
4 |
|
$this->name = $name; |
|
83
|
4 |
|
$this->sizeX = $sizeX; |
|
84
|
4 |
|
$this->sizeY = $sizeY; |
|
85
|
4 |
|
$this->posX = $posX; |
|
86
|
4 |
|
$this->posY = $posY; |
|
87
|
4 |
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return string |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getId() |
|
93
|
|
|
{ |
|
94
|
|
|
return spl_object_hash($this); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @inheritdoc |
|
99
|
|
|
* @param string|array|Group $group |
|
100
|
|
|
*/ |
|
101
|
4 |
|
public function create($group) |
|
102
|
|
|
{ |
|
103
|
4 |
View Code Duplication |
if (is_string($group)) { |
|
|
|
|
|
|
104
|
1 |
|
$group = $this->groupFactory->createForPlayer($group); |
|
105
|
|
|
} else { |
|
106
|
3 |
|
if (is_array($group)) { |
|
107
|
2 |
|
$group = $this->groupFactory->createForPlayers($group); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
4 |
|
if (!is_null($this->guiHandler->getManialink($group, $this))) { |
|
112
|
1 |
|
$this->update($group); |
|
113
|
|
|
|
|
114
|
1 |
|
return $group; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
3 |
|
$ml = $this->createManialink($group); |
|
119
|
3 |
|
$this->guiHandler->addToDisplay($ml, $this); |
|
|
|
|
|
|
120
|
|
|
|
|
121
|
3 |
|
$this->createContent($ml); |
|
122
|
3 |
|
$this->updateContent($ml); |
|
123
|
|
|
|
|
124
|
3 |
|
return $group; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @inheritdoc |
|
129
|
|
|
* @param string|array|Group $group |
|
130
|
|
|
*/ |
|
131
|
1 |
|
public function update($group) |
|
132
|
|
|
{ |
|
133
|
1 |
View Code Duplication |
if (is_string($group)) { |
|
|
|
|
|
|
134
|
|
|
$group = $this->groupFactory->createForPlayer($group); |
|
135
|
|
|
} else { |
|
136
|
1 |
|
if (is_array($group)) { |
|
137
|
|
|
$group = $this->groupFactory->createForPlayers($group); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
1 |
|
$ml = $this->guiHandler->getManialink($group, $this); |
|
142
|
1 |
|
if ($ml) { |
|
143
|
1 |
|
$this->actionFactory->destroyNotPermanentActions($ml); |
|
144
|
1 |
|
if ($ml instanceof Window) { |
|
|
|
|
|
|
145
|
|
|
$ml->busyCounter += 1; |
|
146
|
|
|
echo "counter:".$ml->busyCounter."-".($ml->busyCounter % 3)."\n"; |
|
147
|
|
|
if ($ml->isBusy && $ml->busyCounter > 1) { |
|
148
|
|
|
$ml->setBusy(false); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
1 |
|
$this->updateContent($ml); |
|
152
|
1 |
|
$this->guiHandler->addToDisplay($ml, $this); |
|
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
} |
|
155
|
1 |
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Create content in the manialink. |
|
159
|
|
|
* |
|
160
|
|
|
* @param ManialinkInterface $manialink |
|
161
|
|
|
* |
|
162
|
|
|
*/ |
|
163
|
3 |
|
protected function createContent(ManialinkInterface $manialink) |
|
164
|
|
|
{ |
|
165
|
|
|
// Put content in the manialink here. |
|
166
|
3 |
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Update content in the manialink. |
|
170
|
|
|
* |
|
171
|
|
|
* @param ManialinkInterface $manialink |
|
172
|
|
|
* |
|
173
|
|
|
*/ |
|
174
|
4 |
|
protected function updateContent(ManialinkInterface $manialink) |
|
175
|
|
|
{ |
|
176
|
|
|
// Put content in the manialink here. |
|
177
|
4 |
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @inheritdoc |
|
181
|
|
|
*/ |
|
182
|
1 |
|
public function destroy(Group $group) |
|
183
|
|
|
{ |
|
184
|
1 |
|
$ml = $this->guiHandler->getManialink($group, $this); |
|
185
|
1 |
|
if ($ml) { |
|
186
|
1 |
|
$this->guiHandler->addToHide($ml, $this); |
|
|
|
|
|
|
187
|
|
|
} |
|
188
|
1 |
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Create manialink object for user group. |
|
192
|
|
|
* |
|
193
|
|
|
* @param Group $group |
|
194
|
|
|
* |
|
195
|
|
|
* @return Manialink |
|
196
|
|
|
*/ |
|
197
|
3 |
|
protected function createManialink(Group $group) |
|
198
|
|
|
{ |
|
199
|
3 |
|
$className = $this->className; |
|
200
|
|
|
|
|
201
|
3 |
|
return new $className($this, $group, $this->name, $this->sizeX, $this->sizeY, $this->posX, $this->posY); |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.