|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Lib\Map\VisualPanel\Layer\Render; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
|
|
8
|
|
|
use Stu\Lib\Map\VisualPanel\Layer\Data\CellDataInterface; |
|
9
|
|
|
use Stu\Lib\Map\VisualPanel\Layer\Data\AbstractSubspaceData; |
|
10
|
|
|
use Stu\Lib\Map\VisualPanel\PanelAttributesInterface; |
|
11
|
|
|
|
|
12
|
|
|
final class SubspaceLayerRenderer implements LayerRendererInterface |
|
13
|
|
|
{ |
|
14
|
5 |
|
public function __construct( |
|
15
|
|
|
private readonly int $zIndex, |
|
16
|
|
|
private readonly bool $isInverted = false |
|
17
|
5 |
|
) {} |
|
18
|
|
|
|
|
19
|
|
|
/** @param AbstractSubspaceData $data */ |
|
20
|
5 |
|
#[Override] |
|
21
|
|
|
public function render(CellDataInterface $data, PanelAttributesInterface $panel): string |
|
22
|
|
|
{ |
|
23
|
5 |
|
if ($data->isDisabled()) { |
|
|
|
|
|
|
24
|
1 |
|
return ''; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
4 |
|
$subspaceCode = $this->getSubspaceCode($data); |
|
28
|
4 |
|
if ($subspaceCode === null) { |
|
29
|
2 |
|
return ''; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
3 |
|
return sprintf( |
|
33
|
3 |
|
'<img src="/assets/subspace/generated/%s.png" class="visualPanelLayer%s" |
|
34
|
3 |
|
style="z-index: %d; %s" />', |
|
35
|
3 |
|
$subspaceCode, |
|
36
|
3 |
|
$this->isInverted ? ' inverted' : '', |
|
37
|
3 |
|
$this->zIndex, |
|
38
|
3 |
|
$panel->getHeightAndWidth() |
|
39
|
3 |
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
4 |
|
private function getSubspaceCode(AbstractSubspaceData $data): ?string |
|
43
|
|
|
{ |
|
44
|
4 |
|
if (!$this->isSubspaceCodeAvailable($data)) { |
|
45
|
2 |
|
return null; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
3 |
|
return sprintf( |
|
49
|
3 |
|
'%d%d%d%d', |
|
50
|
3 |
|
$this->getCode($data->getDirection1Count()), |
|
51
|
3 |
|
$this->getCode($data->getDirection2Count()), |
|
52
|
3 |
|
$this->getCode($data->getDirection3Count()), |
|
53
|
3 |
|
$this->getCode($data->getDirection4Count()) |
|
54
|
3 |
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
4 |
|
private function isSubspaceCodeAvailable(AbstractSubspaceData $data): bool |
|
58
|
|
|
{ |
|
59
|
4 |
|
return $data->getDirection1Count() > 0 |
|
60
|
4 |
|
|| $data->getDirection2Count() > 0 |
|
61
|
4 |
|
|| $data->getDirection3Count() > 0 |
|
62
|
4 |
|
|| $data->getDirection4Count() > 0; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
3 |
|
private function getCode(int $shipCount): int |
|
66
|
|
|
{ |
|
67
|
3 |
|
if ($shipCount == 0) { |
|
68
|
1 |
|
return 0; |
|
69
|
|
|
} |
|
70
|
3 |
|
if ($shipCount == 1) { |
|
71
|
2 |
|
return 1; |
|
72
|
|
|
} |
|
73
|
3 |
|
if ($shipCount < 6) { |
|
74
|
3 |
|
return 2; |
|
75
|
|
|
} |
|
76
|
2 |
|
if ($shipCount < 11) { |
|
77
|
2 |
|
return 3; |
|
78
|
|
|
} |
|
79
|
2 |
|
if ($shipCount < 21) { |
|
80
|
2 |
|
return 4; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
1 |
|
return 5; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths