|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Spacecraft\Lib\Ui; |
|
6
|
|
|
|
|
7
|
|
|
use RuntimeException; |
|
8
|
|
|
use Stu\Lib\Map\FieldTypeEffectEnum; |
|
9
|
|
|
use Stu\Lib\Map\VisualPanel\Layer\DataProvider\Spacecraftcount\SpacecraftCountLayerTypeEnum; |
|
10
|
|
|
use Stu\Lib\Map\VisualPanel\Layer\DataProvider\Subspace\SubspaceLayerTypeEnum; |
|
11
|
|
|
use Stu\Lib\Map\VisualPanel\Layer\PanelLayerCreationInterface; |
|
12
|
|
|
use Stu\Lib\Trait\LayerExplorationTrait; |
|
13
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
|
14
|
|
|
use Stu\Orm\Entity\Layer; |
|
15
|
|
|
use Stu\Orm\Entity\Location; |
|
16
|
|
|
use Stu\Orm\Entity\Map; |
|
17
|
|
|
use Stu\Orm\Entity\User; |
|
18
|
|
|
use Stu\Orm\Repository\UserMapRepositoryInterface; |
|
19
|
|
|
|
|
20
|
|
|
class PanelLayerConfiguration |
|
21
|
|
|
{ |
|
22
|
|
|
use LayerExplorationTrait; |
|
23
|
|
|
|
|
24
|
1 |
|
public function __construct(private UserMapRepositoryInterface $userMapRepository) {} |
|
25
|
|
|
|
|
26
|
1 |
|
public function configureLayers( |
|
27
|
|
|
PanelLayerCreationInterface $panelLayerCreation, |
|
28
|
|
|
SpacecraftWrapperInterface $wrapper, |
|
29
|
|
|
Location $panelCenter, |
|
30
|
|
|
User $currentUser, |
|
31
|
|
|
bool $tachyonFresh, |
|
32
|
|
|
bool $isShipOnLevel |
|
33
|
|
|
): void { |
|
34
|
|
|
|
|
35
|
1 |
|
$spacecraft = $wrapper->get(); |
|
36
|
1 |
|
if ($wrapper->get()->getSubspaceState()) { |
|
37
|
|
|
$panelLayerCreation->addSubspaceLayer($currentUser->getId(), SubspaceLayerTypeEnum::IGNORE_USER); |
|
38
|
|
|
$this->checkAndAddSpacecraftSignature($wrapper, $panelLayerCreation); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
1 |
|
$isLssMalfunctioning = $spacecraft->getLocation()->getFieldType()->hasEffect(FieldTypeEffectEnum::LSS_MALFUNCTION); |
|
42
|
1 |
|
if ($isLssMalfunctioning) { |
|
43
|
|
|
return; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
$panelLayerCreation |
|
47
|
1 |
|
->addShipCountLayer($tachyonFresh, $spacecraft, SpacecraftCountLayerTypeEnum::ALL, 0) |
|
48
|
1 |
|
->addBorderLayer($wrapper, $isShipOnLevel) |
|
49
|
1 |
|
->addAnomalyLayer(); |
|
50
|
|
|
|
|
51
|
1 |
|
if ($panelCenter instanceof Map) { |
|
52
|
1 |
|
$layer = $panelCenter->getLayer(); |
|
53
|
1 |
|
if ($layer === null) { |
|
54
|
|
|
throw new RuntimeException('this should not happen'); |
|
55
|
|
|
} |
|
56
|
1 |
|
$panelLayerCreation->addMapLayer($layer); |
|
57
|
1 |
|
$this->createUserMapEntries($wrapper, $layer, $currentUser); |
|
58
|
|
|
} else { |
|
59
|
|
|
$panelLayerCreation |
|
60
|
|
|
->addSystemLayer() |
|
61
|
|
|
->addColonyShieldLayer(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
private function createUserMapEntries(SpacecraftWrapperInterface $wrapper, Layer $layer, User $currentUser): void |
|
66
|
|
|
{ |
|
67
|
1 |
|
$map = $wrapper->get()->getMap(); |
|
68
|
1 |
|
if ($map === null) { |
|
69
|
|
|
return; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
1 |
|
$cx = $map->getX(); |
|
73
|
1 |
|
$cy = $map->getY(); |
|
74
|
1 |
|
$range = $wrapper->getLssSystemData()?->getSensorRange() ?? 0; |
|
75
|
|
|
|
|
76
|
1 |
|
if ($this->isUserMapActive($layer, $currentUser)) { |
|
77
|
1 |
|
$this->userMapRepository->insertMapFieldsForUser( |
|
78
|
1 |
|
$currentUser->getId(), |
|
79
|
1 |
|
$layer->getId(), |
|
80
|
1 |
|
$cx, |
|
81
|
1 |
|
$cy, |
|
82
|
1 |
|
$range |
|
83
|
1 |
|
); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
1 |
|
private function isUserMapActive(Layer $layer, User $currentUser): bool |
|
87
|
|
|
{ |
|
88
|
1 |
|
if (!$currentUser->hasColony()) { |
|
89
|
|
|
return false; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
1 |
|
return !$this->hasExplored($currentUser, $layer); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
private function checkAndAddSpacecraftSignature( |
|
96
|
|
|
SpacecraftWrapperInterface $wrapper, |
|
97
|
|
|
PanelLayerCreationInterface $panelLayerCreation |
|
98
|
|
|
): void { |
|
99
|
|
|
|
|
100
|
|
|
$subspaceSystemData = $wrapper->getSubspaceSystemData(); |
|
101
|
|
|
if ($subspaceSystemData === null) { |
|
102
|
|
|
return; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
$flightSig = $subspaceSystemData->getHighlightedFlightSig($wrapper->get()); |
|
106
|
|
|
if ($flightSig) { |
|
107
|
|
|
$spacecraftId = $flightSig->getShipId(); |
|
108
|
|
|
$rumpId = $flightSig->getRump()->getId(); |
|
109
|
|
|
$panelLayerCreation->addSpacecraftSignatureLayer($spacecraftId, $rumpId); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|