|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Lib\Map\VisualPanel; |
|
6
|
|
|
|
|
7
|
|
|
use Stu\Component\Map\EncodedMapInterface; |
|
8
|
|
|
use Stu\Orm\Entity\LayerInterface; |
|
9
|
|
|
|
|
10
|
|
|
class SignaturePanelEntry implements VisualPanelElementInterface |
|
11
|
|
|
{ |
|
12
|
|
|
protected VisualPanelEntryData $data; |
|
13
|
|
|
|
|
14
|
|
|
private ?LayerInterface $layer; |
|
15
|
|
|
|
|
16
|
|
|
private ?EncodedMapInterface $encodedMap; |
|
17
|
|
|
|
|
18
|
|
|
private string $cssClass = 'lss'; |
|
19
|
|
|
|
|
20
|
7 |
|
public function __construct( |
|
21
|
|
|
VisualPanelEntryData $data, |
|
22
|
|
|
?LayerInterface $layer, |
|
23
|
|
|
?EncodedMapInterface $encodedMap |
|
24
|
|
|
) { |
|
25
|
7 |
|
$this->data = $data; |
|
26
|
7 |
|
$this->layer = $layer; |
|
27
|
7 |
|
$this->encodedMap = $encodedMap; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
6 |
|
public function getCellData(): MapCellData|SystemCellData |
|
31
|
|
|
{ |
|
32
|
6 |
|
if ($this->data->getSystemId() === null) { |
|
33
|
2 |
|
return new MapCellData( |
|
34
|
2 |
|
$this->getMapGraphicPath(), |
|
35
|
2 |
|
$this->getSubspaceCode(), |
|
36
|
2 |
|
$this->getDisplayCount(), |
|
37
|
2 |
|
); |
|
38
|
|
|
} |
|
39
|
4 |
|
return new SystemCellData( |
|
40
|
4 |
|
$this->data->getPosX(), |
|
41
|
4 |
|
$this->data->getPosY(), |
|
42
|
4 |
|
$this->data->getMapfieldType(), |
|
43
|
4 |
|
$this->data->getShieldState(), |
|
44
|
4 |
|
$this->getSubspaceCode(), |
|
45
|
4 |
|
$this->getDisplayCount(), |
|
46
|
4 |
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
2 |
|
private function getMapGraphicPath(): ?string |
|
50
|
|
|
{ |
|
51
|
2 |
|
$layer = $this->layer; |
|
52
|
2 |
|
if ($layer === null) { |
|
53
|
|
|
return null; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
2 |
|
$encodedMap = $this->encodedMap; |
|
57
|
2 |
|
if ($layer->isEncoded() && $encodedMap !== null) { |
|
58
|
|
|
|
|
59
|
1 |
|
return $encodedMap->getEncodedMapPath( |
|
60
|
1 |
|
$this->data->getMapfieldType(), |
|
61
|
1 |
|
$layer |
|
62
|
1 |
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
return sprintf('%d/%d.png', $layer->getId(), $this->data->getMapfieldType()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
6 |
|
private function getSubspaceCode(): ?string |
|
69
|
|
|
{ |
|
70
|
6 |
|
if (!$this->data->isSubspaceCodeAvailable()) { |
|
71
|
2 |
|
return null; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
4 |
|
return sprintf( |
|
75
|
4 |
|
'%d%d%d%d', |
|
76
|
4 |
|
$this->getCode($this->data->getDirection1Count()), |
|
77
|
4 |
|
$this->getCode($this->data->getDirection2Count()), |
|
78
|
4 |
|
$this->getCode($this->data->getDirection3Count()), |
|
79
|
4 |
|
$this->getCode($this->data->getDirection4Count()) |
|
80
|
4 |
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
4 |
|
private function getCode(int $shipCount): int |
|
84
|
|
|
{ |
|
85
|
|
|
//TODO use constant values |
|
86
|
4 |
|
if ($shipCount == 0) { |
|
87
|
|
|
return 0; |
|
88
|
|
|
} |
|
89
|
4 |
|
if ($shipCount == 1) { |
|
90
|
4 |
|
return 1; |
|
91
|
|
|
} |
|
92
|
4 |
|
if ($shipCount < 6) { |
|
93
|
4 |
|
return 2; |
|
94
|
|
|
} |
|
95
|
|
|
if ($shipCount < 11) { |
|
96
|
|
|
return 3; |
|
97
|
|
|
} |
|
98
|
|
|
if ($shipCount < 21) { |
|
99
|
|
|
return 4; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return 5; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
6 |
|
protected function getDisplayCount(): ?string |
|
106
|
|
|
{ |
|
107
|
6 |
|
if ($this->data->getShipCount() > 0) { |
|
108
|
6 |
|
return (string) $this->data->getShipCount(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
return null; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function getBorder(): string |
|
115
|
|
|
{ |
|
116
|
|
|
// default border style |
|
117
|
|
|
return '#2d2d2d'; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function getCSSClass(): string |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->cssClass; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function isRowIndex(): bool |
|
126
|
|
|
{ |
|
127
|
|
|
return false; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|