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\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
13
|
|
|
use Stu\Orm\Entity\LayerInterface; |
14
|
|
|
use Stu\Orm\Entity\LocationInterface; |
15
|
|
|
use Stu\Orm\Entity\MapInterface; |
16
|
|
|
use Stu\Orm\Entity\UserInterface; |
17
|
|
|
use Stu\Orm\Repository\UserMapRepositoryInterface; |
18
|
|
|
|
19
|
|
|
class PanelLayerConfiguration |
20
|
|
|
{ |
21
|
1 |
|
public function __construct(private UserMapRepositoryInterface $userMapRepository) {} |
22
|
|
|
|
23
|
1 |
|
public function configureLayers( |
24
|
|
|
PanelLayerCreationInterface $panelLayerCreation, |
25
|
|
|
SpacecraftWrapperInterface $wrapper, |
26
|
|
|
LocationInterface $panelCenter, |
27
|
|
|
UserInterface $currentUser, |
28
|
|
|
bool $tachyonFresh, |
29
|
|
|
bool $isShipOnLevel |
30
|
|
|
): void { |
31
|
|
|
|
32
|
1 |
|
$spacecraft = $wrapper->get(); |
33
|
|
|
|
34
|
1 |
|
if ($wrapper->get()->getSubspaceState()) { |
35
|
|
|
$panelLayerCreation->addSubspaceLayer($currentUser->getId(), SubspaceLayerTypeEnum::IGNORE_USER); |
36
|
|
|
} |
37
|
|
|
|
38
|
1 |
|
$isLssMalfunctioning = $spacecraft->getLocation()->getFieldType()->hasEffect(FieldTypeEffectEnum::LSS_MALFUNCTION); |
39
|
1 |
|
if ($isLssMalfunctioning) { |
40
|
|
|
return; |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
$panelLayerCreation |
44
|
1 |
|
->addShipCountLayer($tachyonFresh, $spacecraft, SpacecraftCountLayerTypeEnum::ALL, 0) |
45
|
1 |
|
->addBorderLayer($wrapper->get(), $isShipOnLevel) |
46
|
1 |
|
->addAnomalyLayer(); |
47
|
|
|
|
48
|
1 |
|
if ($panelCenter instanceof MapInterface) { |
49
|
1 |
|
$layer = $panelCenter->getLayer(); |
50
|
1 |
|
if ($layer === null) { |
51
|
|
|
throw new RuntimeException('this should not happen'); |
52
|
|
|
} |
53
|
1 |
|
$panelLayerCreation->addMapLayer($layer); |
54
|
1 |
|
$this->createUserMapEntries($wrapper, $layer, $currentUser); |
55
|
|
|
} else { |
56
|
|
|
$panelLayerCreation |
57
|
|
|
->addSystemLayer() |
58
|
|
|
->addColonyShieldLayer(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
private function createUserMapEntries(SpacecraftWrapperInterface $wrapper, LayerInterface $layer, UserInterface $currentUser): void |
63
|
|
|
{ |
64
|
1 |
|
$map = $wrapper->get()->getMap(); |
65
|
1 |
|
if ($map === null) { |
66
|
|
|
return; |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
$cx = $map->getX(); |
70
|
1 |
|
$cy = $map->getY(); |
71
|
1 |
|
$range = $wrapper->getSensorRange(); |
72
|
|
|
|
73
|
1 |
|
if ($this->isUserMapActive($layer->getId(), $currentUser)) { |
74
|
1 |
|
$this->userMapRepository->insertMapFieldsForUser( |
75
|
1 |
|
$currentUser->getId(), |
76
|
1 |
|
$layer->getId(), |
77
|
1 |
|
$cx, |
78
|
1 |
|
$cy, |
79
|
1 |
|
$range |
80
|
1 |
|
); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
private function isUserMapActive(int $layerId, UserInterface $currentUser): bool |
85
|
|
|
{ |
86
|
1 |
|
if (!$currentUser->hasColony()) { |
87
|
|
|
return false; |
88
|
|
|
} |
89
|
|
|
|
90
|
1 |
|
return !$currentUser->hasExplored($layerId); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|