1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Lib\Ui; |
6
|
|
|
|
7
|
|
|
use Stu\Component\Ship\ShipRumpEnum; |
8
|
|
|
use Stu\Lib\Map\Location; |
9
|
|
|
use Stu\Lib\Map\VisualPanel\AbstractVisualPanel; |
10
|
|
|
use Stu\Lib\Map\VisualPanel\Layer\DataProvider\Shipcount\ShipcountLayerTypeEnum; |
11
|
|
|
use Stu\Lib\Map\VisualPanel\Layer\DataProvider\Subspace\SubspaceLayerTypeEnum; |
12
|
|
|
use Stu\Lib\Map\VisualPanel\Layer\PanelLayerCreationInterface; |
13
|
|
|
use Stu\Lib\Map\VisualPanel\PanelBoundaries; |
14
|
|
|
use Stu\Lib\Map\VisualPanel\VisualNavPanelEntry; |
15
|
|
|
use Stu\Module\Logging\LoggerUtilInterface; |
16
|
|
|
use Stu\Orm\Entity\MapInterface; |
17
|
|
|
use Stu\Orm\Entity\ShipInterface; |
18
|
|
|
use Stu\Orm\Entity\UserInterface; |
19
|
|
|
use Stu\Orm\Repository\UserMapRepositoryInterface; |
20
|
|
|
|
21
|
|
|
class VisualNavPanel extends AbstractVisualPanel |
22
|
|
|
{ |
23
|
|
|
private ShipInterface $currentShip; |
24
|
|
|
|
25
|
|
|
private UserInterface $user; |
26
|
|
|
|
27
|
|
|
private bool $tachyonFresh; |
28
|
|
|
|
29
|
|
|
private UserMapRepositoryInterface $userMapRepository; |
30
|
|
|
|
31
|
|
|
private ?Location $panelCenter = null; |
32
|
|
|
|
33
|
|
|
private ?bool $isOnShipLevel = null; |
34
|
|
|
|
35
|
1 |
|
public function __construct( |
36
|
|
|
PanelLayerCreationInterface $panelLayerCreation, |
37
|
|
|
UserMapRepositoryInterface $userMapRepository, |
38
|
|
|
ShipInterface $currentShip, |
39
|
|
|
UserInterface $user, |
40
|
|
|
LoggerUtilInterface $loggerUtil, |
41
|
|
|
bool $tachyonFresh |
42
|
|
|
) { |
43
|
1 |
|
parent::__construct($panelLayerCreation, $loggerUtil); |
44
|
|
|
|
45
|
1 |
|
$this->userMapRepository = $userMapRepository; |
46
|
1 |
|
$this->currentShip = $currentShip; |
47
|
1 |
|
$this->user = $user; |
48
|
1 |
|
$this->tachyonFresh = $tachyonFresh; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function createBoundaries(): PanelBoundaries |
52
|
|
|
{ |
53
|
|
|
return PanelBoundaries::fromLocation($this->getPanelCenter(), $this->currentShip->getSensorRange()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function loadLayers(): void |
57
|
|
|
{ |
58
|
|
|
|
59
|
|
|
$panelLayerCreation = $this->panelLayerCreation |
60
|
|
|
->addShipCountLayer($this->tachyonFresh, $this->currentShip, ShipcountLayerTypeEnum::ALL, 0) |
61
|
|
|
->addBorderLayer($this->currentShip, $this->isOnShipLevel()); |
62
|
|
|
|
63
|
|
|
$map = $this->getPanelCenter()->get(); |
64
|
|
|
|
65
|
|
|
if ($map instanceof MapInterface) { |
66
|
|
|
$panelLayerCreation->addMapLayer($map->getLayer()); |
67
|
|
|
$this->createUserMapEntries(); |
68
|
|
|
} else { |
69
|
|
|
$panelLayerCreation |
70
|
|
|
->addSystemLayer() |
71
|
|
|
->addColonyShieldLayer(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if ($this->currentShip->getSubspaceState()) { |
75
|
|
|
$panelLayerCreation->addSubspaceLayer($this->user->getId(), SubspaceLayerTypeEnum::IGNORE_USER); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$this->layers = $panelLayerCreation->build($this); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
protected function getEntryCallable(): callable |
82
|
|
|
{ |
83
|
|
|
return fn (int $x, int $y) => new VisualNavPanelEntry( |
84
|
|
|
$x, |
85
|
|
|
$y, |
86
|
|
|
$this->isOnShipLevel(), |
87
|
|
|
$this->layers, |
88
|
|
|
$this->currentShip |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
protected function getPanelViewportPercentage(): int |
93
|
|
|
{ |
94
|
|
|
return $this->currentShip->isBase() ? 50 : 33; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
private function isOnShipLevel(): bool |
98
|
|
|
{ |
99
|
|
|
if ($this->isOnShipLevel === null) { |
100
|
|
|
$this->isOnShipLevel = $this->currentShip->getLocation()->get() === $this->getPanelCenter()->get(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $this->isOnShipLevel; |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
private function getPanelCenter(): Location |
107
|
|
|
{ |
108
|
|
|
if ($this->panelCenter === null) { |
109
|
|
|
$this->panelCenter = $this->determinePanelCenter(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $this->panelCenter; |
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
private function determinePanelCenter(): Location |
116
|
|
|
{ |
117
|
|
|
$map = $this->currentShip->getCurrentMapField(); |
118
|
|
|
if ($map instanceof MapInterface) { |
119
|
|
|
return new Location($map, null); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if ( |
123
|
|
|
$this->currentShip->getRump()->getRoleId() === ShipRumpEnum::SHIP_ROLE_SENSOR |
124
|
|
|
|| $this->currentShip->getRump()->getRoleId() === ShipRumpEnum::SHIP_ROLE_BASE |
125
|
|
|
) { |
126
|
|
|
$mapOfSystem = $map->getSystem()->getMapField(); |
127
|
|
|
|
128
|
|
|
return $mapOfSystem === null ? new Location(null, $map) : new Location($mapOfSystem, null); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return new Location(null, $map); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
private function createUserMapEntries(): void |
135
|
|
|
{ |
136
|
|
|
$cx = $this->currentShip->getCX(); |
137
|
|
|
$cy = $this->currentShip->getCY(); |
138
|
|
|
$range = $this->currentShip->getSensorRange(); |
139
|
|
|
|
140
|
|
|
$layerId = $this->currentShip->getLayerId(); |
141
|
|
|
if ($this->isUserMapActive($layerId)) { |
142
|
|
|
$this->userMapRepository->insertMapFieldsForUser( |
143
|
|
|
$this->user->getId(), |
144
|
|
|
$layerId, |
145
|
|
|
$cx, |
146
|
|
|
$cy, |
147
|
|
|
$range |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
private function isUserMapActive(int $layerId): bool |
153
|
|
|
{ |
154
|
|
|
if (!$this->user->hasColony()) { |
155
|
|
|
return false; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
return !$this->user->hasExplored($layerId); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|