Skip to content

Commit 049b111

Browse files
committed
fix map behaviour
1 parent 0777a58 commit 049b111

File tree

15 files changed

+958
-161
lines changed

15 files changed

+958
-161
lines changed

src/Lib/Map/VisualPanel/CellData.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stu\Lib\Map\VisualPanel;
6+
7+
abstract class CellData
8+
{
9+
private ?string $subspaceCode;
10+
private ?string $displayCount;
11+
12+
public function __construct(
13+
?string $subspaceCode,
14+
?string $displayCount
15+
) {
16+
$this->subspaceCode = $subspaceCode;
17+
$this->displayCount = $displayCount;
18+
}
19+
20+
public function getSubspaceCode(): ?string
21+
{
22+
return $this->subspaceCode;
23+
}
24+
25+
public function getDisplayCount(): ?string
26+
{
27+
return $this->displayCount;
28+
}
29+
}

src/Lib/Map/VisualPanel/LssCellData.php

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stu\Lib\Map\VisualPanel;
6+
7+
class MapCellData extends CellData
8+
{
9+
private ?string $mapGraphicPath;
10+
11+
public function __construct(
12+
?string $mapGraphicPath,
13+
?string $subspaceCode,
14+
?string $displayCount
15+
) {
16+
parent::__construct($subspaceCode, $displayCount);
17+
18+
$this->mapGraphicPath = $mapGraphicPath;
19+
}
20+
21+
public function getMapGraphicPath(): ?string
22+
{
23+
return $this->mapGraphicPath;
24+
}
25+
}

src/Lib/Map/VisualPanel/SignaturePanelEntry.php

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
class SignaturePanelEntry implements VisualPanelElementInterface
1111
{
12-
public const ONLY_BACKGROUND_IMAGE = 1;
13-
1412
protected VisualPanelEntryData $data;
1513

1614
private ?LayerInterface $layer;
@@ -29,39 +27,22 @@ public function __construct(
2927
$this->encodedMap = $encodedMap;
3028
}
3129

32-
public function getLssCellData(): LssCellData
33-
{
34-
return new LssCellData(
35-
$this->getSystemBackgroundId(),
36-
$this->getFieldGraphicID(),
37-
$this->getMapGraphicPath(),
38-
$this->data->getShieldState(),
39-
$this->getSubspaceCode(),
40-
$this->getDisplayCount(),
41-
);
42-
}
43-
44-
private function getFieldGraphicID(): ?int
45-
{
46-
$fieldId = $this->data->getMapfieldType();
47-
48-
if ($fieldId === self::ONLY_BACKGROUND_IMAGE) {
49-
return null;
50-
}
51-
52-
return $fieldId;
53-
}
54-
55-
private function getSystemBackgroundId(): ?string
30+
public function getCellData(): MapCellData|SystemCellData
5631
{
5732
if ($this->data->getSystemId() === null) {
58-
return null;
33+
return new MapCellData(
34+
$this->getMapGraphicPath(),
35+
$this->getSubspaceCode(),
36+
$this->getDisplayCount(),
37+
);
5938
}
60-
61-
return sprintf(
62-
'%02d%02d',
39+
return new SystemCellData(
40+
$this->data->getPosX(),
6341
$this->data->getPosY(),
64-
$this->data->getPosX()
42+
$this->data->getMapfieldType(),
43+
$this->data->getShieldState(),
44+
$this->getSubspaceCode(),
45+
$this->getDisplayCount(),
6546
);
6647
}
6748

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stu\Lib\Map\VisualPanel;
6+
7+
class SystemCellData extends CellData
8+
{
9+
public const ONLY_BACKGROUND_IMAGE = 1;
10+
11+
private int $x;
12+
private int $y;
13+
private int $systemFieldId;
14+
private bool $colonyShieldState;
15+
16+
public function __construct(
17+
int $x,
18+
int $y,
19+
int $systemFieldId,
20+
bool $colonyShieldState,
21+
?string $subspaceCode,
22+
?string $displayCount
23+
) {
24+
parent::__construct($subspaceCode, $displayCount);
25+
26+
$this->x = $x;
27+
$this->y = $y;
28+
$this->systemFieldId = $systemFieldId;
29+
$this->colonyShieldState = $colonyShieldState;
30+
}
31+
32+
public function getSystemBackgroundId(): string
33+
{
34+
return sprintf(
35+
'%02d%02d',
36+
$this->y,
37+
$this->x
38+
);
39+
}
40+
41+
public function getSystemFieldId(): ?int
42+
{
43+
if ($this->systemFieldId === self::ONLY_BACKGROUND_IMAGE) {
44+
return null;
45+
}
46+
47+
return $this->systemFieldId;
48+
}
49+
50+
public function getColonyShieldState(): bool
51+
{
52+
return $this->colonyShieldState;
53+
}
54+
}

src/Lib/Map/VisualPanel/VisualNavPanelEntry.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ public function isClickAble(): bool
115115
if (!$this->currentShip->canMove()) {
116116
return false;
117117
}
118-
return !$this->isCurrentShipPosition();
118+
119+
return !$this->isCurrentShipPosition()
120+
&& ($this->data->getPosX() === $this->currentShip->getPosX() || $this->data->getPosY() === $this->currentShip->getPosY());
119121
}
120122

121123
public function getOnClick(): string

src/Module/Database/View/DatabaseEntry/DatabaseEntry.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
use Stu\Component\Database\DatabaseEntryTypeEnum;
88
use Stu\Component\Ship\Crew\ShipCrewCalculatorInterface;
99
use Stu\Exception\AccessViolation;
10-
use Stu\Lib\Map\VisualPanel\SignaturePanelEntry;
11-
use Stu\Lib\Map\VisualPanel\VisualPanelEntryData;
10+
use Stu\Lib\Map\VisualPanel\SystemCellData;
1211
use Stu\Module\Control\GameControllerInterface;
1312
use Stu\Module\Control\ViewControllerInterface;
1413
use Stu\Module\Database\View\Category\Category;
@@ -151,7 +150,7 @@ protected function addSpecialVars(GameControllerInterface $game, DatabaseEntryIn
151150
$userHasColonyInSystem = $this->hasUserColonyInSystem($game->getUser(), $entry_object_id);
152151
foreach ($starSystem->getFields() as $obj) {
153152
$fields['fields'][$obj->getSY()][] = [
154-
'entry' => $this->createSignaturePanelEntry($obj),
153+
'systemCellData' => $this->createSystemCellData($obj),
155154
'colony' => $obj->getColony(),
156155
'showPm' => $userHasColonyInSystem && $this->showPmHref($obj, $game->getUser())
157156
];
@@ -164,13 +163,16 @@ protected function addSpecialVars(GameControllerInterface $game, DatabaseEntryIn
164163
}
165164
}
166165

167-
private function createSignaturePanelEntry(StarSystemMapInterface $systemMap): SignaturePanelEntry
166+
private function createSystemCellData(StarSystemMapInterface $systemMap): SystemCellData
168167
{
169-
$data = new VisualPanelEntryData();
170-
$data->setMapfieldType($systemMap->getFieldId())
171-
->setSystemId($systemMap->getSystemId());
172-
173-
return new SignaturePanelEntry($data, null, null);
168+
return new SystemCellData(
169+
$systemMap->getSx(),
170+
$systemMap->getSy(),
171+
$systemMap->getFieldId(),
172+
false,
173+
null,
174+
null
175+
);
174176
}
175177

176178
private function hasUserColonyInSystem(UserInterface $user, int $systemId): bool

src/Module/Starmap/Lib/YRow.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use RuntimeException;
88
use Stu\Component\Map\EncodedMapInterface;
9+
use Stu\Lib\Map\VisualPanel\SystemCellData;
910
use Stu\Module\Admin\View\Map\EditSection\MapItem;
1011
use Stu\Orm\Entity\LayerInterface;
1112
use Stu\Orm\Entity\StarSystemInterface;
@@ -25,7 +26,7 @@ class YRow
2526

2627
protected int|StarSystemInterface $system;
2728

28-
/** @var null|array<MapItem>|array<StarSystemMapInterface> */
29+
/** @var null|array<MapItem>|array<SystemCellData> */
2930
protected $fields;
3031

3132
private MapRepositoryInterface $mapRepository;
@@ -55,7 +56,7 @@ public function __construct(
5556
}
5657

5758
/**
58-
* @return array<MapItem>|array<StarSystemMapInterface>
59+
* @return array<MapItem>|array<SystemCellData>
5960
*/
6061
public function getFields(): array
6162
{
@@ -85,17 +86,20 @@ public function getFields(): array
8586
}
8687

8788
/**
88-
* @return array<MapItem>|array<StarSystemMapInterface>
89+
* @return array<MapItem>|array<SystemCellData>
8990
*/
9091
public function getSystemFields(): array
9192
{
9293
if ($this->fields === null) {
9394
$this->fields = [];
9495

9596
if ($this->system instanceof StarSystemInterface) {
96-
$this->fields = array_filter(
97-
$this->system->getFields()->toArray(),
98-
fn (StarSystemMapInterface $systemMap) => $systemMap->getSy() === $this->row
97+
$this->fields = array_map(
98+
fn (StarSystemMapInterface $systemMap) => $this->mapSystemMapToSystemCellData($systemMap),
99+
array_filter(
100+
$this->system->getFields()->toArray(),
101+
fn (StarSystemMapInterface $systemMap) => $systemMap->getSy() === $this->row
102+
)
99103
);
100104
} else {
101105

@@ -106,14 +110,26 @@ public function getSystemFields(): array
106110
$this->row
107111
);
108112
if ($systemMap !== null) {
109-
$this->fields[] = $systemMap;
113+
$this->fields[] = $this->mapSystemMapToSystemCellData($systemMap);
110114
}
111115
}
112116
}
113117
}
114118
return $this->fields;
115119
}
116120

121+
private function mapSystemMapToSystemCellData(StarSystemMapInterface $systemMap): SystemCellData
122+
{
123+
return new SystemCellData(
124+
$systemMap->getSx(),
125+
$systemMap->getSy(),
126+
$systemMap->getFieldId(),
127+
false,
128+
null,
129+
null
130+
);
131+
}
132+
117133
/**
118134
* @return int
119135
*/

src/html/admin/adminmacros.xhtml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@
2222
style="width: ${viewportScale}vw; height: ${viewportScale}vw; font-size: ${viewportFont}vw;"
2323
tal:attributes="class entry/getCSSClass" tal:content="entry/getRow">.</td>
2424
<tal:block tal:condition="not:entry/isRowIndex">
25-
<td tal:define="lssCellData entry/getLssCellData"
26-
tal:attributes="class entry/getCSSClass"
27-
style="background-image: url(../assets/map/${lssCellData/getMapGraphicPath}); width: ${viewportScale}vw; height: ${viewportScale}vw; background-size: cover;">
28-
<tal:block tal:define="code lssCellData/getSubspaceCode">
25+
<td tal:define="cellData entry/getCellData" tal:attributes="class entry/getCSSClass"
26+
style="background-image: url(../assets/map/${cellData/getMapGraphicPath}); width: ${viewportScale}vw; height: ${viewportScale}vw; background-size: cover;">
27+
<tal:block tal:define="code cellData/getSubspaceCode">
2928
<div class="imgOverlayText">
3029
<img tal:condition="code" src="../assets/subspace/generated/${code}.png"
3130
style="z-index: 2; width: ${viewportScale}vw; height: ${viewportScale}vw;" />
32-
<div tal:condition="lssCellData/getDisplayCount"
31+
<div tal:condition="cellData/getDisplayCount"
3332
style="font-size: ${viewportFont}vw; color: cyan;" class="centered"
34-
tal:content="lssCellData/getDisplayCount">
33+
tal:content="cellData/getDisplayCount">
3534
.
3635
</div>
3736
</div>

0 commit comments

Comments
 (0)