-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrating FleetJourney component with other components
- Loading branch information
Showing
18 changed files
with
273 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...n/Component/FleetJourney/EventListener/StationFleetOnReachingTargetPointEventListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheGame\Application\Component\FleetJourney\EventListener; | ||
|
||
use TheGame\Application\Component\FleetJourney\Domain\Event\FleetHasReachedJourneyTargetPointEvent; | ||
use TheGame\Application\Component\FleetJourney\Domain\FleetId; | ||
use TheGame\Application\Component\FleetJourney\Domain\MissionType; | ||
use TheGame\Application\Component\FleetJourney\FleetRepositoryInterface; | ||
use TheGame\Application\Component\Galaxy\Bridge\NavigatorInterface; | ||
use TheGame\Application\SharedKernel\Domain\GalaxyPoint; | ||
use TheGame\Application\SharedKernel\Exception\InconsistentModelException; | ||
|
||
final class StationFleetOnReachingTargetPointEventListener | ||
{ | ||
public function __construct( | ||
private readonly FleetRepositoryInterface $fleetRepository, | ||
private readonly NavigatorInterface $navigator, | ||
) { | ||
|
||
} | ||
|
||
public function __invoke(FleetHasReachedJourneyTargetPointEvent $event): void | ||
{ | ||
$mission = MissionType::from($event->getMission()); | ||
if ($mission !== MissionType::Stationing) { | ||
return; | ||
} | ||
|
||
$joiningFleetId = new FleetId($event->getFleetId()); | ||
$fleetJoiningPlanet = $this->fleetRepository->find($joiningFleetId); | ||
if ($fleetJoiningPlanet === null) { | ||
throw new InconsistentModelException(sprintf('Fleet %s doesn\'t exist', $event->getFleetId())); | ||
} | ||
|
||
$stationingPoint = GalaxyPoint::fromString($event->getTargetGalaxyPoint()); | ||
$planetId = $this->navigator->getPlanetId($stationingPoint); | ||
$fleetCurrentlyStationingOnPlanet = $this->fleetRepository->findStationingOnPlanet($planetId); | ||
if ($fleetCurrentlyStationingOnPlanet === null) { | ||
$fleetJoiningPlanet->landOnPlanet($stationingPoint); | ||
|
||
return; | ||
} | ||
|
||
$fleetCurrentlyStationingOnPlanet->merge($fleetJoiningPlanet); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...n/Component/ResourceStorage/EventListener/TakeResourcesOnStartingJourneyEventListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheGame\Application\Component\ResourceStorage\EventListener; | ||
|
||
use TheGame\Application\Component\FleetJourney\Domain\Event\FleetHasStartedJourneyEvent; | ||
use TheGame\Application\Component\ResourceStorage\Command\UseResourceCommand; | ||
use TheGame\Application\SharedKernel\CommandBusInterface; | ||
|
||
final class TakeResourcesOnStartingJourneyEventListener | ||
{ | ||
public function __construct( | ||
private readonly CommandBusInterface $commandBus, | ||
) { | ||
} | ||
|
||
public function __invoke(FleetHasStartedJourneyEvent $event): void | ||
{ | ||
foreach ($event->getResourcesLoad() as $resourceId => $amount) { | ||
$command = new UseResourceCommand( | ||
$event->getPlanetId(), | ||
$resourceId, | ||
$amount, | ||
); | ||
$this->commandBus->dispatch($command); | ||
} | ||
|
||
foreach ($event->getFuelRequirements() as $resourceId => $amount) { | ||
$command = new UseResourceCommand( | ||
$event->getPlanetId(), | ||
$resourceId, | ||
$amount, | ||
); | ||
$this->commandBus->dispatch($command); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...urceStorage/EventListener/UnloadResourcesAfterReachingJourneyReturnPointEventListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheGame\Application\Component\ResourceStorage\EventListener; | ||
|
||
use TheGame\Application\Component\FleetJourney\Domain\Event\FleetHasReachedJourneyReturnPointEvent; | ||
use TheGame\Application\Component\Galaxy\Bridge\NavigatorInterface; | ||
use TheGame\Application\Component\ResourceStorage\Command\DispatchResourcesCommand; | ||
use TheGame\Application\SharedKernel\CommandBusInterface; | ||
use TheGame\Application\SharedKernel\Domain\GalaxyPoint; | ||
|
||
final class UnloadResourcesAfterReachingJourneyReturnPointEventListener | ||
{ | ||
public function __construct( | ||
private readonly NavigatorInterface $navigator, | ||
private readonly CommandBusInterface $commandBus, | ||
) { | ||
} | ||
|
||
public function __invoke(FleetHasReachedJourneyReturnPointEvent $event): void | ||
{ | ||
$returnGalaxyPoint = GalaxyPoint::fromString($event->getStartGalaxyPoint()); | ||
$planetId = $this->navigator->getPlanetId($returnGalaxyPoint); | ||
|
||
foreach ($event->getResourcesLoad() as $resourceId => $amount) { | ||
$command = new DispatchResourcesCommand( | ||
$planetId->getUuid(), | ||
$resourceId, | ||
$amount, | ||
); | ||
$this->commandBus->dispatch($command); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...urceStorage/EventListener/UnloadResourcesAfterReachingJourneyTargetPointEventListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheGame\Application\Component\ResourceStorage\EventListener; | ||
|
||
use TheGame\Application\Component\FleetJourney\Domain\Event\FleetHasReachedJourneyTargetPointEvent; | ||
use TheGame\Application\Component\Galaxy\Bridge\NavigatorInterface; | ||
use TheGame\Application\Component\ResourceStorage\Command\DispatchResourcesCommand; | ||
use TheGame\Application\SharedKernel\CommandBusInterface; | ||
use TheGame\Application\SharedKernel\Domain\GalaxyPoint; | ||
|
||
final class UnloadResourcesAfterReachingJourneyTargetPointEventListener | ||
{ | ||
public function __construct( | ||
private readonly NavigatorInterface $navigator, | ||
private readonly CommandBusInterface $commandBus, | ||
) { | ||
} | ||
|
||
public function __invoke(FleetHasReachedJourneyTargetPointEvent $event): void | ||
{ | ||
$targetGalaxyPoint = GalaxyPoint::fromString($event->getTargetGalaxyPoint()); | ||
$planetId = $this->navigator->getPlanetId($targetGalaxyPoint); | ||
|
||
foreach ($event->getResourcesLoad() as $resourceId => $amount) { | ||
$command = new DispatchResourcesCommand( | ||
$planetId->getUuid(), | ||
$resourceId, | ||
$amount, | ||
); | ||
$this->commandBus->dispatch($command); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.