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\BuildPlanDeleterInterface; |
8
|
|
|
use Stu\Module\Control\GameControllerInterface; |
9
|
|
|
use Stu\Orm\Entity\ShipBuildplanInterface; |
10
|
|
|
use Stu\Orm\Repository\BuildingFunctionRepositoryInterface; |
11
|
|
|
use Stu\Orm\Repository\ShipBuildplanRepositoryInterface; |
12
|
|
|
|
13
|
|
|
final class ShipBuildplansProvider implements GuiComponentProviderInterface |
14
|
|
|
{ |
15
|
|
|
private BuildingFunctionRepositoryInterface $buildingFunctionRepository; |
16
|
|
|
|
17
|
|
|
private ShipBuildplanRepositoryInterface $shipBuildplanRepository; |
18
|
|
|
|
19
|
|
|
private BuildPlanDeleterInterface $buildPlanDeleter; |
20
|
|
|
|
21
|
|
|
public function __construct( |
22
|
|
|
BuildPlanDeleterInterface $buildPlanDeleter, |
23
|
|
|
BuildingFunctionRepositoryInterface $buildingFunctionRepository, |
24
|
|
|
ShipBuildplanRepositoryInterface $shipBuildplanRepository |
25
|
|
|
) { |
26
|
|
|
$this->buildingFunctionRepository = $buildingFunctionRepository; |
27
|
|
|
$this->shipBuildplanRepository = $shipBuildplanRepository; |
28
|
|
|
$this->buildPlanDeleter = $buildPlanDeleter; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function setTemplateVariables( |
32
|
|
|
PlanetFieldHostInterface $host, |
33
|
|
|
GameControllerInterface $game |
34
|
|
|
): void { |
35
|
|
|
|
36
|
|
|
$buildingFunction = $this->buildingFunctionRepository->find( |
37
|
|
|
request::getIntFatal('func') |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
if ($buildingFunction === null) { |
41
|
|
|
return; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$game->setTemplateVar( |
45
|
|
|
'AVAILABLE_BUILDPLANS', |
46
|
|
|
array_map( |
47
|
|
|
fn (ShipBuildplanInterface $plan): array => [ |
48
|
|
|
'plan' => $plan, |
49
|
|
|
'deletable' => $this->buildPlanDeleter->isDeletable($plan) |
50
|
|
|
], |
51
|
|
|
$this->shipBuildplanRepository->getByUserAndBuildingFunction( |
52
|
|
|
$game->getUser()->getId(), |
53
|
|
|
$buildingFunction->getFunction() |
54
|
|
|
) |
55
|
|
|
) |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|