1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Starmap\Lib; |
6
|
|
|
|
7
|
|
|
use Stu\Orm\Entity\MapInterface; |
8
|
|
|
use Stu\Orm\Entity\StarSystemInterface; |
9
|
|
|
use Stu\Orm\Entity\StarSystemMapInterface; |
10
|
|
|
use Stu\Orm\Repository\MapRepositoryInterface; |
11
|
|
|
use Stu\Orm\Repository\StarSystemMapRepositoryInterface; |
12
|
|
|
|
13
|
|
|
class YRow |
14
|
|
|
{ |
15
|
|
|
protected int $layerId; |
16
|
|
|
|
17
|
|
|
protected int $row; |
18
|
|
|
|
19
|
|
|
protected int $minx; |
20
|
|
|
|
21
|
|
|
protected int $maxx; |
22
|
|
|
|
23
|
|
|
protected int|StarSystemInterface $system; |
24
|
|
|
|
25
|
|
|
/** @var null|array<MapInterface|null>|array<StarSystemMapInterface|null> */ |
26
|
|
|
protected $fields; |
27
|
|
|
|
28
|
|
|
private MapRepositoryInterface $mapRepository; |
29
|
|
|
|
30
|
|
|
private StarSystemMapRepositoryInterface $systemMapRepository; |
31
|
|
|
|
32
|
2 |
|
public function __construct( |
33
|
|
|
MapRepositoryInterface $mapRepository, |
34
|
|
|
StarSystemMapRepositoryInterface $systemMapRepository, |
35
|
|
|
int $layerId, |
36
|
|
|
int $cury, |
37
|
|
|
int $minx, |
38
|
|
|
int $maxx, |
39
|
|
|
int|StarSystemInterface $system |
40
|
|
|
) { |
41
|
2 |
|
$this->layerId = $layerId; |
42
|
2 |
|
$this->row = $cury; |
43
|
2 |
|
$this->minx = $minx; |
44
|
2 |
|
$this->maxx = $maxx; |
45
|
2 |
|
$this->system = $system; |
46
|
2 |
|
$this->mapRepository = $mapRepository; |
47
|
2 |
|
$this->systemMapRepository = $systemMapRepository; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return array<StarSystemMapInterface|null>|array<MapInterface|null> |
52
|
|
|
*/ |
53
|
|
|
public function getFields(): iterable |
54
|
|
|
{ |
55
|
|
|
if ($this->fields === null) { |
56
|
|
|
$this->fields = []; |
57
|
|
|
for ($i = $this->minx; $i <= $this->maxx; $i++) { |
58
|
|
|
$this->fields[] = $this->mapRepository->getByCoordinates( |
59
|
|
|
$this->layerId, |
60
|
|
|
$i, |
61
|
|
|
$this->row |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
return $this->fields; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return array<StarSystemMapInterface|null>|array<MapInterface|null> |
70
|
|
|
*/ |
71
|
|
|
public function getSystemFields() |
72
|
|
|
{ |
73
|
|
|
if ($this->fields === null) { |
74
|
|
|
$this->fields = []; |
75
|
|
|
|
76
|
|
|
if ($this->system instanceof StarSystemInterface) { |
77
|
|
|
$this->fields = array_filter( |
78
|
|
|
$this->system->getFields()->toArray(), |
79
|
|
|
fn (StarSystemMapInterface $systemMap) => $systemMap->getSy() === $this->row |
80
|
|
|
); |
81
|
|
|
} else { |
82
|
|
|
|
83
|
|
|
for ($i = $this->minx; $i <= $this->maxx; $i++) { |
84
|
|
|
$this->fields[] = $this->systemMapRepository->getByCoordinates( |
85
|
|
|
$this->system, |
86
|
|
|
$i, |
87
|
|
|
$this->row |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
return $this->fields; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return int |
97
|
|
|
*/ |
98
|
|
|
public function getRow() |
99
|
|
|
{ |
100
|
|
|
return $this->row; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|