1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\NPC\View\ShowShipCreator; |
6
|
|
|
|
7
|
|
|
use Override; |
8
|
|
|
use request; |
9
|
|
|
use Stu\Module\Control\GameControllerInterface; |
10
|
|
|
use Stu\Module\Control\ViewControllerInterface; |
11
|
|
|
use Stu\Orm\Repository\ShipBuildplanRepositoryInterface; |
12
|
|
|
use Stu\Orm\Repository\UserRepositoryInterface; |
13
|
|
|
use Stu\Orm\Repository\LayerRepositoryInterface; |
14
|
|
|
use Stu\Orm\Repository\TorpedoTypeRepositoryInterface; |
15
|
|
|
|
16
|
|
|
final class ShowShipCreator implements ViewControllerInterface |
17
|
|
|
{ |
18
|
|
|
public const string VIEW_IDENTIFIER = 'SHOW_SHIP_CREATOR'; |
|
|
|
|
19
|
|
|
|
20
|
|
|
public function __construct( |
21
|
|
|
private ShipBuildplanRepositoryInterface $shipBuildplanRepository, |
22
|
|
|
private UserRepositoryInterface $userRepository, |
23
|
|
|
private LayerRepositoryInterface $layerRepository, |
24
|
|
|
private TorpedoTypeRepositoryInterface $torpedoTypeRepository |
25
|
|
|
) {} |
26
|
|
|
|
27
|
|
|
#[Override] |
28
|
|
|
public function handle(GameControllerInterface $game): void |
29
|
|
|
{ |
30
|
|
|
$userId = request::getInt('userId'); |
31
|
|
|
$buildplanId = request::getInt('buildplanId'); |
32
|
|
|
|
33
|
|
|
$game->setTemplateFile('html/npc/shipCreator.twig'); |
34
|
|
|
$game->appendNavigationPart('/npc/index.php?SHOW_SHIP_CREATOR=1', 'Schiff erstellen'); |
35
|
|
|
$game->setPageTitle('Schiff erstellen'); |
36
|
|
|
|
37
|
|
|
if ($userId > 0) { |
38
|
|
|
$selectedUser = $this->userRepository->find($userId); |
39
|
|
|
$game->setTemplateVar('USER_ID', $userId); |
40
|
|
|
$game->setTemplateVar('SELECTED_USER', $selectedUser); |
41
|
|
|
|
42
|
|
|
if ($buildplanId > 0) { |
43
|
|
|
$buildplan = $this->shipBuildplanRepository->find($buildplanId); |
44
|
|
|
if ($buildplan !== null) { |
45
|
|
|
$possibleTorpedoTypes = $this->torpedoTypeRepository->getByLevel($buildplan->getRump()->getTorpedoLevel()); |
46
|
|
|
$game->setTemplateVar('TORPEDO_TYPES', $possibleTorpedoTypes); |
47
|
|
|
$game->setTemplateVar('SELECTED_BUILDPLAN', $buildplan); |
48
|
|
|
$game->setTemplateVar('LAYERS', $this->layerRepository->findAll()); |
49
|
|
|
} |
50
|
|
|
} else { |
51
|
|
|
$game->setTemplateVar('BUILDPLANS', $this->shipBuildplanRepository->getByUser($userId)); |
52
|
|
|
} |
53
|
|
|
} else { |
54
|
|
|
$npcList = iterator_to_array($this->userRepository->getNpcList()); |
55
|
|
|
$nonNpcList = iterator_to_array($this->userRepository->getNonNpcList()); |
56
|
|
|
$allUsers = array_merge($npcList, $nonNpcList); |
57
|
|
|
$game->setTemplateVar('ALL_USERS', $allUsers); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|