1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Lib\Map\VisualPanel\LssBlockade; |
6
|
|
|
|
7
|
|
|
use Stu\Lib\Map\FieldTypeEffectEnum; |
8
|
|
|
use Stu\Lib\Map\VisualPanel\AbstractVisualPanel; |
9
|
|
|
use Stu\Lib\Map\VisualPanel\PanelBoundaries; |
10
|
|
|
use Stu\Orm\Entity\Location; |
11
|
|
|
use Stu\Orm\Repository\MapRepositoryInterface; |
12
|
|
|
use Stu\Orm\Repository\StarSystemMapRepositoryInterface; |
13
|
|
|
|
14
|
|
|
class LssBlockadeGridFactory |
15
|
|
|
{ |
16
|
2 |
|
public function __construct( |
17
|
|
|
private readonly MapRepositoryInterface $mapRepository, |
18
|
|
|
private readonly StarSystemMapRepositoryInterface $starSystemMapRepository |
19
|
2 |
|
) {} |
20
|
|
|
|
21
|
5 |
|
public function createLssBlockadeGrid(Location $observerLocation, AbstractVisualPanel $panel): LssBlockadeGrid |
22
|
|
|
{ |
23
|
5 |
|
$boundaries = $panel->getBoundaries(); |
24
|
|
|
|
25
|
5 |
|
$blockadeGrid = new LssBlockadeGrid( |
26
|
5 |
|
$boundaries->getMinX(), |
27
|
5 |
|
$boundaries->getMaxX(), |
28
|
5 |
|
$boundaries->getMinY(), |
29
|
5 |
|
$boundaries->getMaxY(), |
30
|
5 |
|
$observerLocation->getX(), |
31
|
5 |
|
$observerLocation->getY() |
32
|
5 |
|
); |
33
|
|
|
|
34
|
5 |
|
$blockedLocations = $this->getBlockedCoords($boundaries); |
35
|
|
|
|
36
|
5 |
|
array_walk( |
37
|
5 |
|
$blockedLocations, |
38
|
5 |
|
function (array $entry) use ($blockadeGrid): void { |
39
|
1 |
|
$blockadeGrid->setBlocked($entry['x'], $entry['y']); |
40
|
5 |
|
} |
41
|
5 |
|
); |
42
|
|
|
|
43
|
5 |
|
return $blockadeGrid; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** @return array< array{x: int, y: int, effects: ?string}> */ |
|
|
|
|
47
|
5 |
|
private function getBlockedCoords(PanelBoundaries $boundaries): array |
48
|
|
|
{ |
49
|
5 |
|
$locations = $boundaries->isOnMap() |
50
|
1 |
|
? $this->mapRepository->getLssBlockadeLocations($boundaries) |
51
|
4 |
|
: $this->starSystemMapRepository->getLssBlockadeLocations($boundaries); |
52
|
|
|
|
53
|
5 |
|
return array_filter( |
54
|
5 |
|
$locations, |
55
|
5 |
|
fn(array $entry): bool => $entry['effects'] !== null && str_contains($entry['effects'], FieldTypeEffectEnum::LSS_BLOCKADE->value) |
56
|
5 |
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|