1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Admin\View\Map\EditSection; |
6
|
|
|
|
7
|
|
|
use Stu\Component\Map\MapEnum; |
8
|
|
|
use Stu\Module\Control\GameControllerInterface; |
9
|
|
|
use Stu\Module\Control\ViewControllerInterface; |
10
|
|
|
use Stu\Module\Starmap\Lib\StarmapUiFactoryInterface; |
11
|
|
|
use Stu\Module\Starmap\View\ShowSection\ShowSectionRequestInterface; |
12
|
|
|
use Stu\Orm\Entity\StarSystem; |
13
|
|
|
use Stu\Orm\Repository\LayerRepositoryInterface; |
14
|
|
|
use Stu\Orm\Repository\MapFieldTypeRepositoryInterface; |
15
|
|
|
use Stu\Orm\Repository\StarSystemTypeRepositoryInterface; |
16
|
|
|
|
17
|
|
|
final class EditSection implements ViewControllerInterface |
18
|
|
|
{ |
19
|
|
|
public const VIEW_IDENTIFIER = 'SHOW_EDIT_MAP_SECTION'; |
20
|
|
|
|
21
|
|
|
private ShowSectionRequestInterface $request; |
22
|
|
|
|
23
|
|
|
private LayerRepositoryInterface $layerRepository; |
24
|
|
|
|
25
|
|
|
private MapFieldTypeRepositoryInterface $mapFieldTypeRepository; |
26
|
|
|
|
27
|
|
|
private StarmapUiFactoryInterface $starmapUiFactory; |
28
|
|
|
|
29
|
|
|
private StarSystemTypeRepositoryInterface $starSystemTypeRepository; |
30
|
|
|
|
31
|
|
|
public function __construct( |
32
|
|
|
ShowSectionRequestInterface $request, |
33
|
|
|
LayerRepositoryInterface $layerRepository, |
34
|
|
|
StarmapUiFactoryInterface $starmapUiFactory, |
35
|
|
|
MapFieldTypeRepositoryInterface $mapFieldTypeRepository, |
36
|
|
|
StarSystemTypeRepositoryInterface $starSystemTypeRepository |
37
|
|
|
) { |
38
|
|
|
$this->request = $request; |
39
|
|
|
$this->layerRepository = $layerRepository; |
40
|
|
|
$this->mapFieldTypeRepository = $mapFieldTypeRepository; |
41
|
|
|
$this->starmapUiFactory = $starmapUiFactory; |
42
|
|
|
$this->starSystemTypeRepository = $starSystemTypeRepository; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function handle(GameControllerInterface $game): void |
46
|
|
|
{ |
47
|
|
|
$layerId = $this->request->getLayerId(); |
48
|
|
|
$layer = $this->layerRepository->find($layerId); |
49
|
|
|
|
50
|
|
|
$xCoordinate = $this->request->getXCoordinate($layer); |
|
|
|
|
51
|
|
|
$yCoordinate = $this->request->getYCoordinate($layer); |
|
|
|
|
52
|
|
|
$section_id = $this->request->getSectionId(); |
53
|
|
|
|
54
|
|
|
$maxx = $xCoordinate * MapEnum::FIELDS_PER_SECTION; |
55
|
|
|
$minx = $maxx - MapEnum::FIELDS_PER_SECTION + 1; |
56
|
|
|
$maxy = $yCoordinate * MapEnum::FIELDS_PER_SECTION; |
57
|
|
|
$miny = $maxy - MapEnum::FIELDS_PER_SECTION + 1; |
58
|
|
|
|
59
|
|
|
$fields = []; |
60
|
|
|
foreach (range($miny, $maxy) as $value) { |
61
|
|
|
$fields[] = $this->starmapUiFactory->createYRow($layerId, $value, $minx, $maxx); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if ($yCoordinate - 1 >= 1) { |
65
|
|
|
$game->setTemplateVar( |
66
|
|
|
'TOP_PREVIEW_ROW', |
67
|
|
|
$this->starmapUiFactory->createYRow($layerId, $yCoordinate * MapEnum::FIELDS_PER_SECTION - MapEnum::FIELDS_PER_SECTION, $minx, $maxx)->getFields() |
68
|
|
|
); |
69
|
|
|
} else { |
70
|
|
|
$game->setTemplateVar('TOP_PREVIEW_ROW', false); |
71
|
|
|
} |
72
|
|
|
if ($yCoordinate * MapEnum::FIELDS_PER_SECTION + 1 <= $layer->getHeight()) { |
73
|
|
|
$game->setTemplateVar( |
74
|
|
|
'BOTTOM_PREVIEW_ROW', |
75
|
|
|
$this->starmapUiFactory->createYRow($layerId, $yCoordinate * MapEnum::FIELDS_PER_SECTION + 1, $minx, $maxx)->getFields() |
76
|
|
|
); |
77
|
|
|
} else { |
78
|
|
|
$game->setTemplateVar( |
79
|
|
|
'BOTTOM_PREVIEW_ROW', |
80
|
|
|
false |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
if ($xCoordinate - 1 >= 1) { |
84
|
|
|
$row = []; |
85
|
|
|
for ($i = $miny; $i <= $maxy; $i++) { |
86
|
|
|
$row[] = $this->starmapUiFactory->createYRow($layerId, $i, $minx - 1, $minx - 1); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$game->setTemplateVar( |
90
|
|
|
'LEFT_PREVIEW_ROW', |
91
|
|
|
$row |
92
|
|
|
); |
93
|
|
|
} else { |
94
|
|
|
$game->setTemplateVar( |
95
|
|
|
'LEFT_PREVIEW_ROW', |
96
|
|
|
false |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if ($xCoordinate * MapEnum::FIELDS_PER_SECTION + 1 <= $layer->getWidth()) { |
101
|
|
|
$row = []; |
102
|
|
|
for ($i = $miny; $i <= $maxy; $i++) { |
103
|
|
|
$row[] = $this->starmapUiFactory->createYRow($layerId, $i, $maxx + 1, $maxx + 1); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$game->setTemplateVar( |
107
|
|
|
'RIGHT_PREVIEW_ROW', |
108
|
|
|
$row |
109
|
|
|
); |
110
|
|
|
} else { |
111
|
|
|
$game->setTemplateVar( |
112
|
|
|
'RIGHT_PREVIEW_ROW', |
113
|
|
|
false |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$possibleFieldTypes = ['row_0', 'row_1', 'row_2', 'row_3', 'row_4', 'row_5']; |
118
|
|
|
foreach ($this->mapFieldTypeRepository->findAll() as $key => $value) { |
119
|
|
|
if ($value->getIsSystem()) { |
120
|
|
|
continue; |
121
|
|
|
} |
122
|
|
|
$possibleFieldTypes['row_' . ($key % 6)][] = $value; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$possibleSystemTypes = ['row_0', 'row_1', 'row_2', 'row_3', 'row_4', 'row_5']; |
126
|
|
|
foreach ($this->starSystemTypeRepository->findAll() as $key => $value) { |
127
|
|
|
if (!$value->getIsGenerateable()) { |
128
|
|
|
continue; |
129
|
|
|
} |
130
|
|
|
$possibleSystemTypes['row_' . ($key % 6)][] = $value; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$game->setTemplateFile('html/admin/mapeditor_section.xhtml'); |
134
|
|
|
$game->appendNavigationPart('/admin/?SHOW_MAP_EDITOR=1', _('Karteneditor')); |
135
|
|
|
$game->appendNavigationPart( |
136
|
|
|
sprintf( |
137
|
|
|
'/admin/?SHOW_EDIT_MAP_SECTION=1&x=%d&y=%d&sec=%d&layerid=%d', |
138
|
|
|
$xCoordinate, |
139
|
|
|
$yCoordinate, |
140
|
|
|
$section_id, |
141
|
|
|
$layerId |
142
|
|
|
), |
143
|
|
|
sprintf(_('Sektion %d anzeigen'), $section_id) |
144
|
|
|
); |
145
|
|
|
$game->setPageTitle(_('Sektion anzeigen')); |
146
|
|
|
$game->setTemplateVar('POSSIBLE_FIELD_TYPES', $possibleFieldTypes); |
147
|
|
|
$game->setTemplateVar('POSSIBLE_SYSTEM_TYPES', $possibleSystemTypes); |
148
|
|
|
$game->setTemplateVar('FIELDS_PER_SECTION', MapEnum::FIELDS_PER_SECTION); |
149
|
|
|
$game->setTemplateVar('SECTION_ID', $section_id); |
150
|
|
|
$game->setTemplateVar('HEAD_ROW', range($minx, $maxx)); |
151
|
|
|
$game->setTemplateVar('MAP_FIELDS', $fields); |
152
|
|
|
$game->setTemplateVar('HAS_NAV_LEFT', $xCoordinate > 1); |
153
|
|
|
$game->setTemplateVar('HAS_NAV_RIGHT', $xCoordinate * MapEnum::FIELDS_PER_SECTION < $layer->getWidth()); |
154
|
|
|
$game->setTemplateVar('HAS_NAV_UP', $yCoordinate > 1); |
155
|
|
|
$game->setTemplateVar('HAS_NAV_DOWN', $yCoordinate * MapEnum::FIELDS_PER_SECTION < $layer->getHeight()); |
156
|
|
|
$game->setTemplateVar( |
157
|
|
|
'NAV_UP', |
158
|
|
|
sprintf( |
159
|
|
|
'?%s=1&x=%d&y=%d&sec=%d&layerid=%d', |
160
|
|
|
static::VIEW_IDENTIFIER, |
161
|
|
|
$xCoordinate, |
162
|
|
|
$yCoordinate > 1 ? $yCoordinate - 1 : 1, |
163
|
|
|
$section_id - 6, |
164
|
|
|
$layerId |
165
|
|
|
) |
166
|
|
|
); |
167
|
|
|
$game->setTemplateVar( |
168
|
|
|
'NAV_DOWN', |
169
|
|
|
sprintf( |
170
|
|
|
"?%s=1&x=%d&y=%d&sec=%d&layerid=%d", |
171
|
|
|
static::VIEW_IDENTIFIER, |
172
|
|
|
$xCoordinate, |
173
|
|
|
$yCoordinate + 1 > $layer->getHeight() / MapEnum::FIELDS_PER_SECTION ? $yCoordinate : $yCoordinate + 1, |
174
|
|
|
$section_id + 6, |
175
|
|
|
$layerId |
176
|
|
|
) |
177
|
|
|
); |
178
|
|
|
$game->setTemplateVar( |
179
|
|
|
'NAV_LEFT', |
180
|
|
|
sprintf( |
181
|
|
|
"?%s=1&x=%d&y=%d&sec=%d&layerid=%d", |
182
|
|
|
static::VIEW_IDENTIFIER, |
183
|
|
|
$xCoordinate > 1 ? $xCoordinate - 1 : 1, |
184
|
|
|
$yCoordinate, |
185
|
|
|
$section_id - 1, |
186
|
|
|
$layerId |
187
|
|
|
) |
188
|
|
|
); |
189
|
|
|
$game->setTemplateVar( |
190
|
|
|
'NAV_RIGHT', |
191
|
|
|
sprintf( |
192
|
|
|
'?%s=1&x=%d&y=%d&sec=%d&layerid=%d', |
193
|
|
|
static::VIEW_IDENTIFIER, |
194
|
|
|
$xCoordinate + 1 > $layer->getWidth() / MapEnum::FIELDS_PER_SECTION ? $xCoordinate : $xCoordinate + 1, |
195
|
|
|
$yCoordinate, |
196
|
|
|
$section_id + 1, |
197
|
|
|
$layerId |
198
|
|
|
) |
199
|
|
|
); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|