Adds a command to remove scenes.

This commit is contained in:
Vassyli
2021-01-26 18:27:53 +01:00
committed by Basilius Sauter
parent dfd39cd1f8
commit 31387c1840
3 changed files with 120 additions and 2 deletions
@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Console\Command\Scene;
use LotGD\Core\Console\Command\BaseCommand;
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 SceneRemoveCommand extends BaseCommand
{
/**
* @inheritDoc
*/
protected function configure()
{
$this->setName('scene:remove')
->setDescription('Removes a scene.')
->setDefinition(
new InputDefinition([
new InputArgument(
"id",
mode: InputArgument::REQUIRED,
description: "Scene ID",
),
])
)
;
}
/**
* @inheritDoc
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$em = $this->game->getEntityManager();
$io = new SymfonyStyle($input, $output);
$sceneId = $input->getArgument("id");
// Get scene
/** @var Scene $scene */
$scene = $em->getRepository(Scene::class)->find($sceneId);
if (!$scene) {
$io->error("The scene with the ID {$sceneId} was not found.");
return Command::FAILURE;
}
if (!$scene->isRemovable()) {
$io->error("The scene with the ID {$sceneId} was marked as not removable. Please remove the responsible");
return Command::FAILURE;
}
// Mark for removal and flush
try {
$em->remove($scene);
$em->flush();
} catch (\Exception $e) {
$io->error("Removal of {$sceneId} was not possible: {$e->getMessage()}");
return Command::FAILURE;
}
$io->success("Scene was successfully removed.");
return Command::SUCCESS;
}
}
+13 -1
View File
@@ -13,6 +13,7 @@ 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\SceneRemoveCommand;
use LotGD\Core\Console\Command\Scene\SceneAddConnectionGroupCommand;
use LotGD\Core\Console\Command\Scene\SceneConnectCommand;
use LotGD\Core\Console\Command\Scene\SceneListCommand;
@@ -53,15 +54,26 @@ class Main
$this->application->add(new DatabaseInitCommand($this->game));
$this->application->add(new DatabaseSchemaUpdateCommand($this->game));
$this->application->add(new ConsoleCommand($this->game));
// Character commands
$this->application->add(new CharacterListCommand($this->game));
$this->application->add(new CharacterResetViewpointCommand($this->game));
// Scene commands
$this->application->add(new SceneListCommand($this->game));
$this->application->add(new SceneAddCommand($this->game));
$this->application->add(new SceneRemoveCommand($this->game));
$this->application->add(new SceneShowCommand($this->game));
// Scene connections
$this->application->add(new SceneConnectCommand($this->game));
$this->application->add(new SceneDisconnectCommand($this->game));
$this->application->add(new SceneShowCommand($this->game));
// Scene connection group
$this->application->add(new SceneAddConnectionGroupCommand($this->game));
$this->application->add(new SceneRemoveConnectionGroupCommand($this->game));
// Scene templates
$this->application->add(new SceneTemplateListCommand($this->game));
// Add additional ones
+24 -1
View File
@@ -9,6 +9,7 @@ use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\Column;
use LotGD\Core\Exceptions\ArgumentException;
use LotGD\Core\Tools\Model\Creator;
@@ -31,9 +32,15 @@ class Scene implements CreateableInterface, SceneConnectable
use SceneBasics;
use PropertyManager;
/** @Id @Column(type="string", length=36, unique=True, name="id", options={"fixed"=true}) */
/**
* @Id
* @Column(type="string", length=36, unique=True, name="id", options={"fixed"=true})
*/
protected string $id;
/** @Column(type="boolean", nullable=false, options={"default"=true}) */
protected bool $removeable = true;
/**
* @OneToMany(targetEntity="SceneConnectionGroup", mappedBy="scene", cascade={"persist", "remove"})
* @var ?Collection<SceneConnectionGroup>
@@ -84,6 +91,22 @@ class Scene implements CreateableInterface, SceneConnectable
$this->incomingConnections = new ArrayCollection();
}
/**
* @return bool
*/
public function isRemovable(): bool
{
return $this->removeable;
}
/**
* @param bool $removable
*/
public function setRemovable(bool $removable)
{
$this->removeable = $removable;
}
/**
* Returns the primary ID for this scene.
* @return int