1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stu\Module\Colony\Lib\Gui\Component; |
4
|
|
|
|
5
|
|
|
use request; |
6
|
|
|
use Stu\Lib\Colony\PlanetFieldHostInterface; |
7
|
|
|
use Stu\Module\Colony\Lib\BuildableRumpListItemInterface; |
8
|
|
|
use Stu\Module\Colony\Lib\ColonyLibFactoryInterface; |
9
|
|
|
use Stu\Module\Control\GameControllerInterface; |
10
|
|
|
use Stu\Orm\Entity\ShipRumpInterface; |
11
|
|
|
use Stu\Orm\Repository\BuildingFunctionRepositoryInterface; |
12
|
|
|
use Stu\Orm\Repository\ShipRumpRepositoryInterface; |
13
|
|
|
|
14
|
|
|
final class ShipyardProvider implements GuiComponentProviderInterface |
15
|
|
|
{ |
16
|
|
|
private BuildingFunctionRepositoryInterface $buildingFunctionRepository; |
17
|
|
|
|
18
|
|
|
private ShipRumpRepositoryInterface $shipRumpRepository; |
19
|
|
|
|
20
|
|
|
private ColonyLibFactoryInterface $colonyLibFactory; |
21
|
|
|
|
22
|
|
|
public function __construct( |
23
|
|
|
BuildingFunctionRepositoryInterface $buildingFunctionRepository, |
24
|
|
|
ShipRumpRepositoryInterface $shipRumpRepository, |
25
|
|
|
ColonyLibFactoryInterface $colonyLibFactory |
26
|
|
|
) { |
27
|
|
|
$this->buildingFunctionRepository = $buildingFunctionRepository; |
28
|
|
|
$this->shipRumpRepository = $shipRumpRepository; |
29
|
|
|
$this->colonyLibFactory = $colonyLibFactory; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function setTemplateVariables( |
33
|
|
|
PlanetFieldHostInterface $host, |
34
|
|
|
GameControllerInterface $game |
35
|
|
|
): void { |
36
|
|
|
|
37
|
|
|
$buildingFunction = $this->buildingFunctionRepository->find( |
38
|
|
|
request::getIntFatal('func') |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
if ($buildingFunction === null) { |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$user = $game->getUser(); |
46
|
|
|
$userId = $user->getId(); |
47
|
|
|
|
48
|
|
|
$game->setTemplateVar( |
49
|
|
|
'BUILDABLE_SHIPS', |
50
|
|
|
array_map( |
51
|
|
|
fn (ShipRumpInterface $shipRump): BuildableRumpListItemInterface => $this->colonyLibFactory->createBuildableRumpItem( |
52
|
|
|
$shipRump, |
53
|
|
|
$user |
54
|
|
|
), |
55
|
|
|
$this->shipRumpRepository->getBuildableByUserAndBuildingFunction($userId, $buildingFunction->getFunction()) |
56
|
|
|
) |
57
|
|
|
); |
58
|
|
|
$game->setTemplateVar('BUILDABLE_RUMPS', $this->shipRumpRepository->getBuildableByUser($userId)); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|