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
|
4 |
|
public function __construct( |
15
|
|
|
private readonly int $zIndex, |
16
|
|
|
private readonly bool $isInverted = false |
17
|
4 |
|
) {} |
18
|
|
|
|
19
|
|
|
/** @param AbstractSubspaceData $data */ |
20
|
4 |
|
#[Override] |
21
|
|
|
public function render(CellDataInterface $data, PanelAttributesInterface $panel): string |
22
|
|
|
{ |
23
|
4 |
|
if ($data->isDisabled()) { |
|
|
|
|
24
|
1 |
|
return ''; |
25
|
|
|
} |
26
|
|
|
|
27
|
3 |
|
$subspaceCode = $this->getSubspaceCode($data); |
28
|
3 |
|
if ($subspaceCode === null) { |
29
|
1 |
|
return ''; |
30
|
|
|
} |
31
|
|
|
|
32
|
2 |
|
return sprintf( |
33
|
2 |
|
'<img src="/assets/subspace/generated/%s.png" class="visualPanelLayer%s" |
34
|
2 |
|
style="z-index: %d; %s" />', |
35
|
2 |
|
$subspaceCode, |
36
|
2 |
|
$this->isInverted ? ' inverted' : '', |
37
|
2 |
|
$this->zIndex, |
38
|
2 |
|
$panel->getHeightAndWidth() |
39
|
2 |
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
3 |
|
private function getSubspaceCode(AbstractSubspaceData $data): ?string |
43
|
|
|
{ |
44
|
3 |
|
if (!$this->isSubspaceCodeAvailable($data)) { |
45
|
1 |
|
return null; |
46
|
|
|
} |
47
|
|
|
|
48
|
2 |
|
return sprintf( |
49
|
2 |
|
'%d%d%d%d', |
50
|
2 |
|
$this->getCode($data->getDirection1Count()), |
51
|
2 |
|
$this->getCode($data->getDirection2Count()), |
52
|
2 |
|
$this->getCode($data->getDirection3Count()), |
53
|
2 |
|
$this->getCode($data->getDirection4Count()) |
54
|
2 |
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
3 |
|
private function isSubspaceCodeAvailable(AbstractSubspaceData $data): bool |
58
|
|
|
{ |
59
|
3 |
|
return $data->getDirection1Count() > 0 |
60
|
3 |
|
|| $data->getDirection2Count() > 0 |
61
|
3 |
|
|| $data->getDirection3Count() > 0 |
62
|
3 |
|
|| $data->getDirection4Count() > 0; |
63
|
|
|
} |
64
|
|
|
|
65
|
2 |
|
private function getCode(int $shipCount): int |
66
|
|
|
{ |
67
|
2 |
|
if ($shipCount == 0) { |
68
|
|
|
return 0; |
69
|
|
|
} |
70
|
2 |
|
if ($shipCount == 1) { |
71
|
1 |
|
return 1; |
72
|
|
|
} |
73
|
2 |
|
if ($shipCount < 6) { |
74
|
2 |
|
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