|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Lib\Map\VisualPanel\Layer; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
8
|
|
|
use Doctrine\Common\Collections\Collection; |
|
9
|
|
|
use Stu\Lib\Map\VisualPanel\AbstractVisualPanel; |
|
10
|
|
|
use Stu\Lib\Map\VisualPanel\LssBlockade\LssBlockadeGrid; |
|
11
|
|
|
|
|
12
|
|
|
class PanelLayers |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var Collection<int, PanelLayer> */ |
|
15
|
|
|
private Collection $layers; |
|
16
|
|
|
|
|
17
|
|
|
private ?PanelLayer $borderLayer = null; |
|
18
|
|
|
|
|
19
|
5 |
|
public function __construct( |
|
20
|
|
|
private readonly AbstractVisualPanel $panel, |
|
21
|
|
|
private readonly ?LssBlockadeGrid $lssBlockadeGrid |
|
22
|
|
|
) { |
|
23
|
5 |
|
$this->layers = new ArrayCollection(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
5 |
|
public function addLayer(PanelLayerEnum $type, PanelLayer $layer): void |
|
27
|
|
|
{ |
|
28
|
5 |
|
if ($type === PanelLayerEnum::BORDER) { |
|
29
|
1 |
|
$this->borderLayer = $layer; |
|
30
|
|
|
} else { |
|
31
|
5 |
|
$this->layers[$type->value] = $layer; |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** @return array<string> */ |
|
36
|
5 |
|
public function getRenderedCellLayers(int $x, int $y): array |
|
37
|
|
|
{ |
|
38
|
5 |
|
return $this->layers |
|
39
|
5 |
|
->filter(fn(PanelLayer $layer, int $type): bool => $this->isLayerVisible($type, $x, $y)) |
|
40
|
5 |
|
->map(fn(PanelLayer $layer): string => $layer->renderCell($x, $y, $this->panel)) |
|
41
|
5 |
|
->toArray(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
5 |
|
private function isLayerVisible(int $type, int $x, int $y): bool |
|
45
|
|
|
{ |
|
46
|
5 |
|
if ($this->lssBlockadeGrid === null) { |
|
47
|
|
|
return true; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
5 |
|
return !PanelLayerEnum::from($type)->isAffectedByLssBlockade() |
|
51
|
5 |
|
|| $this->lssBlockadeGrid->isVisible($x, $y); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
5 |
|
public function getCellBorder(int $x, int $y): string |
|
55
|
|
|
{ |
|
56
|
5 |
|
if ($this->borderLayer === null) { |
|
57
|
4 |
|
return ''; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
return $this->borderLayer->renderCell($x, $y, $this->panel); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|