|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\WidgetBestRecords\Plugins; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Bundle\LocalRecords\DataProviders\Listener\RecordsDataListener; |
|
6
|
|
|
use eXpansion\Bundle\LocalRecords\Model\Record; |
|
7
|
|
|
use eXpansion\Bundle\WidgetBestRecords\Plugins\Gui\BestRecordsWidgetFactory; |
|
8
|
|
|
use eXpansion\Framework\Core\Model\UserGroups\Group; |
|
9
|
|
|
use eXpansion\Framework\Core\Plugins\StatusAwarePluginInterface; |
|
10
|
|
|
use eXpansion\Framework\Core\Storage\PlayerStorage; |
|
11
|
|
|
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpLegacyMap; |
|
12
|
|
|
use Maniaplanet\DedicatedServer\Connection; |
|
13
|
|
|
use Maniaplanet\DedicatedServer\Structures\Map; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
class BestRecords implements StatusAwarePluginInterface, RecordsDataListener, ListenerInterfaceMpLegacyMap |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var Connection */ |
|
19
|
|
|
protected $connection; |
|
20
|
|
|
/** |
|
21
|
|
|
* @var PlayerStorage |
|
22
|
|
|
*/ |
|
23
|
|
|
private $playerStorage; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var BestRecordsWidgetFactory |
|
26
|
|
|
*/ |
|
27
|
|
|
private $widget; |
|
28
|
|
|
/** |
|
29
|
|
|
* @var Group |
|
30
|
|
|
*/ |
|
31
|
|
|
private $players; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var Group |
|
35
|
|
|
*/ |
|
36
|
|
|
private $allPlayers; |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Debug constructor. |
|
41
|
|
|
* |
|
42
|
|
|
* @param Connection $connection |
|
43
|
|
|
* @param PlayerStorage $playerStorage |
|
44
|
|
|
* @param BestRecordsWidgetFactory $widget |
|
45
|
|
|
* @param Group $players |
|
46
|
|
|
* @param Group $allPlayers |
|
47
|
|
|
*/ |
|
48
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
|
|
49
|
|
|
Connection $connection, |
|
50
|
|
|
PlayerStorage $playerStorage, |
|
51
|
|
|
BestRecordsWidgetFactory $widget, |
|
52
|
|
|
Group $players, |
|
53
|
|
|
Group $allPlayers |
|
54
|
|
|
) { |
|
55
|
|
|
$this->connection = $connection; |
|
56
|
|
|
$this->playerStorage = $playerStorage; |
|
57
|
|
|
$this->widget = $widget; |
|
58
|
|
|
$this->players = $players; |
|
59
|
|
|
$this->allPlayers = $allPlayers; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Set the status of the plugin |
|
64
|
|
|
* |
|
65
|
|
|
* @param boolean $status |
|
66
|
|
|
* |
|
67
|
|
|
* @return void |
|
68
|
|
|
*/ |
|
69
|
|
|
public function setStatus($status) |
|
70
|
|
|
{ |
|
71
|
|
|
if ($status) { |
|
72
|
|
|
$map = $this->connection->getCurrentMapInfo(); |
|
73
|
|
|
$this->widget->setAuthorTime($map->author, $map->goldTime); |
|
74
|
|
|
$this->widget->create($this->allPlayers); |
|
75
|
|
|
} else { |
|
76
|
|
|
$this->widget->destroy($this->allPlayers); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Called when local records are loaded. |
|
82
|
|
|
* |
|
83
|
|
|
* @param Record[] $records |
|
84
|
|
|
*/ |
|
85
|
|
View Code Duplication |
public function onLocalRecordsLoaded($records) |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
if (count($records) > 0) { |
|
88
|
|
|
$this->widget->setLocalRecord($records[0]); |
|
89
|
|
|
} else { |
|
90
|
|
|
$this->widget->setLocalRecord(null); |
|
91
|
|
|
} |
|
92
|
|
|
$this->widget->update($this->allPlayers); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Called when a player finishes map for the very first time (basically first record). |
|
97
|
|
|
* |
|
98
|
|
|
* @param Record $record |
|
99
|
|
|
* @param Record[] $records |
|
100
|
|
|
* @param $position |
|
101
|
|
|
*/ |
|
102
|
|
|
public function onLocalRecordsFirstRecord(Record $record, $records, $position) |
|
103
|
|
|
{ |
|
104
|
|
|
$this->widget->setLocalRecord($record); |
|
105
|
|
|
$this->widget->update($this->allPlayers); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Called when a player finishes map and does same time as before. |
|
110
|
|
|
* |
|
111
|
|
|
* @param Record $record |
|
112
|
|
|
* @param Record $oldRecord |
|
113
|
|
|
* @param Record[] $records |
|
114
|
|
|
*/ |
|
115
|
|
|
public function onLocalRecordsSameScore(Record $record, Record $oldRecord, $records) |
|
116
|
|
|
{ |
|
117
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Called when a player finishes map with better time and has better position. |
|
122
|
|
|
* |
|
123
|
|
|
* @param Record $record |
|
124
|
|
|
* @param Record $oldRecord |
|
125
|
|
|
* @param Record[] $records |
|
126
|
|
|
* @param int $position |
|
127
|
|
|
* @param int $oldPosition |
|
128
|
|
|
*/ |
|
129
|
|
|
public function onLocalRecordsBetterPosition(Record $record, Record $oldRecord, $records, $position, $oldPosition) |
|
130
|
|
|
{ |
|
131
|
|
|
if ($position == 1) { |
|
132
|
|
|
$this->widget->setLocalRecord($record); |
|
133
|
|
|
$this->widget->update($this->allPlayers); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Called when a player finishes map with better time but keeps same position. |
|
139
|
|
|
* |
|
140
|
|
|
* @param Record $record |
|
141
|
|
|
* @param Record $oldRecord |
|
142
|
|
|
* @param Record[] $records |
|
143
|
|
|
* @param $position |
|
144
|
|
|
*/ |
|
145
|
|
|
public function onLocalRecordsSamePosition(Record $record, Record $oldRecord, $records, $position) |
|
146
|
|
|
{ |
|
147
|
|
|
if ($position == 1) { |
|
148
|
|
|
$this->widget->setLocalRecord($record); |
|
149
|
|
|
$this->widget->update($this->allPlayers); |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @param Map $map |
|
156
|
|
|
* |
|
157
|
|
|
* @return void |
|
158
|
|
|
*/ |
|
159
|
|
|
public function onBeginMap(Map $map) |
|
160
|
|
|
{ |
|
161
|
|
|
$this->widget->setAuthorTime($map->author, $map->authorTime); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @param Map $map |
|
166
|
|
|
* |
|
167
|
|
|
* @return void |
|
168
|
|
|
*/ |
|
169
|
|
|
public function onEndMap(Map $map) |
|
170
|
|
|
{ |
|
171
|
|
|
|
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
|
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.