diff --git a/src/Console/Command/Scene/SceneAddCommand.php b/src/Console/Command/Scene/SceneAddCommand.php index d29655d..36167ae 100644 --- a/src/Console/Command/Scene/SceneAddCommand.php +++ b/src/Console/Command/Scene/SceneAddCommand.php @@ -3,12 +3,9 @@ declare(strict_types=1); namespace LotGD\Core\Console\Command\Scene; +use Exception; 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; @@ -60,6 +57,7 @@ class SceneAddCommand extends BaseCommand protected function execute(InputInterface $input, OutputInterface $output): int { $em = $this->game->getEntityManager(); + $logger = $this->game->getLogger(); $io = new SymfonyStyle($input, $output); @@ -84,8 +82,18 @@ class SceneAddCommand extends BaseCommand "template" => $template, ]); - $em->persist($scene); - $em->flush(); + try { + $em->persist($scene); + + // Commit changes + $em->flush(); + } catch (Exception $e) { + $io->error("Persisting of the scene was not possible. Reason: {$e->getMessage()}."); + return Command::FAILURE; + } + + $io->success("Scene was successfully created. ID: {$scene->getId()}."); + $logger->info("{$scene} was created."); return Command::SUCCESS; } diff --git a/src/Console/Command/Scene/SceneAddConnectionGroupCommand.php b/src/Console/Command/Scene/SceneAddConnectionGroupCommand.php index e33df2c..0083f5a 100644 --- a/src/Console/Command/Scene/SceneAddConnectionGroupCommand.php +++ b/src/Console/Command/Scene/SceneAddConnectionGroupCommand.php @@ -3,19 +3,15 @@ declare(strict_types=1); namespace LotGD\Core\Console\Command\Scene; +use Exception; 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; @@ -47,6 +43,7 @@ class SceneAddConnectionGroupCommand extends BaseCommand protected function execute(InputInterface $input, OutputInterface $output): int { $em = $this->game->getEntityManager(); + $logger = $this->game->getLogger(); $io = new SymfonyStyle($input, $output); @@ -69,14 +66,18 @@ class SceneAddConnectionGroupCommand extends BaseCommand // Add try { $scene->addConnectionGroup($connectionGroup); + + // Commit changes + $em->flush(); } catch(ArgumentException $e) { $io->error($e->getMessage()); return Command::FAILURE; + } catch (Exception $e) { + $io->error("An unknown error occured: {$e->getMessage()}"); } - $em->flush(); - - $io->success("Group successfully added"); + $io->success("{$connectionGroup} successfully added."); + $logger->info("{$connectionGroup} was added to {$scene}."); return Command::SUCCESS; } diff --git a/src/Console/Command/Scene/SceneConnectCommand.php b/src/Console/Command/Scene/SceneConnectCommand.php index 8631b25..c729751 100644 --- a/src/Console/Command/Scene/SceneConnectCommand.php +++ b/src/Console/Command/Scene/SceneConnectCommand.php @@ -3,14 +3,11 @@ declare(strict_types=1); namespace LotGD\Core\Console\Command\Scene; +use Exception; 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; @@ -75,6 +72,7 @@ class SceneConnectCommand extends BaseCommand protected function execute(InputInterface $input, OutputInterface $output): int { $em = $this->game->getEntityManager(); + $logger = $this->game->getLogger(); $sceneRepository = $em->getRepository(Scene::class); $io = new SymfonyStyle($input, $output); @@ -139,15 +137,19 @@ class SceneConnectCommand extends BaseCommand // Connect the connectables try { $outgoing->connect($incoming, $directionality); + + // Commit changes + $em->flush(); } catch (ArgumentException $e) { $io->error("Scenes were not connected. Reason: {$e}."); return Command::FAILURE; + } catch (Exception $e) { + $io->error("An unknown error occured: {$e->getMessage()}"); + return Command::FAILURE; } - // Commit changes - $em->flush(); - $io->success("The two scenes were successfully connected."); + $logger->info("Connected {$outgoingScene} to {$incomingScene}."); return Command::SUCCESS; } diff --git a/src/Console/Command/Scene/SceneDisconnectCommand.php b/src/Console/Command/Scene/SceneDisconnectCommand.php index 0cc71ce..b573d02 100644 --- a/src/Console/Command/Scene/SceneDisconnectCommand.php +++ b/src/Console/Command/Scene/SceneDisconnectCommand.php @@ -3,19 +3,13 @@ declare(strict_types=1); namespace LotGD\Core\Console\Command\Scene; +use Exception; 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; @@ -54,6 +48,7 @@ class SceneDisconnectCommand extends BaseCommand protected function execute(InputInterface $input, OutputInterface $output): int { $em = $this->game->getEntityManager(); + $logger = $this->game->getLogger(); $sceneRepository = $em->getRepository(Scene::class); $io = new SymfonyStyle($input, $output); @@ -80,11 +75,17 @@ class SceneDisconnectCommand extends BaseCommand return Command::FAILURE; } - // Commit changes - $em->remove($connection); - $em->flush(); + try { + // Commit changes + $em->remove($connection); + $em->flush(); + } catch (Exception $e) { + $io->error("An unknown error occured: {$e->getMessage()}"); + return Command::FAILURE; + } $io->success("The connections between the two given scenes was removed."); + $logger->info("Disconnected {$connection->getOutgoingScene()} and {$connection->getIncomingScene()}."); return Command::SUCCESS; } diff --git a/src/Console/Command/Scene/SceneRemoveCommand.php b/src/Console/Command/Scene/SceneRemoveCommand.php index 88a433c..d309aaf 100644 --- a/src/Console/Command/Scene/SceneRemoveCommand.php +++ b/src/Console/Command/Scene/SceneRemoveCommand.php @@ -4,17 +4,11 @@ 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; @@ -76,7 +70,7 @@ class SceneRemoveCommand extends BaseCommand return Command::FAILURE; } - $io->success("Scene was successfully removed."); + $io->success("{$scene} was successfully removed."); return Command::SUCCESS; } diff --git a/src/Console/Command/Scene/SceneRemoveConnectionGroupCommand.php b/src/Console/Command/Scene/SceneRemoveConnectionGroupCommand.php index 062abed..46c9333 100644 --- a/src/Console/Command/Scene/SceneRemoveConnectionGroupCommand.php +++ b/src/Console/Command/Scene/SceneRemoveConnectionGroupCommand.php @@ -40,6 +40,7 @@ class SceneRemoveConnectionGroupCommand extends BaseCommand protected function execute(InputInterface $input, OutputInterface $output): int { $em = $this->game->getEntityManager(); + $logger = $this->game->getLogger(); $io = new SymfonyStyle($input, $output); @@ -80,9 +81,15 @@ class SceneRemoveConnectionGroupCommand extends BaseCommand } } - $em->flush(); + try { + $em->flush(); + } catch (\Exception $e) { + $io->error("An unknown error occured: {$e->getMessage()}"); + return Command::FAILURE; + } - $io->success("Group successfully added"); + $io->success("{$connectionGroup} was successfully removed"); + $logger->info("Removed {$connectionGroup} from {$scene}."); return Command::SUCCESS; } diff --git a/src/Console/Command/Scene/SceneShowCommand.php b/src/Console/Command/Scene/SceneShowCommand.php index e822fcd..9c4b22c 100644 --- a/src/Console/Command/Scene/SceneShowCommand.php +++ b/src/Console/Command/Scene/SceneShowCommand.php @@ -4,7 +4,6 @@ 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; @@ -13,7 +12,6 @@ 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; @@ -117,6 +115,7 @@ class SceneShowCommand extends BaseCommand } } } + $io->listing($list); return Command::SUCCESS; diff --git a/src/Console/Command/SceneTemplates/SceneTemplateListCommand.php b/src/Console/Command/SceneTemplates/SceneTemplateListCommand.php index 626c117..f5f236f 100644 --- a/src/Console/Command/SceneTemplates/SceneTemplateListCommand.php +++ b/src/Console/Command/SceneTemplates/SceneTemplateListCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace LotGD\Core\Console\Command\SceneTemplates; use LotGD\Core\Console\Command\BaseCommand; -use LotGD\Core\Models\Scene; use LotGD\Core\Models\SceneTemplate; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; diff --git a/src/Models/Character.php b/src/Models/Character.php index 21bf968..fa782a6 100644 --- a/src/Models/Character.php +++ b/src/Models/Character.php @@ -106,6 +106,14 @@ class Character implements CharacterInterface, CreateableInterface, GameAwareInt $this->messageThreads = new ArrayCollection(); } + /** + * @return string + */ + public function __toString(): string + { + return "id} '$this->name', Lvl. {$this->level}>"; + } + /** * Returns the entity's id. * @return int The id diff --git a/src/Models/Scene.php b/src/Models/Scene.php index 06ea72c..bfec901 100644 --- a/src/Models/Scene.php +++ b/src/Models/Scene.php @@ -91,6 +91,11 @@ class Scene implements CreateableInterface, SceneConnectable $this->incomingConnections = new ArrayCollection(); } + public function __toString(): string + { + return "id} '{$this->title}'>"; + } + /** * @return bool */ diff --git a/src/Models/SceneConnectionGroup.php b/src/Models/SceneConnectionGroup.php index d014112..3bc3218 100644 --- a/src/Models/SceneConnectionGroup.php +++ b/src/Models/SceneConnectionGroup.php @@ -47,6 +47,11 @@ class SceneConnectionGroup implements SceneConnectable $this->title = $title; } + public function __toString(): string + { + return "name} '{$this->title}>"; + } + /** * Returns the scene associated with this connection group. * @return Scene