Adds the possibility to disconnect two scenes.
This commit is contained in:
@@ -30,7 +30,7 @@ class SceneConnectCommand extends BaseCommand
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:connect')
|
||||
->setDescription('Connects to scenes.')
|
||||
->setDescription('Connects two scenes.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument(
|
||||
@@ -81,7 +81,7 @@ class SceneConnectCommand extends BaseCommand
|
||||
|
||||
/** @var ?Scene $outgoingScene */
|
||||
$outgoingScene = $sceneRepository->find($input->getArgument("outgoing"));
|
||||
/** @var ?Scene $outgoingScene */
|
||||
/** @var ?Scene $incomingScene */
|
||||
$incomingScene = $sceneRepository->find($input->getArgument("incoming"));
|
||||
|
||||
// Check of scenes actually exist
|
||||
@@ -147,6 +147,8 @@ class SceneConnectCommand extends BaseCommand
|
||||
// Commit changes
|
||||
$em->flush();
|
||||
|
||||
$io->success("The two scenes were successfully connected.");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use LotGD\Core\Models\Character;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneConnectable;
|
||||
use LotGD\Core\Models\SceneConnection;
|
||||
use LotGD\Core\Models\SceneConnectionGroup;
|
||||
use LotGD\Core\Models\SceneTemplate;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneDisconnectCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:disconnect')
|
||||
->setDescription('Disconnects two scenes.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument(
|
||||
"scene1",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Outgoing scene ID",
|
||||
),
|
||||
new InputArgument(
|
||||
"scene2",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Incoming scene ID",
|
||||
),
|
||||
])
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$sceneRepository = $em->getRepository(Scene::class);
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
/** @var Scene $scene1 */
|
||||
$scene1 = $sceneRepository->find($input->getArgument("scene1"));
|
||||
/** @var Scene $scene2 */
|
||||
$scene2 = $sceneRepository->find($input->getArgument("scene2"));
|
||||
|
||||
if (!$scene1) {
|
||||
$io->error("Scene with id {$input->getArgument('scene1')} was not found.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if (!$scene2) {
|
||||
$io->error("Scene with id {$input->getArgument('scene2')} was not found.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$connection = $scene1->getConnectionTo($scene2);
|
||||
|
||||
if (!$connection) {
|
||||
$io->error("The to given scenes do not share a connection.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// Commit changes
|
||||
$em->remove($connection);
|
||||
$em->flush();
|
||||
|
||||
$io->success("The connections between the two given scenes was removed.");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,9 @@ use LotGD\Core\Console\Command\Database\DatabaseSchemaUpdateCommand;
|
||||
use LotGD\Core\Console\Command\Module\ModuleRegisterCommand;
|
||||
use LotGD\Core\Console\Command\Module\ModuleValidateCommand;
|
||||
use LotGD\Core\Console\Command\Scene\SceneAddCommand;
|
||||
use LotGD\Core\Console\Command\Scene\SceneListCommand;
|
||||
use LotGD\Core\Console\Command\Scene\SceneConnectCommand;
|
||||
use LotGD\Core\Console\Command\Scene\SceneListCommand;
|
||||
use LotGD\Core\Console\Command\Scene\SceneDisconnectCommand;
|
||||
use LotGD\Core\Console\Command\SceneTemplates\SceneTemplateListCommand;
|
||||
use LotGD\Core\Game;
|
||||
use Symfony\Component\Console\Application;
|
||||
@@ -54,6 +55,7 @@ class Main
|
||||
$this->application->add(new SceneListCommand($this->game));
|
||||
$this->application->add(new SceneAddCommand($this->game));
|
||||
$this->application->add(new SceneConnectCommand($this->game));
|
||||
$this->application->add(new SceneDisconnectCommand($this->game));
|
||||
$this->application->add(new SceneTemplateListCommand($this->game));
|
||||
|
||||
// Add additional ones
|
||||
|
||||
+28
-5
@@ -6,6 +6,8 @@ namespace LotGD\Core\Models;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping\Entity;
|
||||
use Doctrine\ORM\Mapping\Id;
|
||||
use Doctrine\ORM\Mapping\OneToMany;
|
||||
use Doctrine\ORM\Mapping\Table;
|
||||
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
@@ -30,27 +32,31 @@ class Scene implements CreateableInterface, SceneConnectable
|
||||
use PropertyManager;
|
||||
|
||||
/** @Id @Column(type="string", length=36, unique=True, name="id", options={"fixed"=true}) */
|
||||
protected $id;
|
||||
protected string $id;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="SceneConnectionGroup", mappedBy="scene", cascade={"persist", "remove"})
|
||||
* @var ?Collection<SceneConnectionGroup>
|
||||
*/
|
||||
private $connectionGroups = null;
|
||||
private ?Collection $connectionGroups = null;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="SceneConnection", mappedBy="outgoingScene", cascade={"persist", "remove"})
|
||||
* @var ?Collection<SceneConnection>
|
||||
*/
|
||||
private $outgoingConnections = null;
|
||||
private ?Collection $outgoingConnections = null;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="SceneConnection", mappedBy="incomingScene", cascade={"persist", "remove"})
|
||||
* @var ?Collection<SceneConnection>
|
||||
*/
|
||||
private $incomingConnections = null;
|
||||
private ?Collection $incomingConnections = null;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="SceneProperty", mappedBy="owner", cascade={"persist", "remove"})
|
||||
* @var ?Collection<SceneProperty>
|
||||
*/
|
||||
private $properties;
|
||||
private ?Collection $properties;
|
||||
|
||||
// required for PropertyManager to now which class the properties belong to.
|
||||
private string $propertyClass = SceneProperty::class;
|
||||
@@ -221,6 +227,23 @@ class Scene implements CreateableInterface, SceneConnectable
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getConnectionTo(self $scene): ?SceneConnection
|
||||
{
|
||||
foreach ($this->outgoingConnections as $outgoingConnection) {
|
||||
if ($outgoingConnection->getIncomingScene() == $scene) {
|
||||
return $outgoingConnection;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->incomingConnections as $incomingConnection) {
|
||||
if ($incomingConnection->getOutgoingScene() == $scene) {
|
||||
return $incomingConnection;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all collections of this entity.
|
||||
* @return Collection
|
||||
|
||||
Reference in New Issue
Block a user