|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Lib; |
|
6
|
|
|
|
|
7
|
|
|
use RuntimeException; |
|
8
|
|
|
use Stu\Component\Ship\AstronomicalMappingEnum; |
|
9
|
|
|
use Stu\Component\Ship\ShipStateEnum; |
|
10
|
|
|
use Stu\Orm\Repository\AstroEntryRepositoryInterface; |
|
11
|
|
|
|
|
12
|
|
|
final class AstroEntryLib implements AstroEntryLibInterface |
|
13
|
|
|
{ |
|
14
|
|
|
private AstroEntryRepositoryInterface $astroEntryRepository; |
|
15
|
|
|
|
|
16
|
4 |
|
public function __construct( |
|
17
|
|
|
AstroEntryRepositoryInterface $astroEntryRepository |
|
18
|
|
|
) { |
|
19
|
4 |
|
$this->astroEntryRepository = $astroEntryRepository; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function cancelAstroFinalizing(ShipWrapperInterface $wrapper): void |
|
23
|
|
|
{ |
|
24
|
|
|
$ship = $wrapper->get(); |
|
25
|
|
|
|
|
26
|
|
|
$ship->setState(ShipStateEnum::SHIP_STATE_NONE); |
|
27
|
|
|
$astroLab = $wrapper->getAstroLaboratorySystemData(); |
|
28
|
|
|
if ($astroLab === null) { |
|
29
|
|
|
throw new RuntimeException('this should not happen'); |
|
30
|
|
|
} |
|
31
|
|
|
$astroLab->setAstroStartTurn(null)->update(); |
|
32
|
|
|
|
|
33
|
|
|
$entry = $this->astroEntryRepository->getByShipLocation($ship, false); |
|
34
|
|
|
|
|
35
|
|
|
$entry->setState(AstronomicalMappingEnum::MEASURED); |
|
36
|
|
|
$entry->setAstroStartTurn(null); |
|
37
|
|
|
$this->astroEntryRepository->save($entry); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function finish(ShipWrapperInterface $wrapper): void |
|
41
|
|
|
{ |
|
42
|
|
|
$ship = $wrapper->get(); |
|
43
|
|
|
|
|
44
|
|
|
$ship->setState(ShipStateEnum::SHIP_STATE_NONE); |
|
45
|
|
|
|
|
46
|
|
|
$astroLab = $wrapper->getAstroLaboratorySystemData(); |
|
47
|
|
|
if ($astroLab === null) { |
|
48
|
|
|
throw new RuntimeException('this should not happen'); |
|
49
|
|
|
} |
|
50
|
|
|
$astroLab->setAstroStartTurn(null)->update(); |
|
51
|
|
|
|
|
52
|
|
|
$entry = $this->astroEntryRepository->getByShipLocation($ship, false); |
|
53
|
|
|
|
|
54
|
|
|
$entry->setState(AstronomicalMappingEnum::DONE); |
|
55
|
|
|
$entry->setAstroStartTurn(null); |
|
56
|
|
|
$this->astroEntryRepository->save($entry); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|