Adds logs to scene commands.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -106,6 +106,14 @@ class Character implements CharacterInterface, CreateableInterface, GameAwareInt
|
||||
$this->messageThreads = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return "<Character#{$this->id} '$this->name', Lvl. {$this->level}>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity's id.
|
||||
* @return int The id
|
||||
|
||||
@@ -91,6 +91,11 @@ class Scene implements CreateableInterface, SceneConnectable
|
||||
$this->incomingConnections = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return "<Scene#{$this->id} '{$this->title}'>";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
@@ -47,6 +47,11 @@ class SceneConnectionGroup implements SceneConnectable
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return "<SceneConnectionGroup#{$this->name} '{$this->title}>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the scene associated with this connection group.
|
||||
* @return Scene
|
||||
|
||||
Reference in New Issue
Block a user