|
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
|
|
|
public const ONLY_BACKGROUND_IMAGE = 1; |
|
13
|
|
|
|
|
14
|
|
|
protected VisualPanelEntryData $data; |
|
15
|
|
|
|
|
16
|
|
|
private ?LayerInterface $layer; |
|
17
|
|
|
|
|
18
|
|
|
private ?EncodedMapInterface $encodedMap; |
|
19
|
|
|
|
|
20
|
|
|
private string $cssClass = 'lss'; |
|
21
|
|
|
|
|
22
|
5 |
|
public function __construct( |
|
23
|
|
|
VisualPanelEntryData $data, |
|
24
|
|
|
?LayerInterface $layer, |
|
25
|
|
|
?EncodedMapInterface $encodedMap |
|
26
|
|
|
) { |
|
27
|
5 |
|
$this->data = $data; |
|
28
|
5 |
|
$this->layer = $layer; |
|
29
|
5 |
|
$this->encodedMap = $encodedMap; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
4 |
|
public function getLssCellData(): LssCellData |
|
33
|
|
|
{ |
|
34
|
4 |
|
return new LssCellData( |
|
35
|
4 |
|
$this->getSystemBackgroundId(), |
|
36
|
4 |
|
$this->getFieldGraphicID(), |
|
37
|
4 |
|
$this->getMapGraphicPath(), |
|
38
|
4 |
|
$this->data->getShieldState(), |
|
39
|
4 |
|
$this->getSubspaceCode(), |
|
40
|
4 |
|
$this->getDisplayCount(), |
|
41
|
4 |
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
4 |
|
private function getFieldGraphicID(): ?int |
|
45
|
|
|
{ |
|
46
|
4 |
|
$fieldId = $this->data->getMapfieldType(); |
|
47
|
|
|
|
|
48
|
4 |
|
if ($fieldId === self::ONLY_BACKGROUND_IMAGE) { |
|
49
|
|
|
return null; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
4 |
|
return $fieldId; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
4 |
|
private function getSystemBackgroundId(): ?string |
|
56
|
|
|
{ |
|
57
|
4 |
|
if ($this->data->getSystemId() === null) { |
|
58
|
|
|
return null; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
4 |
|
return sprintf( |
|
62
|
4 |
|
'%02d%02d', |
|
63
|
4 |
|
$this->data->getPosY(), |
|
64
|
4 |
|
$this->data->getPosX() |
|
65
|
4 |
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
4 |
|
private function getMapGraphicPath(): ?string |
|
69
|
|
|
{ |
|
70
|
4 |
|
$layer = $this->layer; |
|
71
|
4 |
|
if ($layer === null) { |
|
72
|
|
|
return null; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
4 |
|
$encodedMap = $this->encodedMap; |
|
76
|
4 |
|
if ($layer->isEncoded() && $encodedMap !== null) { |
|
77
|
|
|
|
|
78
|
3 |
|
return $encodedMap->getEncodedMapPath( |
|
79
|
3 |
|
$this->data->getMapfieldType(), |
|
80
|
3 |
|
$layer |
|
81
|
3 |
|
); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
1 |
|
return sprintf('%d/%d.png', $layer->getId(), $this->data->getMapfieldType()); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
4 |
|
private function getSubspaceCode(): ?string |
|
88
|
|
|
{ |
|
89
|
4 |
|
if (!$this->data->isSubspaceCodeAvailable()) { |
|
90
|
|
|
return null; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
4 |
|
return sprintf( |
|
94
|
4 |
|
'%d%d%d%d', |
|
95
|
4 |
|
$this->getCode($this->data->getDirection1Count()), |
|
96
|
4 |
|
$this->getCode($this->data->getDirection2Count()), |
|
97
|
4 |
|
$this->getCode($this->data->getDirection3Count()), |
|
98
|
4 |
|
$this->getCode($this->data->getDirection4Count()) |
|
99
|
4 |
|
); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
4 |
|
private function getCode(int $shipCount): int |
|
103
|
|
|
{ |
|
104
|
|
|
//TODO use constant values |
|
105
|
4 |
|
if ($shipCount == 0) { |
|
106
|
|
|
return 0; |
|
107
|
|
|
} |
|
108
|
4 |
|
if ($shipCount == 1) { |
|
109
|
4 |
|
return 1; |
|
110
|
|
|
} |
|
111
|
4 |
|
if ($shipCount < 6) { |
|
112
|
4 |
|
return 2; |
|
113
|
|
|
} |
|
114
|
|
|
if ($shipCount < 11) { |
|
115
|
|
|
return 3; |
|
116
|
|
|
} |
|
117
|
|
|
if ($shipCount < 21) { |
|
118
|
|
|
return 4; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return 5; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
4 |
|
protected function getDisplayCount(): ?string |
|
125
|
|
|
{ |
|
126
|
4 |
|
if ($this->data->getShipCount() > 0) { |
|
127
|
4 |
|
return (string) $this->data->getShipCount(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return null; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function getBorder(): string |
|
134
|
|
|
{ |
|
135
|
|
|
// default border style |
|
136
|
|
|
return '#2d2d2d'; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function getCSSClass(): string |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->cssClass; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function isRowIndex(): bool |
|
145
|
|
|
{ |
|
146
|
|
|
return false; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|