|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Colony\View\ShowModuleFab; |
|
6
|
|
|
|
|
7
|
|
|
use request; |
|
8
|
|
|
use Stu\Component\Colony\ColonyMenuEnum; |
|
9
|
|
|
use Stu\Component\Ship\ShipModuleTypeEnum; |
|
10
|
|
|
use Stu\Module\Colony\Lib\ColonyLoaderInterface; |
|
11
|
|
|
use Stu\Module\Control\GameControllerInterface; |
|
12
|
|
|
use Stu\Module\Control\ViewControllerInterface; |
|
13
|
|
|
use Stu\Orm\Repository\BuildingFunctionRepositoryInterface; |
|
14
|
|
|
use Stu\Orm\Repository\ModuleBuildingFunctionRepositoryInterface; |
|
15
|
|
|
use Stu\Orm\Repository\ModuleQueueRepositoryInterface; |
|
16
|
|
|
use Stu\Orm\Repository\ShipRumpRepositoryInterface; |
|
17
|
|
|
use Stu\Orm\Repository\ShipRumpModuleLevelRepositoryInterface; |
|
18
|
|
|
|
|
19
|
|
|
final class ShowModuleFab implements ViewControllerInterface |
|
20
|
|
|
{ |
|
21
|
|
|
public const VIEW_IDENTIFIER = 'SHOW_MODULEFAB'; |
|
22
|
|
|
|
|
23
|
|
|
private ColonyLoaderInterface $colonyLoader; |
|
24
|
|
|
private ShowModuleFabRequestInterface $showModuleFabRequest; |
|
25
|
|
|
private ModuleBuildingFunctionRepositoryInterface $moduleBuildingFunctionRepository; |
|
26
|
|
|
private BuildingFunctionRepositoryInterface $buildingFunctionRepository; |
|
27
|
|
|
private ModuleQueueRepositoryInterface $moduleQueueRepository; |
|
28
|
|
|
private ShipRumpRepositoryInterface $shipRumpRepository; |
|
29
|
|
|
private ShipRumpModuleLevelRepositoryInterface $shipRumpModuleLevelRepository; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct( |
|
32
|
|
|
ColonyLoaderInterface $colonyLoader, |
|
33
|
|
|
ShowModuleFabRequestInterface $showModuleFabRequest, |
|
34
|
|
|
ModuleBuildingFunctionRepositoryInterface $moduleBuildingFunctionRepository, |
|
35
|
|
|
BuildingFunctionRepositoryInterface $buildingFunctionRepository, |
|
36
|
|
|
ModuleQueueRepositoryInterface $moduleQueueRepository, |
|
37
|
|
|
ShipRumpRepositoryInterface $shipRumpRepository, |
|
38
|
|
|
ShipRumpModuleLevelRepositoryInterface $shipRumpModuleLevelRepository |
|
39
|
|
|
) { |
|
40
|
|
|
$this->colonyLoader = $colonyLoader; |
|
41
|
|
|
$this->showModuleFabRequest = $showModuleFabRequest; |
|
42
|
|
|
$this->moduleBuildingFunctionRepository = $moduleBuildingFunctionRepository; |
|
43
|
|
|
$this->buildingFunctionRepository = $buildingFunctionRepository; |
|
44
|
|
|
$this->moduleQueueRepository = $moduleQueueRepository; |
|
45
|
|
|
$this->shipRumpRepository = $shipRumpRepository; |
|
46
|
|
|
$this->shipRumpModuleLevelRepository = $shipRumpModuleLevelRepository; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function handle(GameControllerInterface $game): void |
|
50
|
|
|
{ |
|
51
|
|
|
$userId = $game->getUser()->getId(); |
|
52
|
|
|
|
|
53
|
|
|
$colony = $this->colonyLoader->loadWithOwnerValidation( |
|
54
|
|
|
$this->showModuleFabRequest->getColonyId(), |
|
55
|
|
|
$userId, |
|
56
|
|
|
false |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
$func = $this->buildingFunctionRepository->find(request::getIntFatal('func')); |
|
60
|
|
|
$modules = $this->moduleBuildingFunctionRepository->getByBuildingFunctionAndUser( |
|
61
|
|
|
$func->getFunction(), |
|
62
|
|
|
$userId |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
$sortedModules = []; |
|
66
|
|
|
foreach ($modules as $module) { |
|
67
|
|
|
$moduleType = $module->getModule()->getType()->value; |
|
68
|
|
|
$moduleLevel = $module->getModule()->getLevel(); |
|
69
|
|
|
if (!isset($sortedModules[$moduleType])) { |
|
70
|
|
|
$sortedModules[$moduleType] = []; |
|
71
|
|
|
} |
|
72
|
|
|
if (!isset($sortedModules[$moduleType][$moduleLevel])) { |
|
73
|
|
|
$sortedModules[$moduleType][$moduleLevel] = []; |
|
74
|
|
|
} |
|
75
|
|
|
$sortedModules[$moduleType][$moduleLevel][] = new ModuleFabricationListItemTal( |
|
76
|
|
|
$this->moduleQueueRepository, |
|
77
|
|
|
$module->getModule(), |
|
78
|
|
|
$colony |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$shipRumps = $this->shipRumpRepository->getBuildableByUser($userId); |
|
83
|
|
|
|
|
84
|
|
|
$moduleTypes = []; |
|
85
|
|
|
foreach (ShipModuleTypeEnum::cases() as $moduleType) { |
|
86
|
|
|
$moduleTypes[$moduleType->value] = [ |
|
87
|
|
|
'name' => $moduleType->getDescription(), |
|
88
|
|
|
'image' => "/assets/buttons/modul_screen_{$moduleType->value}.png" |
|
89
|
|
|
]; |
|
90
|
|
|
} |
|
91
|
|
|
$rumpModules = []; |
|
92
|
|
|
$rumpModules[0] = $sortedModules; |
|
93
|
|
|
foreach ($shipRumps as $rump) { |
|
94
|
|
|
$rumpId = $rump->getId(); |
|
95
|
|
|
$rumpModules[$rumpId] = []; |
|
96
|
|
|
|
|
97
|
|
|
foreach ($sortedModules as $type => $levels) { |
|
98
|
|
|
$mod_level = $this->shipRumpModuleLevelRepository->getByShipRump($rumpId); |
|
99
|
|
|
|
|
100
|
|
|
if ($type === ShipModuleTypeEnum::SPECIAL->value) { |
|
101
|
|
|
foreach ($levels as $level => $modules) { |
|
102
|
|
|
if (!isset($rumpModules[$rumpId][$type])) { |
|
103
|
|
|
$rumpModules[$rumpId][$type] = []; |
|
104
|
|
|
} |
|
105
|
|
|
$rumpModules[$rumpId][$type][$level] = $modules; |
|
106
|
|
|
} |
|
107
|
|
|
} else { |
|
108
|
|
|
$min_level_method = 'getModuleLevel' . $type . 'Min'; |
|
109
|
|
|
$max_level_method = 'getModuleLevel' . $type . 'Max'; |
|
110
|
|
|
|
|
111
|
|
|
if ($mod_level !== null && method_exists($mod_level, $min_level_method) && method_exists($mod_level, $max_level_method)) { |
|
112
|
|
|
$min_level = $mod_level->$min_level_method(); |
|
113
|
|
|
$max_level = $mod_level->$max_level_method(); |
|
114
|
|
|
|
|
115
|
|
|
foreach ($levels as $level => $modules) { |
|
116
|
|
|
if ($level >= $min_level && $level <= $max_level) { |
|
117
|
|
|
if (!isset($rumpModules[$rumpId][$type])) { |
|
118
|
|
|
$rumpModules[$rumpId][$type] = []; |
|
119
|
|
|
} |
|
120
|
|
|
$rumpModules[$rumpId][$type][$level] = $modules; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
$game->showMacro(ColonyMenuEnum::MENU_MODULEFAB->getTemplate()); |
|
129
|
|
|
$game->setTemplateVar('CURRENT_MENU', ColonyMenuEnum::MENU_MODULEFAB); |
|
130
|
|
|
|
|
131
|
|
|
$game->setTemplateVar('HOST', $colony); |
|
132
|
|
|
$game->setTemplateVar('FUNC', $func); |
|
133
|
|
|
$game->setTemplateVar('SORTED_MODULES', $sortedModules); |
|
134
|
|
|
$game->setTemplateVar('SHIP_RUMPS', $shipRumps); |
|
135
|
|
|
$game->setTemplateVar('MODULE_TYPES', $moduleTypes); |
|
136
|
|
|
$game->setTemplateVar('RUMP_MODULES', $rumpModules); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|