|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Component\StarSystem; |
|
6
|
|
|
|
|
7
|
|
|
use RuntimeException; |
|
8
|
|
|
use Stu\Component\StarSystem\StarSystemCreationInterface; |
|
9
|
|
|
use Stu\Orm\Repository\LayerRepositoryInterface; |
|
10
|
|
|
use Stu\Orm\Repository\MapRepositoryInterface; |
|
11
|
|
|
use Stu\Orm\Repository\StarSystemRepositoryInterface; |
|
12
|
|
|
|
|
13
|
|
|
final class GenerateEmptySystems implements GenerateEmptySystemsInterface |
|
14
|
|
|
{ |
|
15
|
|
|
public const BATCH_AMOUNT = 10; |
|
16
|
|
|
|
|
17
|
|
|
private LayerRepositoryInterface $layerRepository; |
|
18
|
|
|
|
|
19
|
|
|
private MapRepositoryInterface $mapRepository; |
|
20
|
|
|
|
|
21
|
|
|
private StarSystemRepositoryInterface $starSystemRepository; |
|
22
|
|
|
|
|
23
|
|
|
private StarSystemCreationInterface $starSystemCreation; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct( |
|
26
|
|
|
LayerRepositoryInterface $layerRepository, |
|
27
|
|
|
MapRepositoryInterface $mapRepository, |
|
28
|
|
|
StarSystemRepositoryInterface $starSystemRepository, |
|
29
|
|
|
StarSystemCreationInterface $starSystemCreation |
|
30
|
|
|
) { |
|
31
|
|
|
$this->layerRepository = $layerRepository; |
|
32
|
|
|
$this->mapRepository = $mapRepository; |
|
33
|
|
|
$this->starSystemRepository = $starSystemRepository; |
|
34
|
|
|
$this->starSystemCreation = $starSystemCreation; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function generate(int $layerId): int |
|
38
|
|
|
{ |
|
39
|
|
|
$layer = $this->layerRepository->find($layerId); |
|
40
|
|
|
if ($layer === null) { |
|
41
|
|
|
throw new RuntimeException('layer does not exist'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$mapArray = $this->mapRepository->getWithEmptySystem($layer); |
|
45
|
|
|
|
|
46
|
|
|
$count = 0; |
|
47
|
|
|
|
|
48
|
|
|
$randomNames = $this->starSystemRepository->getRandomFreeSystemNames(self::BATCH_AMOUNT); |
|
49
|
|
|
|
|
50
|
|
|
foreach ($mapArray as $map) { |
|
51
|
|
|
if ($count === self::BATCH_AMOUNT) { |
|
52
|
|
|
break; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$this->starSystemCreation->recreateStarSystem($map, $randomNames[$count]->getName()); |
|
56
|
|
|
$count++; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $count; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|