|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\View\ShowShip; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
|
|
8
|
|
|
use Stu\Component\Ship\AstronomicalMappingEnum; |
|
|
|
|
|
|
9
|
|
|
use Stu\Module\Control\GameControllerInterface; |
|
10
|
|
|
use Stu\Component\Game\ModuleEnum; |
|
11
|
|
|
use Stu\Module\Control\ViewContext; |
|
12
|
|
|
use Stu\Module\Ship\Lib\AstroEntryLibInterface; |
|
13
|
|
|
use Stu\Module\Ship\Lib\ShipLoaderInterface; |
|
14
|
|
|
use Stu\Module\Spacecraft\View\ShowSpacecraft\ShowSpacecraft; |
|
|
|
|
|
|
15
|
|
|
use Stu\Module\Spacecraft\View\ShowSpacecraft\SpacecraftTypeShowStragegyInterface; |
|
16
|
|
|
use Stu\Orm\Entity\DatabaseEntryInterface; |
|
17
|
|
|
use Stu\Orm\Entity\ShipInterface; |
|
18
|
|
|
use Stu\Orm\Repository\DatabaseUserRepositoryInterface; |
|
19
|
|
|
|
|
20
|
|
|
class ShipShowStrategy implements SpacecraftTypeShowStragegyInterface |
|
21
|
|
|
{ |
|
22
|
1 |
|
public function __construct( |
|
23
|
|
|
private ShipLoaderInterface $shipLoader, |
|
24
|
|
|
private DatabaseUserRepositoryInterface $databaseUserRepository, |
|
25
|
|
|
private AstroEntryLibInterface $astroEntryLib, |
|
26
|
1 |
|
) {} |
|
27
|
|
|
|
|
28
|
1 |
|
#[Override] |
|
29
|
|
|
public function appendNavigationPart(GameControllerInterface $game): SpacecraftTypeShowStragegyInterface |
|
30
|
|
|
{ |
|
31
|
1 |
|
$game->appendNavigationPart('ship.php', _('Schiffe')); |
|
32
|
|
|
|
|
33
|
1 |
|
return $this; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
#[Override] |
|
37
|
|
|
public function setTemplateVariables(int $spacecraftId, GameControllerInterface $game): SpacecraftTypeShowStragegyInterface |
|
38
|
|
|
{ |
|
39
|
1 |
|
$ship = $this->shipLoader->getByIdAndUser($spacecraftId, $game->getUser()->getId(), true, false); |
|
40
|
1 |
|
$game->setTemplateVar('ASTRO_STATE_SYSTEM', $this->getAstroState($ship, $game, true)); |
|
41
|
1 |
|
$game->setTemplateVar('ASTRO_STATE_REGION', $this->getAstroState($ship, $game, false)); |
|
42
|
|
|
|
|
43
|
1 |
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
private function getAstroState(ShipInterface $ship, GameControllerInterface $game, bool $isSystem): AstroStateWrapper |
|
47
|
|
|
{ |
|
48
|
|
|
//$this->loggerUtil->init('SS', LoggerEnum::LEVEL_ERROR); |
|
49
|
|
|
|
|
50
|
1 |
|
$databaseEntry = $this->getDatabaseEntryForShipLocation($ship, $isSystem); |
|
51
|
|
|
|
|
52
|
1 |
|
$astroEntry = null; |
|
53
|
|
|
|
|
54
|
1 |
|
if ($databaseEntry === null) { |
|
55
|
|
|
$state = AstronomicalMappingEnum::NONE; |
|
56
|
1 |
|
} elseif ($this->databaseUserRepository->exists($game->getUser()->getId(), $databaseEntry->getId())) { |
|
57
|
|
|
$state = AstronomicalMappingEnum::DONE; |
|
58
|
|
|
} else { |
|
59
|
1 |
|
$astroEntry = $this->astroEntryLib->getAstroEntryByShipLocation($ship, $isSystem); |
|
60
|
|
|
|
|
61
|
1 |
|
$state = $astroEntry === null ? AstronomicalMappingEnum::PLANNABLE : $astroEntry->getState(); |
|
62
|
|
|
} |
|
63
|
1 |
|
$turnsLeft = null; |
|
64
|
1 |
|
if ($state === AstronomicalMappingEnum::FINISHING && $astroEntry !== null) { |
|
65
|
|
|
$turnsLeft = AstronomicalMappingEnum::TURNS_TO_FINISH - ($game->getCurrentRound()->getTurn() - $astroEntry->getAstroStartTurn()); |
|
66
|
|
|
} |
|
67
|
1 |
|
$measurementpointsleft = null; |
|
68
|
1 |
|
if ($state === AstronomicalMappingEnum::PLANNED && $astroEntry !== null) { |
|
69
|
|
|
$fieldIds = unserialize($astroEntry->getFieldIds()); |
|
70
|
|
|
$measurementpointsleft = is_array($fieldIds) ? count($fieldIds) : 0; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
return new AstroStateWrapper($state, $turnsLeft, $isSystem, $measurementpointsleft); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
1 |
|
private function getDatabaseEntryForShipLocation(ShipInterface $ship, bool $isSystem): ?DatabaseEntryInterface |
|
77
|
|
|
{ |
|
78
|
1 |
|
if ($isSystem) { |
|
79
|
1 |
|
$system = $ship->getSystem() ?? $ship->isOverSystem(); |
|
80
|
1 |
|
if ($system !== null) { |
|
81
|
1 |
|
return $system->getDatabaseEntry(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return null; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
1 |
|
$mapRegion = $ship->getMapRegion(); |
|
88
|
1 |
|
if ($mapRegion !== null) { |
|
89
|
1 |
|
return $mapRegion->getDatabaseEntry(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return null; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
1 |
|
#[Override] |
|
96
|
|
|
public function getViewContext(): ViewContext |
|
97
|
|
|
{ |
|
98
|
1 |
|
return new ViewContext(ModuleEnum::SHIP, ShowSpacecraft::VIEW_IDENTIFIER); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths