1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Orm\Entity; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\Common\Collections\Collection; |
9
|
|
|
use Doctrine\ORM\Mapping\Column; |
10
|
|
|
use Doctrine\ORM\Mapping\Entity; |
11
|
|
|
use Doctrine\ORM\Mapping\GeneratedValue; |
12
|
|
|
use Doctrine\ORM\Mapping\Id; |
13
|
|
|
use Doctrine\ORM\Mapping\Index; |
14
|
|
|
use Doctrine\ORM\Mapping\JoinColumn; |
15
|
|
|
use Doctrine\ORM\Mapping\ManyToOne; |
16
|
|
|
use Doctrine\ORM\Mapping\OneToMany; |
17
|
|
|
use Doctrine\ORM\Mapping\OneToOne; |
18
|
|
|
use Doctrine\ORM\Mapping\OrderBy; |
19
|
|
|
use Doctrine\ORM\Mapping\Table; |
20
|
|
|
use Doctrine\ORM\Mapping\UniqueConstraint; |
21
|
|
|
use Stu\Component\Map\MapEnum; |
22
|
|
|
use Stu\Lib\SectorString; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @Entity(repositoryClass="Stu\Orm\Repository\MapRepository") |
26
|
|
|
* @Table( |
27
|
|
|
* name="stu_map", |
28
|
|
|
* indexes={ |
29
|
|
|
* @Index(name="coordinates_idx", columns={"cx", "cy"}), |
30
|
|
|
* @Index(name="coordinates_reverse_idx", columns={"cy", "cx"}), |
31
|
|
|
* @Index(name="map_field_type_idx", columns={"field_id"}), |
32
|
|
|
* @Index(name="map_layer_idx", columns={"layer_id"}), |
33
|
|
|
* @Index(name="map_system_idx", columns={"systems_id"}), |
34
|
|
|
* @Index(name="map_system_type_idx", columns={"system_type_id"}) |
35
|
|
|
* }, |
36
|
|
|
* uniqueConstraints={ |
37
|
|
|
* @UniqueConstraint(name="map_coordinate_idx", columns={"layer_id", "cx", "cy"}) |
38
|
|
|
* } |
39
|
|
|
* ) |
40
|
|
|
**/ |
41
|
|
|
class Map implements MapInterface |
42
|
|
|
{ |
43
|
|
|
/** |
44
|
|
|
* @Id |
45
|
|
|
* @Column(type="integer") |
46
|
|
|
* @GeneratedValue(strategy="IDENTITY") |
47
|
|
|
* |
48
|
|
|
*/ |
49
|
|
|
private int $id; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @Column(type="integer") |
53
|
|
|
* |
54
|
|
|
*/ |
55
|
|
|
private int $cx = 0; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @Column(type="integer") |
59
|
|
|
* |
60
|
|
|
*/ |
61
|
|
|
private int $cy = 0; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @Column(type="integer") |
65
|
|
|
* |
66
|
|
|
*/ |
67
|
|
|
private int $layer_id; |
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @Column(type="integer") |
71
|
|
|
* |
72
|
|
|
*/ |
73
|
|
|
private int $field_id = 0; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @Column(type="integer", nullable=true) |
77
|
|
|
* |
78
|
|
|
*/ |
79
|
|
|
private ?int $system_type_id = null; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @Column(type="integer", nullable=true) |
83
|
|
|
* |
84
|
|
|
*/ |
85
|
|
|
private ?int $systems_id = 0; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @Column(type="integer", nullable=true) |
89
|
|
|
* |
90
|
|
|
*/ |
91
|
|
|
private ?int $influence_area_id = 0; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @Column(type="integer", nullable=true) |
95
|
|
|
* |
96
|
|
|
*/ |
97
|
|
|
private ?int $bordertype_id = 0; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @Column(type="integer", nullable=true) |
101
|
|
|
* |
102
|
|
|
*/ |
103
|
|
|
private ?int $region_id = 0; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @Column(type="integer", nullable=true) |
107
|
|
|
* |
108
|
|
|
*/ |
109
|
|
|
private ?int $admin_region_id = null; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* |
113
|
|
|
* @ManyToOne(targetEntity="Layer") |
114
|
|
|
* @JoinColumn(name="layer_id", referencedColumnName="id") |
115
|
|
|
*/ |
116
|
|
|
private LayerInterface $layer; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* |
120
|
|
|
* @OneToOne(targetEntity="StarSystem", inversedBy="map") |
121
|
|
|
* @JoinColumn(name="systems_id", referencedColumnName="id") |
122
|
|
|
*/ |
123
|
|
|
private ?StarSystemInterface $starSystem = null; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* |
127
|
|
|
* @ManyToOne(targetEntity="StarSystem") |
128
|
|
|
* @JoinColumn(name="influence_area_id", referencedColumnName="id") |
129
|
|
|
*/ |
130
|
|
|
private ?StarSystemInterface $influenceArea = null; |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* |
134
|
|
|
* @ManyToOne(targetEntity="MapFieldType") |
135
|
|
|
* @JoinColumn(name="field_id", referencedColumnName="id") |
136
|
|
|
*/ |
137
|
|
|
private MapFieldTypeInterface $mapFieldType; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* |
141
|
|
|
* @ManyToOne(targetEntity="StarSystemType") |
142
|
|
|
* @JoinColumn(name="system_type_id", referencedColumnName="id") |
143
|
|
|
*/ |
144
|
|
|
private ?StarSystemTypeInterface $starSystemType; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* |
148
|
|
|
* @ManyToOne(targetEntity="MapBorderType") |
149
|
|
|
* @JoinColumn(name="bordertype_id", referencedColumnName="id") |
150
|
|
|
*/ |
151
|
|
|
private ?MapBorderTypeInterface $mapBorderType = null; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* |
155
|
|
|
* @ManyToOne(targetEntity="MapRegion") |
156
|
|
|
* @JoinColumn(name="region_id", referencedColumnName="id") |
157
|
|
|
*/ |
158
|
|
|
private ?MapRegionInterface $mapRegion = null; |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* |
162
|
|
|
* @ManyToOne(targetEntity="MapRegion") |
163
|
|
|
* @JoinColumn(name="admin_region_id", referencedColumnName="id") |
164
|
|
|
*/ |
165
|
|
|
private ?MapRegionInterface $administratedRegion = null; |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @var ArrayCollection<int, ShipInterface> |
169
|
|
|
* |
170
|
|
|
* @OneToMany(targetEntity="Ship", mappedBy="map", fetch="EXTRA_LAZY") |
171
|
|
|
*/ |
172
|
|
|
private Collection $ships; |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @var ArrayCollection<int, FlightSignatureInterface> |
176
|
|
|
* |
177
|
|
|
* @OneToMany(targetEntity="FlightSignature", mappedBy="map") |
178
|
|
|
* @OrderBy({"time": "DESC"}) |
179
|
|
|
*/ |
180
|
|
|
private Collection $signatures; |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @var ArrayCollection<int, AnomalyInterface> |
184
|
|
|
* |
185
|
|
|
* @OneToMany(targetEntity="Anomaly", mappedBy="map", fetch="EXTRA_LAZY") |
186
|
|
|
*/ |
187
|
|
|
private Collection $anomalies; |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @var ArrayCollection<int, WormholeEntryInterface> |
191
|
|
|
* |
192
|
|
|
* @OneToMany(targetEntity="WormholeEntry", mappedBy="map") |
193
|
|
|
*/ |
194
|
|
|
private Collection $wormholeEntries; |
195
|
|
|
|
196
|
|
|
|
197
|
|
|
public function __construct() |
198
|
|
|
{ |
199
|
|
|
$this->ships = new ArrayCollection(); |
200
|
|
|
$this->signatures = new ArrayCollection(); |
201
|
|
|
$this->anomalies = new ArrayCollection(); |
202
|
|
|
$this->wormholeEntries = new ArrayCollection(); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function getId(): int |
206
|
|
|
{ |
207
|
|
|
return $this->id; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function getCx(): int |
211
|
|
|
{ |
212
|
|
|
return $this->cx; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public function setCx(int $cx): MapInterface |
216
|
|
|
{ |
217
|
|
|
$this->cx = $cx; |
218
|
|
|
return $this; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
public function getX(): int |
222
|
|
|
{ |
223
|
|
|
return $this->getCx(); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
public function getCy(): int |
227
|
|
|
{ |
228
|
|
|
return $this->cy; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
public function setCy(int $cy): MapInterface |
232
|
|
|
{ |
233
|
|
|
$this->cy = $cy; |
234
|
|
|
return $this; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
public function getY(): int |
238
|
|
|
{ |
239
|
|
|
return $this->getCy(); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
public function getFieldId(): int |
243
|
|
|
{ |
244
|
|
|
return $this->field_id; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
public function setFieldId(int $fieldId): MapInterface |
248
|
|
|
{ |
249
|
|
|
$this->field_id = $fieldId; |
250
|
|
|
return $this; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
public function getSystemsId(): ?int |
254
|
|
|
{ |
255
|
|
|
return $this->systems_id; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
public function setSystemsId(?int $systems_id): MapInterface |
259
|
|
|
{ |
260
|
|
|
$this->systems_id = $systems_id; |
261
|
|
|
return $this; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
public function getSystemTypeId(): ?int |
265
|
|
|
{ |
266
|
|
|
return $this->system_type_id; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
public function setSystemTypeId(?int $system_type_id): MapInterface |
270
|
|
|
{ |
271
|
|
|
$this->system_type_id = $system_type_id; |
272
|
|
|
return $this; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
public function getInfluenceAreaId(): ?int |
276
|
|
|
{ |
277
|
|
|
return $this->influence_area_id; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
public function setInfluenceAreaId(?int $influenceAreaId): MapInterface |
281
|
|
|
{ |
282
|
|
|
$this->influence_area_id = $influenceAreaId; |
283
|
|
|
return $this; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
public function getBordertypeId(): ?int |
287
|
|
|
{ |
288
|
|
|
return $this->bordertype_id; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
public function setBordertypeId(?int $bordertype_id): MapInterface |
292
|
|
|
{ |
293
|
|
|
$this->bordertype_id = $bordertype_id; |
294
|
|
|
return $this; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
public function getRegionId(): ?int |
298
|
|
|
{ |
299
|
|
|
return $this->region_id; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
public function setRegionId(?int $region_id): MapInterface |
303
|
|
|
{ |
304
|
|
|
$this->region_id = $region_id; |
305
|
|
|
return $this; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
public function getAdminRegionId(): ?int |
309
|
|
|
{ |
310
|
|
|
return $this->admin_region_id; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
public function setAdminRegionId(?int $admin_region_id): MapInterface |
314
|
|
|
{ |
315
|
|
|
$this->admin_region_id = $admin_region_id; |
316
|
|
|
return $this; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
public function getLayer(): LayerInterface |
320
|
|
|
{ |
321
|
|
|
return $this->layer; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
public function getSystem(): ?StarSystemInterface |
325
|
|
|
{ |
326
|
|
|
return $this->starSystem; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
public function setSystem(StarSystemInterface $starSystem): MapInterface |
330
|
|
|
{ |
331
|
|
|
$this->starSystem = $starSystem; |
332
|
|
|
return $this; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
public function getInfluenceArea(): ?StarSystemInterface |
336
|
|
|
{ |
337
|
|
|
return $this->influenceArea; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
public function setInfluenceArea(?StarSystemInterface $influenceArea): MapInterface |
341
|
|
|
{ |
342
|
|
|
$this->influenceArea = $influenceArea; |
343
|
|
|
return $this; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
public function getFieldType(): MapFieldTypeInterface |
347
|
|
|
{ |
348
|
|
|
return $this->mapFieldType; |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
public function getStarSystemType(): ?StarSystemTypeInterface |
352
|
|
|
{ |
353
|
|
|
return $this->starSystemType; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
public function getMapBorderType(): ?MapBorderTypeInterface |
357
|
|
|
{ |
358
|
|
|
return $this->mapBorderType; |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
public function getMapRegion(): ?MapRegionInterface |
362
|
|
|
{ |
363
|
|
|
return $this->mapRegion; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
public function getAdministratedRegion(): ?MapRegionInterface |
367
|
|
|
{ |
368
|
|
|
return $this->administratedRegion; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
public function getBorder(): string |
372
|
|
|
{ |
373
|
|
|
$borderType = $this->getMapBorderType(); |
374
|
|
|
if ($borderType === null) { |
375
|
|
|
return ''; |
376
|
|
|
} |
377
|
|
|
return 'border: 1px solid ' . $borderType->getColor(); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
public function getFieldStyle(): string |
381
|
|
|
{ |
382
|
|
|
// @todo hide unexplored fields |
383
|
|
|
$style = "background-image: url('/assets/map/" . $this->getLayer()->getId() . "/" . $this->getFieldId() . ".png'); opacity:1;"; |
384
|
|
|
return $style . $this->getBorder(); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
public function getShips(): Collection |
388
|
|
|
{ |
389
|
|
|
return $this->ships; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
public function getAnomalies(): Collection |
393
|
|
|
{ |
394
|
|
|
return $this->anomalies; |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
public function getSignatures(): Collection |
398
|
|
|
{ |
399
|
|
|
return $this->signatures; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
public function getRandomWormholeEntry(): ?WormholeEntryInterface |
403
|
|
|
{ |
404
|
|
|
if ($this->wormholeEntries->isEmpty()) { |
405
|
|
|
return null; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
$usableEntries = array_filter( |
409
|
|
|
$this->wormholeEntries->toArray(), |
410
|
|
|
function (WormholeEntryInterface $entry): bool { |
411
|
|
|
$type = $entry->getType(); |
412
|
|
|
|
413
|
|
|
return $entry->isUsable() && ($type === MapEnum::WORMHOLE_ENTRY_TYPE_BOTH || |
414
|
|
|
$type === MapEnum::WORMHOLE_ENTRY_TYPE_IN); |
415
|
|
|
} |
416
|
|
|
); |
417
|
|
|
|
418
|
|
|
return $usableEntries === [] ? null : $usableEntries[array_rand($usableEntries)]; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
public function getSectorString(): string |
422
|
|
|
{ |
423
|
|
|
return SectorString::getForMap($this); |
424
|
|
|
} |
425
|
|
|
} |