Skip to content

Commit

Permalink
fix map behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
g5bot committed Sep 10, 2023
1 parent 0777a58 commit 049b111
Show file tree
Hide file tree
Showing 15 changed files with 958 additions and 161 deletions.
29 changes: 29 additions & 0 deletions src/Lib/Map/VisualPanel/CellData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Stu\Lib\Map\VisualPanel;

abstract class CellData
{
private ?string $subspaceCode;
private ?string $displayCount;

public function __construct(
?string $subspaceCode,
?string $displayCount
) {
$this->subspaceCode = $subspaceCode;
$this->displayCount = $displayCount;
}

public function getSubspaceCode(): ?string
{
return $this->subspaceCode;
}

public function getDisplayCount(): ?string
{
return $this->displayCount;
}
}
61 changes: 0 additions & 61 deletions src/Lib/Map/VisualPanel/LssCellData.php

This file was deleted.

25 changes: 25 additions & 0 deletions src/Lib/Map/VisualPanel/MapCellData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Stu\Lib\Map\VisualPanel;

class MapCellData extends CellData
{
private ?string $mapGraphicPath;

public function __construct(
?string $mapGraphicPath,
?string $subspaceCode,
?string $displayCount
) {
parent::__construct($subspaceCode, $displayCount);

$this->mapGraphicPath = $mapGraphicPath;
}

public function getMapGraphicPath(): ?string
{
return $this->mapGraphicPath;
}
}
43 changes: 12 additions & 31 deletions src/Lib/Map/VisualPanel/SignaturePanelEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

class SignaturePanelEntry implements VisualPanelElementInterface
{
public const ONLY_BACKGROUND_IMAGE = 1;

protected VisualPanelEntryData $data;

private ?LayerInterface $layer;
Expand All @@ -29,39 +27,22 @@ public function __construct(
$this->encodedMap = $encodedMap;
}

public function getLssCellData(): LssCellData
{
return new LssCellData(
$this->getSystemBackgroundId(),
$this->getFieldGraphicID(),
$this->getMapGraphicPath(),
$this->data->getShieldState(),
$this->getSubspaceCode(),
$this->getDisplayCount(),
);
}

private function getFieldGraphicID(): ?int
{
$fieldId = $this->data->getMapfieldType();

if ($fieldId === self::ONLY_BACKGROUND_IMAGE) {
return null;
}

return $fieldId;
}

private function getSystemBackgroundId(): ?string
public function getCellData(): MapCellData|SystemCellData
{
if ($this->data->getSystemId() === null) {
return null;
return new MapCellData(
$this->getMapGraphicPath(),
$this->getSubspaceCode(),
$this->getDisplayCount(),
);
}

return sprintf(
'%02d%02d',
return new SystemCellData(
$this->data->getPosX(),
$this->data->getPosY(),
$this->data->getPosX()
$this->data->getMapfieldType(),
$this->data->getShieldState(),
$this->getSubspaceCode(),
$this->getDisplayCount(),
);
}

Expand Down
54 changes: 54 additions & 0 deletions src/Lib/Map/VisualPanel/SystemCellData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace Stu\Lib\Map\VisualPanel;

class SystemCellData extends CellData
{
public const ONLY_BACKGROUND_IMAGE = 1;

private int $x;
private int $y;
private int $systemFieldId;
private bool $colonyShieldState;

public function __construct(
int $x,
int $y,
int $systemFieldId,
bool $colonyShieldState,
?string $subspaceCode,
?string $displayCount
) {
parent::__construct($subspaceCode, $displayCount);

$this->x = $x;
$this->y = $y;
$this->systemFieldId = $systemFieldId;
$this->colonyShieldState = $colonyShieldState;
}

public function getSystemBackgroundId(): string
{
return sprintf(
'%02d%02d',
$this->y,
$this->x
);
}

public function getSystemFieldId(): ?int
{
if ($this->systemFieldId === self::ONLY_BACKGROUND_IMAGE) {
return null;
}

return $this->systemFieldId;
}

public function getColonyShieldState(): bool
{
return $this->colonyShieldState;
}
}
4 changes: 3 additions & 1 deletion src/Lib/Map/VisualPanel/VisualNavPanelEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ public function isClickAble(): bool
if (!$this->currentShip->canMove()) {
return false;
}
return !$this->isCurrentShipPosition();

return !$this->isCurrentShipPosition()
&& ($this->data->getPosX() === $this->currentShip->getPosX() || $this->data->getPosY() === $this->currentShip->getPosY());
}

public function getOnClick(): string
Expand Down
20 changes: 11 additions & 9 deletions src/Module/Database/View/DatabaseEntry/DatabaseEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
use Stu\Component\Database\DatabaseEntryTypeEnum;
use Stu\Component\Ship\Crew\ShipCrewCalculatorInterface;
use Stu\Exception\AccessViolation;
use Stu\Lib\Map\VisualPanel\SignaturePanelEntry;
use Stu\Lib\Map\VisualPanel\VisualPanelEntryData;
use Stu\Lib\Map\VisualPanel\SystemCellData;
use Stu\Module\Control\GameControllerInterface;
use Stu\Module\Control\ViewControllerInterface;
use Stu\Module\Database\View\Category\Category;
Expand Down Expand Up @@ -151,7 +150,7 @@ protected function addSpecialVars(GameControllerInterface $game, DatabaseEntryIn
$userHasColonyInSystem = $this->hasUserColonyInSystem($game->getUser(), $entry_object_id);
foreach ($starSystem->getFields() as $obj) {
$fields['fields'][$obj->getSY()][] = [
'entry' => $this->createSignaturePanelEntry($obj),
'systemCellData' => $this->createSystemCellData($obj),
'colony' => $obj->getColony(),
'showPm' => $userHasColonyInSystem && $this->showPmHref($obj, $game->getUser())
];
Expand All @@ -164,13 +163,16 @@ protected function addSpecialVars(GameControllerInterface $game, DatabaseEntryIn
}
}

private function createSignaturePanelEntry(StarSystemMapInterface $systemMap): SignaturePanelEntry
private function createSystemCellData(StarSystemMapInterface $systemMap): SystemCellData
{
$data = new VisualPanelEntryData();
$data->setMapfieldType($systemMap->getFieldId())
->setSystemId($systemMap->getSystemId());

return new SignaturePanelEntry($data, null, null);
return new SystemCellData(
$systemMap->getSx(),
$systemMap->getSy(),
$systemMap->getFieldId(),
false,
null,
null
);
}

private function hasUserColonyInSystem(UserInterface $user, int $systemId): bool
Expand Down
30 changes: 23 additions & 7 deletions src/Module/Starmap/Lib/YRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use RuntimeException;
use Stu\Component\Map\EncodedMapInterface;
use Stu\Lib\Map\VisualPanel\SystemCellData;
use Stu\Module\Admin\View\Map\EditSection\MapItem;
use Stu\Orm\Entity\LayerInterface;
use Stu\Orm\Entity\StarSystemInterface;
Expand All @@ -25,7 +26,7 @@ class YRow

protected int|StarSystemInterface $system;

/** @var null|array<MapItem>|array<StarSystemMapInterface> */
/** @var null|array<MapItem>|array<SystemCellData> */
protected $fields;

private MapRepositoryInterface $mapRepository;
Expand Down Expand Up @@ -55,7 +56,7 @@ public function __construct(
}

/**
* @return array<MapItem>|array<StarSystemMapInterface>
* @return array<MapItem>|array<SystemCellData>
*/
public function getFields(): array
{
Expand Down Expand Up @@ -85,17 +86,20 @@ public function getFields(): array
}

/**
* @return array<MapItem>|array<StarSystemMapInterface>
* @return array<MapItem>|array<SystemCellData>
*/
public function getSystemFields(): array
{
if ($this->fields === null) {
$this->fields = [];

if ($this->system instanceof StarSystemInterface) {
$this->fields = array_filter(
$this->system->getFields()->toArray(),
fn (StarSystemMapInterface $systemMap) => $systemMap->getSy() === $this->row
$this->fields = array_map(
fn (StarSystemMapInterface $systemMap) => $this->mapSystemMapToSystemCellData($systemMap),
array_filter(
$this->system->getFields()->toArray(),
fn (StarSystemMapInterface $systemMap) => $systemMap->getSy() === $this->row
)
);
} else {

Expand All @@ -106,14 +110,26 @@ public function getSystemFields(): array
$this->row
);
if ($systemMap !== null) {
$this->fields[] = $systemMap;
$this->fields[] = $this->mapSystemMapToSystemCellData($systemMap);
}
}
}
}
return $this->fields;
}

private function mapSystemMapToSystemCellData(StarSystemMapInterface $systemMap): SystemCellData
{
return new SystemCellData(
$systemMap->getSx(),
$systemMap->getSy(),
$systemMap->getFieldId(),
false,
null,
null
);
}

/**
* @return int
*/
Expand Down
11 changes: 5 additions & 6 deletions src/html/admin/adminmacros.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@
style="width: ${viewportScale}vw; height: ${viewportScale}vw; font-size: ${viewportFont}vw;"
tal:attributes="class entry/getCSSClass" tal:content="entry/getRow">.</td>
<tal:block tal:condition="not:entry/isRowIndex">
<td tal:define="lssCellData entry/getLssCellData"
tal:attributes="class entry/getCSSClass"
style="background-image: url(../assets/map/${lssCellData/getMapGraphicPath}); width: ${viewportScale}vw; height: ${viewportScale}vw; background-size: cover;">
<tal:block tal:define="code lssCellData/getSubspaceCode">
<td tal:define="cellData entry/getCellData" tal:attributes="class entry/getCSSClass"
style="background-image: url(../assets/map/${cellData/getMapGraphicPath}); width: ${viewportScale}vw; height: ${viewportScale}vw; background-size: cover;">
<tal:block tal:define="code cellData/getSubspaceCode">
<div class="imgOverlayText">
<img tal:condition="code" src="../assets/subspace/generated/${code}.png"
style="z-index: 2; width: ${viewportScale}vw; height: ${viewportScale}vw;" />
<div tal:condition="lssCellData/getDisplayCount"
<div tal:condition="cellData/getDisplayCount"
style="font-size: ${viewportFont}vw; color: cyan;" class="centered"
tal:content="lssCellData/getDisplayCount">
tal:content="cellData/getDisplayCount">
.
</div>
</div>
Expand Down
Loading

0 comments on commit 049b111

Please sign in to comment.