29 Commits

Author SHA1 Message Date
Basilius Sauter 4ca81a3789 Fixed some class documentation. 2019-04-05 13:19:33 +02:00
Basilius Sauter 353c4251c4 Allows the modulemanager to return null instead of the ModuleModel 2019-04-03 17:25:21 +02:00
Basilius Sauter 248258a8fe Adds character stats and tests. 2019-04-03 16:17:36 +02:00
Basilius Sauter 4d1ab9e763 Changed quote strategy to BasicQuoteStrategy as AnsiQuoteStrategy seems to mess up the column names. 2019-04-02 21:12:02 +02:00
Basilius Sauter d7229858cc Adds command to list all characters, and to reset a given characters viewpoint. 2019-04-01 16:50:18 +02:00
Basilius Sauter 14b1db8b82 Changes command module:register to resolve dependencies first. 2019-04-01 16:50:14 +02:00
Basilius Sauter d7100deb0f Merge branch 'master' of https://github.com/lotgd/core into feature/symfony4 2019-03-22 16:26:53 +01:00
Basilius Sauter e260a1d661 Added missing doc block 2019-03-22 16:23:50 +01:00
Basilius Sauter 2ff8d647e8 Changed a small bug causing actions to not have any titles. 2019-03-22 16:23:50 +01:00
Basilius Sauter 8d9a186b46 Small changed to documentation. 2019-03-22 16:23:50 +01:00
Basilius Sauter 8f69527764 Character model: added default parameters for name and displayName. 2019-03-22 16:23:50 +01:00
Basilius Sauter 684f86aed6 Added missing use statements in character model for doctrine annotations. 2019-03-22 16:23:50 +01:00
Basilius Sauter 55481c30b1 Adds schema-update daenerys command. 2019-03-22 16:23:50 +01:00
Basilius Sauter 6b383be1cd Added config to disable automatic database schema update. 2019-03-22 16:23:50 +01:00
Basilius Sauter d609f981aa Changed doctrine dependency 2019-03-22 16:23:50 +01:00
Basilius Sauter 4ec84dfec3 Changed dependency to symfony 4 2019-03-22 16:23:50 +01:00
Basilius Sauter 049d116028 Updated version identifier for 0.5 2018-10-10 10:12:59 +02:00
Basilius Sauter aa63259992 Updated version identifier for 0.5 2018-10-10 10:10:38 +02:00
Basilius Sauter a097c29d67 Added tests to ensure ModuleManager::register does not change anything upon error. 2018-10-08 17:29:44 +02:00
Basilius Sauter bab3e0f236 Changed viewpoint to use uuid-based primary key 2018-10-08 17:29:44 +02:00
Basilius Sauter 2f89bbc7e3 Changed buff to use uuid. 2018-10-08 17:29:44 +02:00
Basilius Sauter 6e2ba248c4 Small changes. 2018-10-08 17:29:44 +02:00
Basilius Sauter b398ffae14 Changed motd id to uuid 2018-10-08 17:29:44 +02:00
Basilius Sauter 90971d152a Changed motd id to uuid 2018-10-08 17:29:44 +02:00
Basilius Sauter 04b3b6aaf9 Changed character id to uuid 2018-10-08 17:29:44 +02:00
Vassyli 0aaba1b94b Fixes inheritance issue with CharacterRepository 2018-10-08 17:28:16 +02:00
Vassyli 2affd4803f Added missing DocBlocks 2018-10-08 17:26:44 +02:00
Vassyli c07f7b3342 Removed auto-flushing for every event from EventManager. 2018-10-08 17:26:44 +02:00
Vassyli 8a75e81431 Updated failing tests 2018-10-08 17:26:44 +02:00
58 changed files with 2231 additions and 610 deletions
+6 -5
View File
@@ -2,7 +2,7 @@
"name": "lotgd/core", "name": "lotgd/core",
"description": "Core functionality for Legend of the Green Dragon, a text-based RPG game.", "description": "Core functionality for Legend of the Green Dragon, a text-based RPG game.",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"version": "0.4.0", "version": "0.5.0",
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"LotGD\\Core\\": "src/", "LotGD\\Core\\": "src/",
@@ -16,11 +16,12 @@
"php": "^7.1.0", "php": "^7.1.0",
"composer/composer": "*", "composer/composer": "*",
"gedmo/doctrine-extensions": "*", "gedmo/doctrine-extensions": "*",
"doctrine/orm": "2.5.*", "doctrine/orm": "^2.5",
"monolog/monolog": "^1.12", "monolog/monolog": "^1.12",
"symfony/console": "^3.0", "symfony/console": "^3.0|^4.0",
"symfony/yaml": "^3.0", "symfony/yaml": "^3.0|^4.0",
"d11wtq/boris": "^1.0" "d11wtq/boris": "^1.0",
"ramsey/uuid-doctrine": "^1.5"
}, },
"repositories": [ "repositories": [
{ {
Generated
+804 -291
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -3,6 +3,7 @@ database:
name: daenerys name: daenerys
user: root user: root
password: password:
disableAutoSchemaUpdate: false
game: game:
epoch: 2016-07-01 00:00:00.0 -8 epoch: 2016-07-01 00:00:00.0 -8
offsetSeconds: 0 offsetSeconds: 0
+2 -2
View File
@@ -20,7 +20,7 @@ class Action
* @param string|null $title * @param string|null $title
* @param array $parameters * @param array $parameters
*/ */
public function __construct(int $destinationSceneId, ?string $title = null, array $parameters = []) public function __construct(string $destinationSceneId, ?string $title = null, array $parameters = [])
{ {
$this->id = bin2hex(random_bytes(8)); $this->id = bin2hex(random_bytes(8));
$this->destinationSceneId = $destinationSceneId; $this->destinationSceneId = $destinationSceneId;
@@ -43,7 +43,7 @@ class Action
* go if they take this action. * go if they take this action.
* @return int * @return int
*/ */
public function getDestinationSceneId(): int public function getDestinationSceneId(): string
{ {
return $this->destinationSceneId; return $this->destinationSceneId;
} }
+2 -2
View File
@@ -70,7 +70,7 @@ class ActionGroup implements \Countable
/** /**
* Returns the ordered array of actions. * Returns the ordered array of actions.
* @return array<Action> * @return Action[]
*/ */
public function getActions(): array public function getActions(): array
{ {
@@ -79,7 +79,7 @@ class ActionGroup implements \Countable
/** /**
* Sets the ordered array of actions. * Sets the ordered array of actions.
* @param array<Action> $actions * @param Action[] $actions
*/ */
public function setActions(array $actions) public function setActions(array $actions)
{ {
+13 -8
View File
@@ -6,6 +6,7 @@ namespace LotGD\Core;
use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\EventManager as DoctrineEventManager; use Doctrine\Common\EventManager as DoctrineEventManager;
use Doctrine\Common\Util\Debug; use Doctrine\Common\Util\Debug;
use Doctrine\DBAL\DBALException;
use Doctrine\ORM\Events as DoctrineEvents; use Doctrine\ORM\Events as DoctrineEvents;
use Doctrine\ORM\ { use Doctrine\ORM\ {
EntityManager, EntityManager,
@@ -65,7 +66,7 @@ class Bootstrap
list($dsn, $user, $password) = $config->getDatabaseConnectionDetails($cwd); list($dsn, $user, $password) = $config->getDatabaseConnectionDetails($cwd);
$pdo = $this->connectToDatabase($dsn, $user, $password); $pdo = $this->connectToDatabase($dsn, $user, $password);
$entityManager = $this->createEntityManager($pdo); $entityManager = $this->createEntityManager($pdo, $config);
$this->game = (new GameBuilder()) $this->game = (new GameBuilder())
->withConfiguration($config) ->withConfiguration($config)
@@ -158,7 +159,7 @@ class Bootstrap
* @param \PDO $pdo * @param \PDO $pdo
* @return EntityManagerInterface * @return EntityManagerInterface
*/ */
protected function createEntityManager(\PDO $pdo): EntityManagerInterface protected function createEntityManager(\PDO $pdo, Configuration $config): EntityManagerInterface
{ {
$this->annotationDirectories = $this->generateAnnotationDirectories(); $this->annotationDirectories = $this->generateAnnotationDirectories();
$this->logger->addDebug("Adding annotation directories:"); $this->logger->addDebug("Adding annotation directories:");
@@ -167,16 +168,20 @@ class Bootstrap
} }
$configuration = Setup::createAnnotationMetadataConfiguration($this->annotationDirectories, true); $configuration = Setup::createAnnotationMetadataConfiguration($this->annotationDirectories, true);
// Set a quote
$configuration->setQuoteStrategy(new AnsiQuoteStrategy());
// Create entity manager // Create entity manager
$entityManager = EntityManager::create(["pdo" => $pdo], $configuration); $entityManager = EntityManager::create(["pdo" => $pdo], $configuration);
// Register uuid type
try {
\Doctrine\DBAL\Types\Type::addType('uuid', 'Ramsey\Uuid\Doctrine\UuidType');
} catch (DBALException $e) {}
// Create Schema and update database if needed // Create Schema and update database if needed
$metaData = $entityManager->getMetadataFactory()->getAllMetadata(); if ($config->getDatabaseAutoSchemaUpdate()) {
$schemaTool = new SchemaTool($entityManager); $metaData = $entityManager->getMetadataFactory()->getAllMetadata();
$schemaTool->updateSchema($metaData); $schemaTool = new SchemaTool($entityManager);
$schemaTool->updateSchema($metaData);
}
return $entityManager; return $entityManager;
} }
+3 -6
View File
@@ -4,10 +4,7 @@ declare(strict_types=1);
namespace LotGD\Core; namespace LotGD\Core;
use Composer\{ use Composer\{
Composer, Composer, Factory, IO\NullIO, Package\CompletePackageInterface, Package\PackageInterface
Factory,
IO\NullIO,
Package\CompletePackageInterface
}; };
use Monolog\Logger; use Monolog\Logger;
@@ -73,7 +70,7 @@ class ComposerManager
/** /**
* Return all the packages installed in the current setup. * Return all the packages installed in the current setup.
* @return array<Composer\PackageInterface> * @return PackageInterface[]
*/ */
public function getPackages(): array public function getPackages(): array
{ {
@@ -85,7 +82,7 @@ class ComposerManager
/** /**
* Return a list of the configured packages which are LotGD modules (type = 'lotgd-module'). * Return a list of the configured packages which are LotGD modules (type = 'lotgd-module').
* @return array Array of \Composer\PackageInterface. * @return PackageInterface[]
*/ */
public function getModulePackages(): array public function getModulePackages(): array
{ {
+16
View File
@@ -20,6 +20,7 @@ class Configuration
private $databaseName; private $databaseName;
private $databaseUser; private $databaseUser;
private $databasePassword; private $databasePassword;
private $databaseAutoSchemaUpdate;
private $logPath; private $logPath;
private $gameEpoch; private $gameEpoch;
private $gameOffsetSeconds; private $gameOffsetSeconds;
@@ -70,6 +71,12 @@ class Configuration
$this->databasePassword = $passwd; $this->databasePassword = $passwd;
$this->databaseName = $name; $this->databaseName = $name;
if (empty($rawConfig['database']['disableAutoSchemaUpdate'])) {
$this->databaseAutoSchemaUpdate = true;
} else {
$this->databaseAutoSchemaUpdate = false;
}
$gameEpoch = $rawConfig['game']['epoch']; $gameEpoch = $rawConfig['game']['epoch'];
$gameOffsetSeconds = $rawConfig['game']['offsetSeconds']; $gameOffsetSeconds = $rawConfig['game']['offsetSeconds'];
$gameDaysPerDay = $rawConfig['game']['daysPerDay']; $gameDaysPerDay = $rawConfig['game']['daysPerDay'];
@@ -157,6 +164,15 @@ class Configuration
return $this->databasePassword; return $this->databasePassword;
} }
/**
* True if doctrine should not auto update.
* @return bool
*/
public function getDatabaseAutoSchemaUpdate(): bool
{
return $this->databaseAutoSchemaUpdate;
}
/** /**
* Return the path to the directory to store log files. * Return the path to the directory to store log files.
* @return string The configured log directory path. * @return string The configured log directory path.
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Console\Command;
use LotGD\Core\Models\Character;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* Command to list all characters.
* @package LotGD\Core\Console\Command
*/
class CharacterListCommand extends BaseCommand
{
/**
* @inheritDoc
*/
protected function configure()
{
$this->setName('character:list')
->setDescription('Lists all characters');
}
/**
* @inheritDoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$characters = $this->game->getEntityManager()->getRepository(Character::class)->findAll();
$table = [["id", "name", "level"], []];
foreach ($characters as $character) {
$table[1][] = [
$character->getId(),
$character->getDisplayName(),
$character->getLevel()
];
}
$io->table(...$table);
}
}
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Console\Command;
use LotGD\Core\Models\Character;
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.
* @package LotGD\Core\Console\Command
*/
class CharacterResetViewpointCommand extends BaseCommand
{
/**
* @inheritDoc
*/
protected function configure()
{
$this->setName('character:resetViewpoint')
->setDescription('Resets the viewpoint of a given character.')
->setDefinition(
new InputDefinition([
new InputOption('id', null, InputOption::VALUE_REQUIRED)
])
);
}
/**
* @inheritDoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$id = $input->getOption("id");
/* @var $character \LotGD\Core\Models\Character */
$character = $this->game->getEntityManager()->getRepository(Character::class)->find($id);
if ($character === null) {
$io->error("Character not found.");
return;
}
$this->game->getEntityManager()->remove($character->getViewpoint());
$character->setViewpoint(null);
$this->game->getEntityManager()->flush();
}
}
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Console\Command;
use Doctrine\ORM\Tools\SchemaTool;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use LotGD\Core\Console\Main;
use LotGD\Core\Game;
/**
* Danerys command to initiate the database with default values.
*/
class DatabaseSchemaUpdateCommand extends BaseCommand
{
/**
* @inheritDoc
*/
protected function configure()
{
$this->setName('database:schemaUpdate')
->setDescription('Updates the database schema manually.');
}
/**
* @inheritDoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$entityManager = $this->game->getEntityManager();
$metaData = $entityManager->getMetadataFactory()->getAllMetadata();
$schemaTool = new SchemaTool($entityManager);
$schemaTool->updateSchema($metaData);
$entityManager->flush();
}
}
+51 -12
View File
@@ -3,12 +3,15 @@ declare(strict_types=1);
namespace LotGD\Core\Console\Command; namespace LotGD\Core\Console\Command;
use Composer\Repository\RepositoryInterface;
use LotGD\Core\ModuleManager;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use LotGD\Core\Exceptions\ClassNotFoundException; use LotGD\Core\Exceptions\ClassNotFoundException;
use LotGD\Core\Exceptions\ModuleAlreadyExistsException; use LotGD\Core\Exceptions\ModuleAlreadyExistsException;
use LotGD\Core\LibraryConfiguration; use LotGD\Core\LibraryConfiguration;
use Symfony\Component\Console\Style\SymfonyStyle;
/** /**
* Danerys command to register and initiate any newly installed modules. * Danerys command to register and initiate any newly installed modules.
@@ -29,21 +32,57 @@ class ModuleRegisterCommand extends BaseCommand
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$io = new SymfonyStyle($input, $output);
$modules = $this->game->getComposerManager()->getModulePackages(); $modules = $this->game->getComposerManager()->getModulePackages();
$registered = [];
foreach ($modules as $p) { foreach ($modules as $p) {
$library = new LibraryConfiguration($this->game->getComposerManager(), $p, $this->game->getCWD()); $this->registerModule($p->getName(), $io, $registered);
$name = $library->getName();
try {
$this->game->getModuleManager()->register($library);
$output->writeln("<info>Registered new module {$name}</info>");
} catch (ModuleAlreadyExistsException $e) {
$output->writeln("Skipping already registered module {$name}");
} catch (ClassNotFoundException $e) {
$output->writeln("<error>Error installing module {$name}: " . $e->getMessage() . "</error>");
}
} }
} }
/**
* Register a given package as a module if it is of type lotdg-module. Resolves dependencies and skips already registered packages.
* @param string $packageName
* @param OutputInterface $output
* @param array $registered
* @throws \LotGD\Core\Exceptions\InvalidConfigurationException
* @throws \LotGD\Core\Exceptions\WrongTypeException
*/
protected function registerModule(
string $packageName,
SymfonyStyle $io,
array &$registered
) {
$composerRepository = $this->game->getComposerManager()->getComposer()
->getRepositoryManager()->getLocalRepository();
$package = $composerRepository->findPackage($packageName, "*");
if ($package->getType() !== "lotgd-module") {
return;
}
if (!empty($registered[$packageName])) {
return;
}
$io->text("Reading module {$packageName} {$package->getPrettyVersion()}");
$library = new LibraryConfiguration($this->game->getComposerManager(), $package, $this->game->getCWD());
$dependencies = $package->getRequires();
foreach ($dependencies as $dependency) {
$this->registerModule($dependency->getTarget(), $io, $registered);
}
try {
$this->game->getModuleManager()->register($library);
$io->success("\tRegistered new module {$packageName}");
} catch (ModuleAlreadyExistsException $e) {
$io->note("\tSkipping already registered module {$packageName}");
} catch (ClassNotFoundException $e) {
$io->error("\tError installing module {$packageName}: {$e->getMessage()}");
}
$registered[$packageName] = true;
}
} }
+6
View File
@@ -8,7 +8,10 @@ use Symfony\Component\Console\Application;
use LotGD\Core\Bootstrap; use LotGD\Core\Bootstrap;
use LotGD\Core\Game; use LotGD\Core\Game;
use LotGD\Core\Console\Command\{ use LotGD\Core\Console\Command\{
CharacterListCommand,
CharacterResetViewpointCommand,
DatabaseInitCommand, DatabaseInitCommand,
DatabaseSchemaUpdateCommand,
ModuleValidateCommand, ModuleValidateCommand,
ModuleRegisterCommand, ModuleRegisterCommand,
ConsoleCommand ConsoleCommand
@@ -42,7 +45,10 @@ class Main
$this->application->add(new ModuleValidateCommand($this->game)); $this->application->add(new ModuleValidateCommand($this->game));
$this->application->add(new ModuleRegisterCommand($this->game)); $this->application->add(new ModuleRegisterCommand($this->game));
$this->application->add(new DatabaseInitCommand($this->game)); $this->application->add(new DatabaseInitCommand($this->game));
$this->application->add(new DatabaseSchemaUpdateCommand($this->game));
$this->application->add(new ConsoleCommand($this->game)); $this->application->add(new ConsoleCommand($this->game));
$this->application->add(new CharacterListCommand($this->game));
$this->application->add(new CharacterResetViewpointCommand($this->game));
// Add additional ones // Add additional ones
$this->bootstrap->addDaenerysCommands($this->application); $this->bootstrap->addDaenerysCommands($this->application);
+2 -3
View File
@@ -10,9 +10,8 @@ interface EventHandler
* Called when an event is published that is handled by this class. * Called when an event is published that is handled by this class.
* *
* @param Game $g The game. * @param Game $g The game.
* @param string $event Name of this event. * @param EventContext $context Arbitrary dictionary representing context around this event.
* @param array $context Arbitrary dictionary representing context around this event. * @return EventContext Return an array if you want to make changes to the $context before
* @return array|null Return an array if you want to make changes to the $context before
* the next handler is called. Otherwise, return null. Any changes made will be propogated * the next handler is called. Otherwise, return null. Any changes made will be propogated
* to the event publisher as well. * to the event publisher as well.
*/ */
+2 -1
View File
@@ -111,7 +111,8 @@ class EventManager
'class' => $class, 'class' => $class,
'library' => $library 'library' => $library
]); ]);
$e->save($this->g->getEntityManager());
$this->g->getEntityManager()->persist($e);
} }
/** /**
+15
View File
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Exceptions;
/**
* Class CharacterStatException
* @package LotGD\Core\Exceptions
*/
class CharacterStatException extends CoreException
{
}
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Exceptions;
/**
* Class CharacterStatExistsException
* @package LotGD\Core\Exceptions
*/
class CharacterStatExistsException extends CharacterStatException
{
}
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Exceptions;
/**
* Class CharacterStatGroupExistsException
* @package LotGD\Core\Exceptions
*/
class CharacterStatGroupExistsException extends CharacterStatException
{
}
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Exceptions;
/**
* Class CharacterStatGroupNotFoundException
* @package LotGD\Core\Exceptions
*/
class CharacterStatGroupNotFoundException extends CharacterStatException
{
}
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Exceptions;
/**
* Class CharacterStatNotFoundException
* @package LotGD\Core\Exceptions
*/
class CharacterStatNotFoundException extends CharacterStatException
{
}
+2 -2
View File
@@ -60,7 +60,7 @@ class Game
*/ */
public static function getVersion(): string public static function getVersion(): string
{ {
return '0.1.0'; return '0.5.0';
} }
/** /**
@@ -310,7 +310,7 @@ class Game
} }
$this->getLogger()->addDebug(" Adding navigation action for child sceneId={$connectedScene->getId()}"); $this->getLogger()->addDebug(" Adding navigation action for child sceneId={$connectedScene->getId()}");
$action = new Action($connectedScene->getId()); $action = new Action($connectedScene->getId(), $connectedScene->getTitle());
if ($connectionGroupName === null) { if ($connectionGroupName === null) {
$actionGroups[ActionGroup::DefaultGroup]->addAction($action); $actionGroups[ActionGroup::DefaultGroup]->addAction($action);
+12 -2
View File
@@ -4,13 +4,15 @@ declare(strict_types=1);
namespace LotGD\Core\Models; namespace LotGD\Core\Models;
use Doctrine\ORM\Mapping\MappedSuperclass; use Doctrine\ORM\Mapping\MappedSuperclass;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/** /**
* @MappedSuperclass * @MappedSuperclass
*/ */
abstract class BasicEnemy implements FighterInterface abstract class BasicEnemy implements FighterInterface
{ {
/** @Id @Column(type="integer") @GeneratedValue */ /** @Id @Column(type="uuid", unique=True) */
protected $id; protected $id;
/** @Column(type="string", length=50); */ /** @Column(type="string", length=50); */
protected $name; protected $name;
@@ -19,11 +21,19 @@ abstract class BasicEnemy implements FighterInterface
/** @var int */ /** @var int */
protected $health; protected $health;
/**
* BasicEnemy constructor. Sets uuid upon creation.
* @throws \Exception
*/
public function __construct() {
$this->id = Uuid::uuid4();
}
/** /**
* Returns the enemy's id * Returns the enemy's id
* @return int * @return int
*/ */
public function getId(): int public function getId(): UuidInterface
{ {
return $this->id; return $this->id;
} }
+10 -6
View File
@@ -7,6 +7,8 @@ use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Table; use Doctrine\ORM\Mapping\Table;
use LotGD\Core\Exceptions\ArgumentException; use LotGD\Core\Exceptions\ArgumentException;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/** /**
* A model representing a buff used to modify the flow of the battle. * A model representing a buff used to modify the flow of the battle.
@@ -23,7 +25,7 @@ class Buff
const ACTIVATE_NONE = 0b0000; const ACTIVATE_NONE = 0b0000;
const ACTIVATE_ANY = 0b1111; const ACTIVATE_ANY = 0b1111;
/** @Id @Column(type="integer") @GeneratedValue */ /** @Id @Column(type="uuid", unique=True) */
private $id; private $id;
/** /**
* @ManyToOne(targetEntity="Character", inversedBy="buffs") * @ManyToOne(targetEntity="Character", inversedBy="buffs")
@@ -231,7 +233,7 @@ class Buff
* Allowed buff values and their type * Allowed buff values and their type
* @var array * @var array
*/ */
private $buffArrayTemplate = [ private static $buffArrayTemplate = [
"slot" => "string", "slot" => "string",
"name" => "string", "name" => "string",
"startMessage" => "string", "startMessage" => "string",
@@ -282,13 +284,15 @@ class Buff
*/ */
public function __construct(array $buffArray) public function __construct(array $buffArray)
{ {
$this->id = Uuid::uuid4();
foreach ($buffArray as $attribute => $value) { foreach ($buffArray as $attribute => $value) {
// Throw exception if an attribute does not exist (to prevent spelling errors) // Throw exception if an attribute does not exist (to prevent spelling errors)
if (!isset($this->buffArrayTemplate[$attribute])) { if (!isset(self::$buffArrayTemplate[$attribute])) {
throw new ArgumentException("{$attribute} is not a valid key for a buff."); throw new ArgumentException("{$attribute} is not a valid key for a buff.");
} }
switch ($this->buffArrayTemplate[$attribute]) { switch (self::$buffArrayTemplate[$attribute]) {
case "string": case "string":
if (is_string($value) === false) { if (is_string($value) === false) {
throw new ArgumentException("{$attribute} needs to be a string."); throw new ArgumentException("{$attribute} needs to be a string.");
@@ -338,7 +342,7 @@ class Buff
{ {
$buffArray = []; $buffArray = [];
foreach ($this->buffArrayTemplate as $attribute => $type) { foreach (self::$buffArrayTemplate as $attribute => $type) {
$buffArray[$attribute] = $buff->$attribute; $buffArray[$attribute] = $buff->$attribute;
} }
@@ -349,7 +353,7 @@ class Buff
* Returns the id of the buff * Returns the id of the buff
* @return int * @return int
*/ */
public function getId(): int public function getId(): UuidInterface
{ {
return $this->id; return $this->id;
} }
+16 -5
View File
@@ -7,7 +7,14 @@ use Doctrine\Common\Collections\{
ArrayCollection, ArrayCollection,
Collection Collection
}; };
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\JoinTable;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\ORM\Mapping\Table; use Doctrine\ORM\Mapping\Table;
use LotGD\Core\{ use LotGD\Core\{
@@ -17,6 +24,8 @@ use LotGD\Core\Exceptions\BuffSlotOccupiedException;
use LotGD\Core\Tools\Model\{ use LotGD\Core\Tools\Model\{
Creator, ExtendableModel, GameAware, PropertyManager, SoftDeletable Creator, ExtendableModel, GameAware, PropertyManager, SoftDeletable
}; };
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/** /**
* Model for a character * Model for a character
@@ -32,12 +41,12 @@ class Character implements CharacterInterface, CreateableInterface, GameAwareInt
use GameAware; use GameAware;
use ExtendableModel; use ExtendableModel;
/** @Id @Column(type="integer") @GeneratedValue */ /** @Id @Column(type="uuid", unique=True) */
private $id; private $id;
/** @Column(type="string", length=50); */ /** @Column(type="string", length=50); */
private $name; private $name = "";
/** @Column(type="text"); */ /** @Column(type="text"); */
private $displayName; private $displayName = "";
/** @Column(type="integer", options={"default":10}) */ /** @Column(type="integer", options={"default":10}) */
private $maxHealth = 10; private $maxHealth = 10;
/** @Column(type="integer", options={"default":10}) */ /** @Column(type="integer", options={"default":10}) */
@@ -90,6 +99,8 @@ class Character implements CharacterInterface, CreateableInterface, GameAwareInt
*/ */
public function __construct() public function __construct()
{ {
$this->id = Uuid::uuid4();
$this->properties = new ArrayCollection(); $this->properties = new ArrayCollection();
$this->buffs = new ArrayCollection(); $this->buffs = new ArrayCollection();
$this->messageThreads = new ArrayCollection(); $this->messageThreads = new ArrayCollection();
@@ -99,7 +110,7 @@ class Character implements CharacterInterface, CreateableInterface, GameAwareInt
* Returns the entity's id * Returns the entity's id
* @return int The id * @return int The id
*/ */
public function getId(): int public function getId(): UuidInterface
{ {
return $this->id; return $this->id;
} }
@@ -287,7 +298,7 @@ class Character implements CharacterInterface, CreateableInterface, GameAwareInt
/** /**
* Sets the current character viewpoint. * Sets the current character viewpoint.
*/ */
public function setViewpoint(Viewpoint $v) public function setViewpoint(?Viewpoint $v)
{ {
$this->viewpoint = $v; $this->viewpoint = $v;
} }
+3 -1
View File
@@ -3,12 +3,14 @@ declare(strict_types=1);
namespace LotGD\Core\Models; namespace LotGD\Core\Models;
use Ramsey\Uuid\UuidInterface;
/** /**
* Interface for the character model and all objects that mimick such a model. * Interface for the character model and all objects that mimick such a model.
*/ */
interface CharacterInterface extends FighterInterface interface CharacterInterface extends FighterInterface
{ {
public function getId(): int; public function getId(): UuidInterface;
public function getName(): string; public function getName(): string;
public function getDisplayName(): string; public function getDisplayName(): string;
public function getHealth(): int; public function getHealth(): int;
+119
View File
@@ -0,0 +1,119 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Models;
use LotGD\Core\Exceptions\CharacterStatExistsException;
use LotGD\Core\Exceptions\CharacterStatNotFoundException;
use LotGD\Core\Models\CharacterStats\CharacterStatInterface;
/**
* Class CharacterStatGroup
* @package LotGD\Core\Models
*/
class CharacterStatGroup
{
private $id;
private $name;
private $stats = [];
private $weight;
private $sorted = true;
/**
* CharacterStatGroup constructor.
* @param string $id
* @param string $name
*/
public function __construct(string $id, string $name, int $weight = 0)
{
$this->id = $id;
$this->name = $name;
$this->weight = $weight;
}
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @return int
*/
public function getWeight(): int
{
return $this->weight;
}
/**
* @param CharacterStatInterface $characterStat
* @throws CharacterStatExistsException
*/
public function addCharacterStat(CharacterStatInterface $characterStat)
{
if (isset($this->stats[$characterStat->getId()])) {
throw new CharacterStatExistsException("There is already a character stat registered to this group with the id {$characterStat->getId()}");
}
$this->stats[$characterStat->getId()] = $characterStat;
$this->sorted = false;
}
/**
* @param string $id
* @return CharacterStatInterface
* @throws CharacterStatNotFoundException
*/
public function getCharacterStat(string $id): CharacterStatInterface
{
if (empty($this->stats[$id])) {
throw new CharacterStatNotFoundException("Character stat with id {$id} not found.");
}
return $this->stats[$id];
}
/**
* @param string $id
* @return bool
*/
public function hasCharacterStat(string $id): bool
{
if (isset($this->stats[$id])) {
return true;
}
return false;
}
/**
* @return \Generator|CharacterStatInterface[]
*/
public function iterate(): \Generator
{
// First, sort stat set by weight if not sorted
if (!$this->sorted) {
uasort($this->stats, function (CharacterStatInterface $a, CharacterStatInterface $b) {
return $a->getWeight() <=> $b->getWeight();
});
$this->sorted = true;
}
// Now, iterate.
foreach ($this->stats as $stat) {
yield $stat;
}
}
}
+100
View File
@@ -0,0 +1,100 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Models;
use LotGD\Core\Events\EventContextData;
use LotGD\Core\Exceptions\CharacterStatGroupExistsException;
use LotGD\Core\Exceptions\CharacterStatGroupNotFoundException;
use LotGD\Core\Game;
/**
* Class CharacterStats
* @package LotGD\Core\Models
*/
class CharacterStats
{
private $game;
private $character;
private $stat_groups;
private $sorted = true;
/**
* CharacterStats constructor.
* @param Game $game
* @param Character $character
*/
public function __construct(Game $game, Character $character)
{
$this->game = $game;
$this->character = $character;
// Hook
$eventData = $this->game->getEventManager()->publish(
"h/lotgd/core/characterStats/populate",
EventContextData::create(["character" => $character, "stats" => $this])
);
}
/**
* @return \Generator|CharacterStatGroup[]
*/
public function iterate(): \Generator
{
// First, sort stat set by weight if not sorted yet
if (!$this->sorted) {
uasort($this->stat_groups, function (CharacterStatGroup $a, CharacterStatGroup $b) {
return $a->getWeight() <=> $b->getWeight();
});
$this->sorted = true;
}
// Now, iterate.
foreach ($this->stat_groups as $id => $stat_group) {
yield $stat_group;
}
}
/**
* @param CharacterStatGroup $group
* @throws CharacterStatGroupExistsException
*/
public function addCharacterStatGroup(CharacterStatGroup $group)
{
if (isset($this->stat_groups[$group->getId()])) {
throw new CharacterStatGroupExistsException("Character stat {$group->getId()} already exists.");
}
$this->stat_groups[$group->getId()] = $group;
$this->sorted = false;
}
/**
* @param string $id
* @return CharacterStatGroup
* @throws CharacterStatGroupNotFoundException
*/
public function getCharacterStatGroup(string $id): CharacterStatGroup
{
if (empty($this->stat_groups[$id])) {
throw new CharacterStatGroupNotFoundException("Character stat {$id} does not exists.");
}
return $this->stat_groups[$id];
}
/**
* @param string $id
* @return bool
*/
public function hasCharacterStatGroup(string $id): bool
{
if (isset($this->stat_groups[$id])) {
return true;
}
return false;
}
}
@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Models\CharacterStats;
/**
* Class BaseCharacterStat
* @package LotGD\Core\Models\CharacterStats
*/
class BaseCharacterStat implements CharacterStatInterface
{
private $id;
private $name;
private $value;
private $weight;
/**
* BaseCharacterStat constructor.
* @param string $id
* @param string $name
* @param $value
*/
public function __construct(string $id, string $name, $value, int $weight = 0)
{
$this->id = $id;
$this->name = $name;
$this->value = $value;
$this->weight = $weight;
}
/** @inheritdoc */
public function getId(): string
{
return $this->id;
}
/** @inheritdoc */
public function getName(): string
{
return $this->name;
}
/** @inheritdoc */
public function setName(string $name)
{
$this->name = $name;
}
/** @inheritdoc */
public function getValue()
{
return $this->value;
}
/** @inheritdoc */
public function setValue($value)
{
$this->value = $value;
}
/** @inheritdoc */
public function getValueAsString(): string
{
return sprintf("%s", $this->getValue());
}
/** @inheritdoc */
public function setWeight(int $weight)
{
$this->weight = $weight;
}
/** @inheritdoc */
public function getWeight(): int
{
return $this->weight;
}
}
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Models\CharacterStats;
interface CharacterStatInterface
{
/**
* CharacterStatInterface constructor.
* @param string $id
* @param string $name
* @param $value
*/
public function __construct(string $id, string $name, $value, int $weight = 0);
/**
* @return string
*/
public function getId(): string;
/**
* @return string
*/
public function getName(): string;
/**
* @param string $name
* @return mixed
*/
public function setName(string $name);
/**
* @return mixed
*/
public function getValue();
/**
* @param $value
* @return mixed
*/
public function setValue($value);
/**
* @return string
*/
public function getValueAsString(): string;
/**
* @return int
*/
public function getWeight(): int;
/**
* @param int $weight
* @return mixed
*/
public function setWeight(int $weight);
}
-3
View File
@@ -39,9 +39,6 @@ class Message
private $systemMessage = false; private $systemMessage = false;
/** /**
* Constructs the message. * Constructs the message.
* Use the Message Manager methods send() and sendSystemMessage() instead. * Use the Message Manager methods send() and sendSystemMessage() instead.
+5 -2
View File
@@ -8,6 +8,8 @@ use Doctrine\ORM\Mapping\Table;
use LotGD\Core\Tools\Model\Creator; use LotGD\Core\Tools\Model\Creator;
use LotGD\Core\Tools\Model\Deletor; use LotGD\Core\Tools\Model\Deletor;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/** /**
* Model for the message of the day * Model for the message of the day
@@ -20,7 +22,7 @@ class MotD implements CreateableInterface
use Creator; use Creator;
use Deletor; use Deletor;
/** @Id @Column(type="integer") @GeneratedValue */ /** @Id @Column(type="uuid", unique=True) */
private $id; private $id;
/** /**
* @ManyToOne(targetEntity="Character", cascade={"persist"}, fetch="EAGER") * @ManyToOne(targetEntity="Character", cascade={"persist"}, fetch="EAGER")
@@ -49,6 +51,7 @@ class MotD implements CreateableInterface
*/ */
public function __construct() public function __construct()
{ {
$this->id = Uuid::uuid4();
$this->creationTime = new \DateTime("now"); $this->creationTime = new \DateTime("now");
} }
@@ -56,7 +59,7 @@ class MotD implements CreateableInterface
* Returns the entities ID * Returns the entities ID
* @return int * @return int
*/ */
public function getId(): int public function getId(): UuidInterface
{ {
return $this->id; return $this->id;
} }
@@ -43,9 +43,9 @@ class CharacterRepository extends EntityRepository
} }
/** /**
* Find a character by ID. * Find a character by ID, excluding soft deleted ones.
*/ */
public function find($id, $lockMode = NULL, $lockVersion = NULL, int $deletes = self::SKIP_SOFTDELETED) public function find($id, $lockMode=null, $lockVersion=null)
{ {
$queryBuilder = $this->getEntityManager()->createQueryBuilder(); $queryBuilder = $this->getEntityManager()->createQueryBuilder();
$queryBuilder->select("c") $queryBuilder->select("c")
@@ -53,7 +53,29 @@ class CharacterRepository extends EntityRepository
->where($queryBuilder->expr()->eq("c.id", ":id")) ->where($queryBuilder->expr()->eq("c.id", ":id"))
->setParameter("id", $id); ->setParameter("id", $id);
$this->modifyQuery($queryBuilder, $deletes); $this->modifyQuery($queryBuilder, self::SKIP_SOFTDELETED);
try {
return $queryBuilder->getQuery()->getSingleResult();
} catch (NoResultException $e) {
return null;
}
}
/**
* Finds a character id ID, including soft deleted ones.
* @param $id
* @return mixed|null
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findWithSoftDeleted($id) {
$queryBuilder = $this->getEntityManager()->createQueryBuilder();
$queryBuilder->select("c")
->from(Character::class, "c")
->where($queryBuilder->expr()->eq("c.id", ":id"))
->setParameter("id", $id);
$this->modifyQuery($queryBuilder, self::INCLUDE_SOFTDELETED);
try { try {
return $queryBuilder->getQuery()->getSingleResult(); return $queryBuilder->getQuery()->getSingleResult();
+7 -3
View File
@@ -12,6 +12,8 @@ use LotGD\Core\Exceptions\ArgumentException;
use LotGD\Core\Tools\Model\Creator; use LotGD\Core\Tools\Model\Creator;
use LotGD\Core\Tools\Model\Deletor; use LotGD\Core\Tools\Model\Deletor;
use LotGD\Core\Tools\Model\SceneBasics; use LotGD\Core\Tools\Model\SceneBasics;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/** /**
* A scene is a location within the game, such as the Village or the Tavern. Designed * A scene is a location within the game, such as the Village or the Tavern. Designed
@@ -26,8 +28,8 @@ class Scene implements CreateableInterface, SceneConnectable
use Deletor; use Deletor;
use SceneBasics; use SceneBasics;
/** @Id @Column(type="integer") @GeneratedValue */ /** @Id @Column(type="string", length=36, unique=True, name="id", options={"fixed" = true}) */
private $id; protected $id;
/** /**
* @OneToMany(targetEntity="SceneConnectionGroup", mappedBy="scene", cascade={"persist", "remove"}) * @OneToMany(targetEntity="SceneConnectionGroup", mappedBy="scene", cascade={"persist", "remove"})
@@ -61,6 +63,8 @@ class Scene implements CreateableInterface, SceneConnectable
*/ */
public function __construct() public function __construct()
{ {
$this->id = Uuid::uuid4()->toString();
$this->connectionGroups = new ArrayCollection(); $this->connectionGroups = new ArrayCollection();
$this->outgoingConnections = new ArrayCollection(); $this->outgoingConnections = new ArrayCollection();
$this->incomingConnections = new ArrayCollection(); $this->incomingConnections = new ArrayCollection();
@@ -70,7 +74,7 @@ class Scene implements CreateableInterface, SceneConnectable
* Returns the primary ID for this scene. * Returns the primary ID for this scene.
* @return int * @return int
*/ */
public function getId(): int public function getId(): string
{ {
return $this->id; return $this->id;
} }
+2 -2
View File
@@ -15,14 +15,14 @@ class SceneConnection
{ {
/** /**
* @Id * @Id
* @ManyToOne(targetEntity="Scene") * @ManyToOne(targetEntity="Scene", inversedBy="outgoingConnections")
* @JoinColumn(name="outgoingScene", referencedColumnName="id") * @JoinColumn(name="outgoingScene", referencedColumnName="id")
*/ */
private $outgoingScene; private $outgoingScene;
/** /**
* @Id * @Id
* @ManyToOne(targetEntity="Scene") * @ManyToOne(targetEntity="Scene", inversedBy="incomingConnections")
* @JoinColumn(name="incomingScene", referencedColumnName="id") * @JoinColumn(name="incomingScene", referencedColumnName="id")
*/ */
private $incomingScene; private $incomingScene;
+17 -5
View File
@@ -3,7 +3,12 @@ declare(strict_types=1);
namespace LotGD\Core\Models; namespace LotGD\Core\Models;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\ORM\Mapping\Table; use Doctrine\ORM\Mapping\Table;
use LotGD\Core\Action; use LotGD\Core\Action;
@@ -24,7 +29,11 @@ class Viewpoint implements CreateableInterface
use Creator; use Creator;
use SceneBasics; use SceneBasics;
/** @Id @OneToOne(targetEntity="Character", inversedBy="viewpoint", cascade="persist") */ /**
* @Id
* @OneToOne(targetEntity="Character", inversedBy="viewpoint", cascade="persist")
* @JoinColumn(fieldName="owner_id", referencedColumnName="id")
*/
private $owner; private $owner;
/** @Column(type="array") */ /** @Column(type="array") */
private $actionGroups = []; private $actionGroups = [];
@@ -32,7 +41,10 @@ class Viewpoint implements CreateableInterface
private $attachments = []; private $attachments = [];
/** @Column(type="array") */ /** @Column(type="array") */
private $data = []; private $data = [];
/** @ManyToOne(targetEntity="Scene") */ /**
* @ManyToOne(targetEntity="Scene")
* @JoinColumn(name="scene_id", referencedColumnName="id")
*/
private $scene; private $scene;
/** @var SceneDescription */ /** @var SceneDescription */
@@ -171,7 +183,7 @@ class Viewpoint implements CreateableInterface
/** /**
* Returns all action groups. * Returns all action groups.
* @return array * @return ActionGroup[]
*/ */
public function getActionGroups(): array public function getActionGroups(): array
{ {
@@ -180,7 +192,7 @@ class Viewpoint implements CreateableInterface
/** /**
* Sets action groups. * Sets action groups.
* @param array $actionGroups * @param ActionGroup[] $actionGroups
*/ */
public function setActionGroups(array $actionGroups) public function setActionGroups(array $actionGroups)
{ {
@@ -329,7 +341,7 @@ class Viewpoint implements CreateableInterface
* Removes any actions that correspond to a given scene ID, if present. * Removes any actions that correspond to a given scene ID, if present.
* @param int $id * @param int $id
*/ */
public function removeActionsWithSceneId(int $id) public function removeActionsWithSceneId(string $id)
{ {
foreach ($this->getActionGroups() as $group) { foreach ($this->getActionGroups() as $group) {
$actions = $group->getActions(); $actions = $group->getActions();
+25 -5
View File
@@ -42,6 +42,7 @@ class ModuleManager
{ {
$name = $library->getName(); $name = $library->getName();
$package = $library->getComposerPackage(); $package = $library->getComposerPackage();
$em = $this->g->getEntityManager();
$this->g->getLogger()->debug("Registering module {$name}..."); $this->g->getLogger()->debug("Registering module {$name}...");
@@ -53,6 +54,8 @@ class ModuleManager
$this->g->getLogger()->debug("Creating module model for {$name}"); $this->g->getLogger()->debug("Creating module model for {$name}");
$m = new ModuleModel($name); $m = new ModuleModel($name);
$em->beginTransaction();
$class = $library->getRootNamespace() . 'Module'; $class = $library->getRootNamespace() . 'Module';
try { try {
$klass = new \ReflectionClass($class); $klass = new \ReflectionClass($class);
@@ -69,9 +72,16 @@ class ModuleManager
} }
// Subscribe to the module's events. // Subscribe to the module's events.
$subscriptions = $library->getSubscriptionPatterns(); try {
foreach ($subscriptions as $s) { $subscriptions = $library->getSubscriptionPatterns();
$this->g->getEventManager()->subscribe($s, $class, $name); foreach ($subscriptions as $s) {
$this->g->getEventManager()->subscribe($s, $class, $name);
}
} catch (\Throwable $e) {
$em->rollBack();
$em->clear();
throw $e;
} }
// Run the module's onRegister handler. // Run the module's onRegister handler.
@@ -79,10 +89,20 @@ class ModuleManager
try { try {
$class::onRegister($this->g, $m); $class::onRegister($this->g, $m);
$m->save($this->g->getEntityManager()); $this->g->getEntityManager()->persist($m);
$this->g->getEntityManager()->flush();
$em->commit();
return;
} catch (Throwable $e) { } catch (Throwable $e) {
$em->rollBack();
$em->clear();
$this->g->getLogger()->error("Calling {$class}::onRegister failed with exception: {$e->getMessage()}"); $this->g->getLogger()->error("Calling {$class}::onRegister failed with exception: {$e->getMessage()}");
unset($m); unset($m);
// Propagate the exception.
throw $e;
} }
} }
} }
@@ -142,7 +162,7 @@ class ModuleManager
* @param string $library * @param string $library
* @return Module * @return Module
*/ */
public function getModule(string $library): ModuleModel public function getModule(string $library): ?ModuleModel
{ {
return $this->g->getEntityManager()->getRepository(ModuleModel::class)->find($library); return $this->g->getEntityManager()->getRepository(ModuleModel::class)->find($library);
} }
+2 -1
View File
@@ -10,6 +10,7 @@ use LotGD\Core\{
}; };
use LotGD\Core\Exceptions\IsNullException; use LotGD\Core\Exceptions\IsNullException;
use LotGD\Core\Models\Viewpoint; use LotGD\Core\Models\Viewpoint;
use Ramsey\Uuid\UuidInterface;
/** /**
* Provides basic implementation to mock CharacterInterface. * Provides basic implementation to mock CharacterInterface.
@@ -21,7 +22,7 @@ trait MockCharacter
throw new IsNullException(); throw new IsNullException();
} }
public function getId(): int public function getId(): UuidInterface
{ {
throw new IsNullException(); throw new IsNullException();
} }
+34 -30
View File
@@ -5,6 +5,7 @@ namespace LotGD\Core\Tests\Models;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Util\Debug;
use LotGD\Core\{ use LotGD\Core\{
Battle, Battle,
DiceBag, DiceBag,
@@ -25,6 +26,9 @@ use LotGD\Core\Models\BattleEvents\{
}; };
use LotGD\Core\Tests\CoreModelTestCase; use LotGD\Core\Tests\CoreModelTestCase;
use Ramsey\Uuid\Codec\OrderedTimeCodec;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidFactory;
class BattleTest extends CoreModelTestCase class BattleTest extends CoreModelTestCase
{ {
@@ -52,8 +56,8 @@ class BattleTest extends CoreModelTestCase
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$character = $em->getRepository(Character::class)->find(1); $character = $em->getRepository(Character::class)->find("d363c077-234a-433d-834e-f1a1d3b281d8");
$monster = $em->getRepository(Monster::class)->find(1); $monster = $em->getRepository(Monster::class)->find("de84c507-9673-44e7-b665-9e43416b9c2f");
$this->assertSame(5, $monster->getLevel()); $this->assertSame(5, $monster->getLevel());
$this->assertSame(52, $monster->getMaxHealth()); $this->assertSame(52, $monster->getMaxHealth());
@@ -69,8 +73,8 @@ class BattleTest extends CoreModelTestCase
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$character = $em->getRepository(Character::class)->find(1); $character = $em->getRepository(Character::class)->find("d363c077-234a-433d-834e-f1a1d3b281d8");
$monster = $em->getRepository(Monster::class)->find(1); $monster = $em->getRepository(Monster::class)->find("de84c507-9673-44e7-b665-9e43416b9c2f");
$battle = new Battle($this->getMockGame($character), $character, $monster); $battle = new Battle($this->getMockGame($character), $character, $monster);
@@ -106,8 +110,8 @@ class BattleTest extends CoreModelTestCase
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$character = $em->getRepository(Character::class)->find(1); $character = $em->getRepository(Character::class)->find("d363c077-234a-433d-834e-f1a1d3b281d8");
$monster = $em->getRepository(Monster::class)->find(1); $monster = $em->getRepository(Monster::class)->find("de84c507-9673-44e7-b665-9e43416b9c2f");
$battle = new Battle($this->getMockGame($character), $character, $monster); $battle = new Battle($this->getMockGame($character), $character, $monster);
$battle = $battle->serialize(); $battle = $battle->serialize();
@@ -139,8 +143,8 @@ class BattleTest extends CoreModelTestCase
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$highLevelPlayer = $em->getRepository(Character::class)->find(2); $highLevelPlayer = $em->getRepository(Character::class)->find("4d01c29b-d825-4bc7-9e6e-63525155fd37");
$lowLevelMonster = $em->getRepository(Monster::class)->find(3); $lowLevelMonster = $em->getRepository(Monster::class)->find("c004bcb6-a7c1-4f9a-abc2-1711c64e23a0");
$battle = new Battle($this->getMockGame($highLevelPlayer), $highLevelPlayer, $lowLevelMonster); $battle = new Battle($this->getMockGame($highLevelPlayer), $highLevelPlayer, $lowLevelMonster);
@@ -172,8 +176,8 @@ class BattleTest extends CoreModelTestCase
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$lowLevelPlayer = $em->getRepository(Character::class)->find(3); $lowLevelPlayer = $em->getRepository(Character::class)->find("c3792b61-4e34-4710-9871-65a68ac30bb4");
$highLevelMonster = $em->getRepository(Monster::class)->find(2); $highLevelMonster = $em->getRepository(Monster::class)->find("b636df29-f72d-4e2d-9850-982e783a9e94");
$battle = new Battle($this->getMockGame($lowLevelPlayer), $lowLevelPlayer, $highLevelMonster); $battle = new Battle($this->getMockGame($lowLevelPlayer), $lowLevelPlayer, $highLevelMonster);
@@ -205,8 +209,8 @@ class BattleTest extends CoreModelTestCase
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$character = $em->getRepository(Character::class)->find(1); $character = $em->getRepository(Character::class)->find("d363c077-234a-433d-834e-f1a1d3b281d8");
$monster = $em->getRepository(Monster::class)->find(1); $monster = $em->getRepository(Monster::class)->find("de84c507-9673-44e7-b665-9e43416b9c2f");
$battle = new Battle($this->getMockGame($character), $character, $monster); $battle = new Battle($this->getMockGame($character), $character, $monster);
@@ -220,8 +224,8 @@ class BattleTest extends CoreModelTestCase
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$character = $em->getRepository(Character::class)->find(1); $character = $em->getRepository(Character::class)->find("d363c077-234a-433d-834e-f1a1d3b281d8");
$monster = $em->getRepository(Monster::class)->find(1); $monster = $em->getRepository(Monster::class)->find("de84c507-9673-44e7-b665-9e43416b9c2f");
$battle = new Battle($this->getMockGame($character), $character, $monster); $battle = new Battle($this->getMockGame($character), $character, $monster);
@@ -236,8 +240,8 @@ class BattleTest extends CoreModelTestCase
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$character = $em->getRepository(Character::class)->find(1); $character = $em->getRepository(Character::class)->find("d363c077-234a-433d-834e-f1a1d3b281d8");
$monster = $em->getRepository(Monster::class)->find(1); $monster = $em->getRepository(Monster::class)->find("de84c507-9673-44e7-b665-9e43416b9c2f");
$battle = new Battle($this->getMockGame($character), $character, $monster); $battle = new Battle($this->getMockGame($character), $character, $monster);
@@ -257,23 +261,23 @@ class BattleTest extends CoreModelTestCase
default: default:
case 0: case 0:
// Fair Battle // Fair Battle
$character = $em->getRepository(Character::class)->find(1); $character = $em->getRepository(Character::class)->find("d363c077-234a-433d-834e-f1a1d3b281d8");
$monster = $em->getRepository(Monster::class)->find(1); $monster = $em->getRepository(Monster::class)->find("de84c507-9673-44e7-b665-9e43416b9c2f");
break; break;
case 1: case 1:
// very long battle // very long battle
$character = $em->getRepository(Character::class)->find(4); $character = $em->getRepository(Character::class)->find("6565b418-55f5-4a6b-8d92-a9ef81329912");
$monster = $em->getRepository(Monster::class)->find(3); $monster = $em->getRepository(Monster::class)->find("c004bcb6-a7c1-4f9a-abc2-1711c64e23a0");
break; break;
case 2: case 2:
// player should win battle // player should win battle
$character = $em->getRepository(Character::class)->find(13); $character = $em->getRepository(Character::class)->find("1a9f63f2-3006-4e12-b272-4fd6be518a93");
$monster = $em->getRepository(Monster::class)->find(11); $monster = $em->getRepository(Monster::class)->find("7ca9c141-aaf8-44a5-9d04-b6f9923f3c66");
break; break;
case 3: case 3:
// player should lose battle // player should lose battle
$character = $em->getRepository(Character::class)->find(11); $character = $em->getRepository(Character::class)->find("24d71c26-f915-401c-8b3e-1932edf650ce");
$monster = $em->getRepository(Monster::class)->find(13); $monster = $em->getRepository(Monster::class)->find("09540b93-63c9-4d82-8501-f569f63dfc4c");
break; break;
} }
@@ -1331,7 +1335,7 @@ class BattleTest extends CoreModelTestCase
public function testBufflistGoodguyAttackModifier() public function testBufflistGoodguyAttackModifier()
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$player = $em->getRepository(Character::class)->find(1); $player = $em->getRepository(Character::class)->find("d363c077-234a-433d-834e-f1a1d3b281d8");
$game = $this->getMockGame($player); $game = $this->getMockGame($player);
$player->addBuff(new Buff([ $player->addBuff(new Buff([
@@ -1360,7 +1364,7 @@ class BattleTest extends CoreModelTestCase
public function testBufflistGoodguyDefenseModifier() public function testBufflistGoodguyDefenseModifier()
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$player = $em->getRepository(Character::class)->find(1); $player = $em->getRepository(Character::class)->find("d363c077-234a-433d-834e-f1a1d3b281d8");
$game = $this->getMockGame($player); $game = $this->getMockGame($player);
$player->addBuff(new Buff([ $player->addBuff(new Buff([
@@ -1389,7 +1393,7 @@ class BattleTest extends CoreModelTestCase
public function testBufflistGoodguyDamageModifier() public function testBufflistGoodguyDamageModifier()
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$player = $em->getRepository(Character::class)->find(1); $player = $em->getRepository(Character::class)->find("d363c077-234a-433d-834e-f1a1d3b281d8");
$game = $this->getMockGame($player); $game = $this->getMockGame($player);
$player->addBuff(new Buff([ $player->addBuff(new Buff([
@@ -1418,7 +1422,7 @@ class BattleTest extends CoreModelTestCase
public function testBufflistBadguyAttackModifier() public function testBufflistBadguyAttackModifier()
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$player = $em->getRepository(Character::class)->find(1); $player = $em->getRepository(Character::class)->find("d363c077-234a-433d-834e-f1a1d3b281d8");
$game = $this->getMockGame($player); $game = $this->getMockGame($player);
$player->addBuff(new Buff([ $player->addBuff(new Buff([
@@ -1447,7 +1451,7 @@ class BattleTest extends CoreModelTestCase
public function testBufflistBadguyDefenseModifier() public function testBufflistBadguyDefenseModifier()
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$player = $em->getRepository(Character::class)->find(1); $player = $em->getRepository(Character::class)->find("d363c077-234a-433d-834e-f1a1d3b281d8");
$game = $this->getMockGame($player); $game = $this->getMockGame($player);
$player->addBuff(new Buff([ $player->addBuff(new Buff([
@@ -1476,7 +1480,7 @@ class BattleTest extends CoreModelTestCase
public function testBufflistBadguyDamageModifier() public function testBufflistBadguyDamageModifier()
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$player = $em->getRepository(Character::class)->find(1); $player = $em->getRepository(Character::class)->find("d363c077-234a-433d-834e-f1a1d3b281d8");
$game = $this->getMockGame($player); $game = $this->getMockGame($player);
$player->addBuff(new Buff([ $player->addBuff(new Buff([
+4
View File
@@ -5,6 +5,7 @@ namespace LotGD\Core\Tests\DefectiveModule;
use LotGD\Core\Exceptions\CoreException; use LotGD\Core\Exceptions\CoreException;
use LotGD\Core\Game; use LotGD\Core\Game;
use LotGD\Core\Events\EventContext; use LotGD\Core\Events\EventContext;
use LotGD\Core\Models\Character;
use LotGD\Core\Module as ModuleInterface; use LotGD\Core\Module as ModuleInterface;
use LotGD\Core\Models\Module as ModuleModel; use LotGD\Core\Models\Module as ModuleModel;
@@ -18,6 +19,9 @@ class Module implements ModuleInterface {
public static function onRegister(Game $g, ModuleModel $module) public static function onRegister(Game $g, ModuleModel $module)
{ {
$character = Character::create(["name" => "Test"]);
$character->save($g->getEntityManager());
throw new DefectiveModuleException("Exception"); throw new DefectiveModuleException("Exception");
} }
+2 -1
View File
@@ -1,3 +1,4 @@
entityNamespace: "LotGD\\Core\\Tests\\FakeModule\\Models\\" entityNamespace: "LotGD\\Core\\Tests\\FakeModule\\Models\\"
subscriptionPatterns: subscriptionPatterns:
- "e/lotgd/core/tests/event" - "e/lotgd/core/tests/defective-event"
- "e/lotgd/core/tests/gom-event"
+1
View File
@@ -96,6 +96,7 @@ class EventManagerTest extends CoreModelTestCase
$library = 'lotgd/tests'; $library = 'lotgd/tests';
$em->subscribe($pattern, $class, $library); $em->subscribe($pattern, $class, $library);
$this->getEntityManager()->flush();
$sub = EventSubscription::create([ $sub = EventSubscription::create([
'pattern' => $pattern, 'pattern' => $pattern,
+26 -19
View File
@@ -37,15 +37,16 @@ class DefaultSceneProvider implements EventHandler
)); ));
} }
$context->setDataField("scene", $g->getEntityManager()->getRepository(Scene::class)->find(1)); $context->setDataField("scene", $g->getEntityManager()->getRepository(Scene::class)
->find("30000000-0000-0000-0000-000000000001"));
break; break;
case 'h/lotgd/core/navigate-to/lotgd/tests/village': case 'h/lotgd/core/navigate-to/lotgd/tests/village':
$v = $context->getDataField('viewpoint'); $v = $context->getDataField('viewpoint');
self::$actionGroups = [new ActionGroup('default', 'Title', 0)]; self::$actionGroups = [new ActionGroup('default', 'Title', 0)];
self::$actionGroups[0]->setActions([ self::$actionGroups[0]->setActions([
new Action(2), // This is a real sceneId in game.yml new Action("30000000-0000-0000-0000-000000000002"), // This is a real sceneId in game.yml
new Action(101), new Action("30000000-0000-0000-0000-000000000101"),
]); ]);
$v->setActionGroups(self::$actionGroups); $v->setActionGroups(self::$actionGroups);
@@ -128,7 +129,7 @@ class GameTest extends CoreModelTestCase
public function testSetGetCharacter() public function testSetGetCharacter()
{ {
$c = $this->getEntityManager()->getRepository(Character::class)->find(1); $c = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$this->g->setCharacter($c); $this->g->setCharacter($c);
$this->assertEquals($c, $this->g->getCharacter()); $this->assertEquals($c, $this->g->getCharacter());
@@ -136,7 +137,7 @@ class GameTest extends CoreModelTestCase
public function testGetViewpointException() public function testGetViewpointException()
{ {
$c = $this->getEntityManager()->getRepository(Character::class)->find(1); $c = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$this->g->setCharacter($c); $this->g->setCharacter($c);
// There should'nt be any listeners to provide a default scene. // There should'nt be any listeners to provide a default scene.
@@ -146,7 +147,7 @@ class GameTest extends CoreModelTestCase
public function testGetViewpointStored() public function testGetViewpointStored()
{ {
$c = $this->getEntityManager()->getRepository(Character::class)->find(2); $c = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$this->g->setCharacter($c); $this->g->setCharacter($c);
$this->assertNotNull($this->g->getViewpoint()); $this->assertNotNull($this->g->getViewpoint());
@@ -154,11 +155,12 @@ class GameTest extends CoreModelTestCase
public function testGetViewpointDefault() public function testGetViewpointDefault()
{ {
$c = $this->getEntityManager()->getRepository(Character::class)->find(1); $c = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$this->g->setCharacter($c); $this->g->setCharacter($c);
$this->g->getEventManager()->subscribe('/h\/lotgd\/core\/default-scene/', DefaultSceneProvider::class, 'lotgd/core/tests'); $this->g->getEventManager()->subscribe('/h\/lotgd\/core\/default-scene/', DefaultSceneProvider::class, 'lotgd/core/tests');
$this->g->getEventManager()->subscribe('/h\/lotgd\/core\/navigate-to\/.*/', DefaultSceneProvider::class, 'lotgd/core/tests'); $this->g->getEventManager()->subscribe('/h\/lotgd\/core\/navigate-to\/.*/', DefaultSceneProvider::class, 'lotgd/core/tests');
$this->getEntityManager()->flush();
$v = $this->g->getViewpoint(); $v = $this->g->getViewpoint();
// Run it twice to make sure no additional DB operations happen. // Run it twice to make sure no additional DB operations happen.
@@ -175,7 +177,7 @@ class GameTest extends CoreModelTestCase
public function testTakeActionNonExistant() public function testTakeActionNonExistant()
{ {
$c = $this->getEntityManager()->getRepository(Character::class)->find(1); $c = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$this->g->setCharacter($c); $this->g->setCharacter($c);
// For now, I cant seem to serialize a proper ActionGroup to store in // For now, I cant seem to serialize a proper ActionGroup to store in
@@ -188,7 +190,7 @@ class GameTest extends CoreModelTestCase
public function testTakeActionNavigate() public function testTakeActionNavigate()
{ {
$c = $this->getEntityManager()->getRepository(Character::class)->find(3); $c = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000003");
$this->g->setCharacter($c); $this->g->setCharacter($c);
// For now, I cant seem to serialize a proper ActionGroup to store in // For now, I cant seem to serialize a proper ActionGroup to store in
@@ -209,13 +211,14 @@ class GameTest extends CoreModelTestCase
public function testIfActionParametersAreRelayedToEvent() public function testIfActionParametersAreRelayedToEvent()
{ {
/* @var $c Character */ /* @var $c Character */
$c = $this->getEntityManager()->getRepository(Character::class)->find(2); $c = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$this->g->setCharacter($c); $this->g->setCharacter($c);
// subscribe event // subscribe event
$this->g->getEventManager()->subscribe('#h/lotgd/core/navigate-to/lotgd/tests/paramaters#', DefaultSceneProvider::class, 'lotgd/core/tests'); $this->g->getEventManager()->subscribe('#h/lotgd/core/navigate-to/lotgd/tests/paramaters#', DefaultSceneProvider::class, 'lotgd/core/tests');
$this->getEntityManager()->flush();
$action = new Action(7, null, ["foo" => "baz"]); $action = new Action("30000000-0000-0000-0000-000000000007", null, ["foo" => "baz"]);
$actionId = $action->getId(); $actionId = $action->getId();
$ag = new ActionGroup("group1", "Group 1", 5); $ag = new ActionGroup("group1", "Group 1", 5);
@@ -238,13 +241,14 @@ class GameTest extends CoreModelTestCase
public function testIfActionParametersTakePriorityToOtherParameters() public function testIfActionParametersTakePriorityToOtherParameters()
{ {
/* @var $c Character */ /* @var $c Character */
$c = $this->getEntityManager()->getRepository(Character::class)->find(2); $c = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$this->g->setCharacter($c); $this->g->setCharacter($c);
// subscribe event // subscribe event
$this->g->getEventManager()->subscribe('#h/lotgd/core/navigate-to/lotgd/tests/paramaters#', DefaultSceneProvider::class, 'lotgd/core/tests'); $this->g->getEventManager()->subscribe('#h/lotgd/core/navigate-to/lotgd/tests/paramaters#', DefaultSceneProvider::class, 'lotgd/core/tests');
$this->getEntityManager()->flush();
$action = new Action(7, null, ["foo" => "baz"]); $action = new Action("30000000-0000-0000-0000-000000000007", null, ["foo" => "baz"]);
$actionId = $action->getId(); $actionId = $action->getId();
$ag = new ActionGroup("group1", "Group 1", 5); $ag = new ActionGroup("group1", "Group 1", 5);
@@ -285,7 +289,7 @@ class GameTest extends CoreModelTestCase
return $values; return $values;
}; };
$c = $this->getEntityManager()->getRepository(Character::class)->find(3); $c = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000003");
$this->g->setCharacter($c); $this->g->setCharacter($c);
$v0 = $this->g->getViewpoint(); $v0 = $this->g->getViewpoint();
@@ -295,9 +299,9 @@ class GameTest extends CoreModelTestCase
$this->assertSame([ $this->assertSame([
"Parent Scene", "Parent Scene",
[ [
ActionGroup::DefaultGroup => [1], ActionGroup::DefaultGroup => ["30000000-0000-0000-0000-000000000001"],
"lotgd/tests/none/child1" => [5], "lotgd/tests/none/child1" => ["30000000-0000-0000-0000-000000000005"],
"lotgd/tests/none/child2" => [6], "lotgd/tests/none/child2" => ["30000000-0000-0000-0000-000000000006"],
ActionGroup::HiddenGroup => [], ActionGroup::HiddenGroup => [],
] ]
], $viewpointToArray($v1)); ], $viewpointToArray($v1));
@@ -307,7 +311,10 @@ class GameTest extends CoreModelTestCase
$this->assertSame([ $this->assertSame([
"Child Scene 1", "Child Scene 1",
[ [
ActionGroup::DefaultGroup => [6, 4], ActionGroup::DefaultGroup => [
"30000000-0000-0000-0000-000000000006",
"30000000-0000-0000-0000-000000000004"
],
ActionGroup::HiddenGroup => [], ActionGroup::HiddenGroup => [],
] ]
], $viewpointToArray($v2)); ], $viewpointToArray($v2));
@@ -317,7 +324,7 @@ class GameTest extends CoreModelTestCase
$this->assertSame([ $this->assertSame([
"Child Scene 2", "Child Scene 2",
[ [
ActionGroup::DefaultGroup => [4], ActionGroup::DefaultGroup => ["30000000-0000-0000-0000-000000000004"],
ActionGroup::HiddenGroup => [], ActionGroup::HiddenGroup => [],
] ]
], $viewpointToArray($v3)); ], $viewpointToArray($v3));
+3 -1
View File
@@ -59,10 +59,12 @@ abstract class ModelTestCase extends \PHPUnit_Extensions_Database_TestCase
// Read db annotations from model files // Read db annotations from model files
$configuration = Setup::createAnnotationMetadataConfiguration($directories, true); $configuration = Setup::createAnnotationMetadataConfiguration($directories, true);
$configuration->setQuoteStrategy(new AnsiQuoteStrategy());
self::$em = EntityManager::create(["pdo" => self::$pdo], $configuration); self::$em = EntityManager::create(["pdo" => self::$pdo], $configuration);
// Register uuid type
\Doctrine\DBAL\Types\Type::addType('uuid', 'Ramsey\Uuid\Doctrine\UuidType');
// Create Schema // Create Schema
$metaData = self::$em->getMetadataFactory()->getAllMetadata(); $metaData = self::$em->getMetadataFactory()->getAllMetadata();
$schemaTool = new SchemaTool(self::$em); $schemaTool = new SchemaTool(self::$em);
+7 -5
View File
@@ -12,6 +12,7 @@ use LotGD\Core\Models\Character;
use LotGD\Core\Models\CharacterProperty; use LotGD\Core\Models\CharacterProperty;
use LotGD\Core\Tests\CoreModelTestCase; use LotGD\Core\Tests\CoreModelTestCase;
use LotGD\Core\Models\Repositories\CharacterRepository; use LotGD\Core\Models\Repositories\CharacterRepository;
use Ramsey\Uuid\UuidInterface;
/** /**
* Tests the management of Characters * Tests the management of Characters
@@ -26,13 +27,13 @@ class CharacterModelTest extends CoreModelTestCase
*/ */
public function testSoftDeletion() public function testSoftDeletion()
{ {
$chars = $this->getEntityManager()->getRepository(Character::class)->find(3); $chars = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000003");
$this->assertSame(null, $chars); $this->assertSame(null, $chars);
$allChars = $this->getEntityManager()->getRepository(Character::class)->findAll(); $allChars = $this->getEntityManager()->getRepository(Character::class)->findAll();
$this->assertSame(2, count($allChars)); $this->assertSame(2, count($allChars));
$char = $this->getEntityManager()->getRepository(Character::class)->find(1); $char = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$char->delete($this->getEntityManager()); $char->delete($this->getEntityManager());
$this->getEntityManager()->flush(); $this->getEntityManager()->flush();
$this->getEntityManager()->clear(); $this->getEntityManager()->clear();
@@ -101,7 +102,7 @@ class CharacterModelTest extends CoreModelTestCase
$em->flush(); $em->flush();
$this->assertInternalType("int", $characterEntity->getId()); $this->assertInstanceOf(UuidInterface::class, $characterEntity->getId());
$this->assertSame(16, $characterEntity->getProperty("a property")); $this->assertSame(16, $characterEntity->getProperty("a property"));
$em->flush(); $em->flush();
@@ -142,7 +143,7 @@ class CharacterModelTest extends CoreModelTestCase
$rowsBefore = count($em->getRepository(Character::class)->findAll()); $rowsBefore = count($em->getRepository(Character::class)->findAll());
// Delete one row // Delete one row
$character = $em->getRepository(Character::class)->find(1); $character = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$character->delete($em); $character->delete($em);
$em->clear(); $em->clear();
@@ -163,7 +164,7 @@ class CharacterModelTest extends CoreModelTestCase
$em = $this->getEntityManager(); $em = $this->getEntityManager();
// test default values // test default values
$firstCharacter = $em->getRepository(Character::class)->find(1); $firstCharacter = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$this->assertSame(5, $firstCharacter->getProperty("dragonkills", 5)); $this->assertSame(5, $firstCharacter->getProperty("dragonkills", 5));
$this->assertNotSame(5, $firstCharacter->getProperty("dragonkills", "5")); $this->assertNotSame(5, $firstCharacter->getProperty("dragonkills", "5"));
$this->assertSame("hanniball", $firstCharacter->getProperty("petname", "hanniball")); $this->assertSame("hanniball", $firstCharacter->getProperty("petname", "hanniball"));
@@ -226,6 +227,7 @@ class CharacterModelTest extends CoreModelTestCase
$eventManager->subscribe("#h/lotgd/core/getCharacterAttack#", get_class($detectionClass), "test"); $eventManager->subscribe("#h/lotgd/core/getCharacterAttack#", get_class($detectionClass), "test");
$eventManager->subscribe("#h/lotgd/core/getCharacterDefense#", get_class($detectionClass), "test"); $eventManager->subscribe("#h/lotgd/core/getCharacterDefense#", get_class($detectionClass), "test");
$this->getEntityManager()->flush();
$this->assertSame($level*2, $character1->getAttack()); $this->assertSame($level*2, $character1->getAttack());
$this->assertSame($level*4, $character2->getDefense()); $this->assertSame($level*4, $character2->getDefense());
+269
View File
@@ -0,0 +1,269 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Tests\Models;
use LotGD\Core\EventHandler;
use LotGD\Core\Events\EventContext;
use LotGD\Core\Exceptions\CharacterStatExistsException;
use LotGD\Core\Exceptions\CharacterStatGroupExistsException;
use LotGD\Core\Exceptions\CharacterStatGroupNotFoundException;
use LotGD\Core\Exceptions\CharacterStatNotFoundException;
use LotGD\Core\Game;
use LotGD\Core\Models\Character;
use LotGD\Core\Models\CharacterStatGroup;
use LotGD\Core\Models\CharacterStats;
use LotGD\Core\Tests\CoreModelTestCase;
class TestEventProvider implements EventHandler
{
static $called = 0;
static $last_context;
public static function handleEvent(Game $g, EventContext $context): EventContext
{
$stats = $context->getDataField("stats");
$character = $context->getDataField("character");
self::$called++;
self::$last_context = $context;
return $context;
}
}
class CharaterStatsTest extends CoreModelTestCase
{
/** @var string default data set */
protected $dataset = "character_stats";
public function setUp()
{
parent::setUp();
$game = $this->g;
$game->getEventManager()->subscribe("#h/lotgd/core/characterStats/populate#", TestEventProvider::class, "lotgd/test");
$this->getEntityManager()->flush();
}
public function tearDown()
{
$game = $this->g;
$game->getEventManager()->unsubscribe("#h/lotgd/core/characterStats/populate#", TestEventProvider::class, "lotgd/test");
$this->getEntityManager()->flush();
parent::tearDown();
}
public function testICharacterStatPopulationEventGetsCalled()
{
$character = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$stats = new CharacterStats($this->g, $character);
$this->assertSame(1, TestEventProvider::$called);
}
public function testIfCharacterStatPopulationEventUsesCorrectTypes()
{
$character = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$stats = new CharacterStats($this->g, $character);
$this->assertInstanceOf(CharacterStats::class, TestEventProvider::$last_context->getDataField("stats"));
$this->assertInstanceOf(Character::class, TestEventProvider::$last_context->getDataField("character"));
}
public function testIfCharacterStatGroupCanGetAddedToCharacterStats()
{
$character = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$stats = new CharacterStats($this->g, $character);
$group = new CharacterStatGroup("vendor/test", "Test");
$stats->addCharacterStatGroup($group);
$this->assertSame($group, $stats->getCharacterStatGroup("vendor/test"));
}
public function testIfAddingCharacterStatGroupWithSameIdResultsInException()
{
$character = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$stats = new CharacterStats($this->g, $character);
$group = new CharacterStatGroup("vendor/test", "Test");
$stats->addCharacterStatGroup($group);
$this->assertTrue($stats->hasCharacterStatGroup($group->getId()));
$this->expectException(CharacterStatGroupExistsException::class);
$group2 = new CharacterStatGroup("vendor/test", "Test");
$stats->addCharacterStatGroup($group2);
}
public function testIfGettingUnknownCharacterStatGroupResultsInException()
{
$character = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$stats = new CharacterStats($this->g, $character);
$group = new CharacterStatGroup("vendor/test", "Test");
$this->assertFalse($stats->hasCharacterStatGroup($group->getId()));
$this->expectException(CharacterStatGroupNotFoundException::class);
$stats->getCharacterStatGroup($group->getId());
}
public function testIfIteratingCharacterStatsYieldsAllStatGroups()
{
$character = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$stats = new CharacterStats($this->g, $character);
$groups = [
new CharacterStatGroup("vendor/test-0", "Test 1"),
new CharacterStatGroup("vendor/test-1", "Test 2"),
new CharacterStatGroup("vendor/test-2", "Test 3")
];
foreach ($groups as $group) {
$stats->addCharacterStatGroup($group);
}
$i = 0;
foreach($stats->iterate() as $statGroup)
{
$this->assertInstanceOf(CharacterStatGroup::class, $statGroup);
$this->assertTrue($stats->hasCharacterStatGroup($statGroup->getId()));
$this->assertSame($groups[$i], $statGroup);
$i++;
}
}
public function testIfIteratingCharacterStatsYieldsAllStatGroupsSortedAccordingToTheirWeight()
{
$character = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$stats = new CharacterStats($this->g, $character);
$groups = [
new CharacterStatGroup("vendor/test-0", "Test 1", 100),
new CharacterStatGroup("vendor/test-1", "Test 2", 0),
new CharacterStatGroup("vendor/test-2", "Test 3", -100)
];
foreach ($groups as $group) {
$stats->addCharacterStatGroup($group);
}
$i = 0;
foreach($stats->iterate() as $statGroup)
{
$this->assertInstanceOf(CharacterStatGroup::class, $statGroup);
$this->assertTrue($stats->hasCharacterStatGroup($statGroup->getId()));
$this->assertSame($groups[2-$i], $statGroup);
$i++;
}
}
public function testIfCharacterStatCanGetAddedToCharacterStatGroup()
{
$character = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$stats = new CharacterStats($this->g, $character);
$group = new CharacterStatGroup("vendor/test", "Test");
$stats->addCharacterStatGroup($group);
$stat = new CharacterStats\BaseCharacterStat("vendor/test/item", "Item", 17);
$group->addCharacterStat($stat);
$this->assertSame($stat, $group->getCharacterStat("vendor/test/item"));
}
public function testIfAddingCharacterStatWithSameIdResultsInException()
{
$character = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$stats = new CharacterStats($this->g, $character);
$group = new CharacterStatGroup("vendor/test", "Test");
$stats->addCharacterStatGroup($group);
$stat = new CharacterStats\BaseCharacterStat("vendor/test/item", "Item", 17);
$group->addCharacterStat($stat);
$this->assertTrue($group->hasCharacterStat($stat->getId()));
$this->expectException(CharacterStatExistsException::class);
$stat2 = new CharacterStats\BaseCharacterStat("vendor/test/item", "Item", 17);
$group->addCharacterStat($stat2);
}
public function testIfGettingUnknownCharacterStatResultsInException()
{
$character = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$stats = new CharacterStats($this->g, $character);
$group = new CharacterStatGroup("vendor/test", "Test");
$stats->addCharacterStatGroup($group);
$stat = new CharacterStats\BaseCharacterStat("vendor/test/item", "Item", 17);
$this->assertFalse($group->hasCharacterStat($stat->getId()));
$this->expectException(CharacterStatNotFoundException::class);
$group->getCharacterStat($group->getId());
}
public function testIfIteratingCharacterGroupYieldsAllStatGroups()
{
$character = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$stats = new CharacterStats($this->g, $character);
$stats = [
new CharacterStats\BaseCharacterStat("vendor/test/item-0", "Item 1", 17),
new CharacterStats\BaseCharacterStat("vendor/test/item-1", "Item 2", 18),
new CharacterStats\BaseCharacterStat("vendor/test/item-2", "Item 3", 19),
];
$group = new CharacterStatGroup("vendor/test", "Test-Group");
foreach ($stats as $stat) {
$group->addCharacterStat($stat);
}
$i = 0;
foreach($group->iterate() as $stat) {
$this->assertInstanceOf(CharacterStats\BaseCharacterStat::class, $stat);
$this->assertTrue($group->hasCharacterStat($stat->getId()));
$this->assertSame($stats[$i], $stat);
$i++;
}
}
public function testIfIteratingCharacterGroupYieldsAllStatGroupsIfWeightsAreGiven()
{
$character = $this->getEntityManager()->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$stats = new CharacterStats($this->g, $character);
$stats = [
new CharacterStats\BaseCharacterStat("vendor/test/item-0", "Item 1", 17, 100),
new CharacterStats\BaseCharacterStat("vendor/test/item-1", "Item 2", 18, 0),
new CharacterStats\BaseCharacterStat("vendor/test/item-2", "Item 3", 19, -1),
];
$group = new CharacterStatGroup("vendor/test", "Test-Group");
foreach ($stats as $stat) {
$group->addCharacterStat($stat);
}
$i = 0;
foreach($group->iterate() as $stat) {
$this->assertInstanceOf(CharacterStats\BaseCharacterStat::class, $stat);
$this->assertTrue($group->hasCharacterStat($stat->getId()));
$this->assertSame($stats[2-$i], $stat);
$i++;
}
}
}
+20 -20
View File
@@ -24,8 +24,8 @@ class MessageModelTest extends CoreModelTestCase
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$mm=new MessageManager(); $mm=new MessageManager();
$character1 = $em->getRepository(Character::class)->find(1); $character1 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$character2 = $em->getRepository(Character::class)->find(4); $character2 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000004");
$thread1 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character1, $character2]); $thread1 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character1, $character2]);
$thread2 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character2, $character1]); $thread2 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character2, $character1]);
@@ -42,8 +42,8 @@ class MessageModelTest extends CoreModelTestCase
$em->flush(); $em->flush();
$em->clear(); $em->clear();
$character1 = $em->getRepository(Character::class)->find(1); $character1 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$character2 = $em->getRepository(Character::class)->find(4); $character2 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000004");
$thread1 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character1, $character2]); $thread1 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character1, $character2]);
@@ -62,10 +62,10 @@ class MessageModelTest extends CoreModelTestCase
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$mm=new MessageManager(); $mm=new MessageManager();
$character1 = $em->getRepository(Character::class)->find(1); $character1 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$character2 = $em->getRepository(Character::class)->find(2); $character2 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$character3 = $em->getRepository(Character::class)->find(3, NULL, NULL, CharacterRepository::INCLUDE_SOFTDELETED); $character3 = $em->getRepository(Character::class)->findWithSoftDeleted("10000000-0000-0000-0000-000000000003");
$character4 = $em->getRepository(Character::class)->find(4); $character4 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000004");
$thread1 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character1, $character2, $character3, $character4]); $thread1 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character1, $character2, $character3, $character4]);
$thread2 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character4, $character2, $character1, $character3]); $thread2 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character4, $character2, $character1, $character3]);
@@ -90,10 +90,10 @@ class MessageModelTest extends CoreModelTestCase
$em->flush(); $em->flush();
$character1 = $em->getRepository(Character::class)->find(1); $character1 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$character2 = $em->getRepository(Character::class)->find(2); $character2 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$character3 = $em->getRepository(Character::class)->find(3, NULL, NULL, CharacterRepository::INCLUDE_SOFTDELETED); $character3 = $em->getRepository(Character::class)->findWithSoftDeleted("10000000-0000-0000-0000-000000000003");
$character4 = $em->getRepository(Character::class)->find(4); $character4 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000004");
$thread1 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character1, $character2, $character3, $character4]); $thread1 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character1, $character2, $character3, $character4]);
@@ -111,8 +111,8 @@ class MessageModelTest extends CoreModelTestCase
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$mm=new MessageManager(); $mm=new MessageManager();
$character1 = $em->getRepository(Character::class)->find(1); $character1 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$character2 = $em->getRepository(Character::class)->find(2); $character2 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$thread1 = $em->getRepository(MessageThread::class)->findOrCreateReadonlyFor([$character1]); $thread1 = $em->getRepository(MessageThread::class)->findOrCreateReadonlyFor([$character1]);
$thread2 = $em->getRepository(MessageThread::class)->findOrCreateReadonlyFor([$character2]); $thread2 = $em->getRepository(MessageThread::class)->findOrCreateReadonlyFor([$character2]);
@@ -125,8 +125,8 @@ class MessageModelTest extends CoreModelTestCase
$em->flush(); $em->flush();
$em->clear(); $em->clear();
$character1 = $em->getRepository(Character::class)->find(1); $character1 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$character2 = $em->getRepository(Character::class)->find(2); $character2 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$thread1 = $em->getRepository(MessageThread::class)->findOrCreateReadonlyFor([$character1]); $thread1 = $em->getRepository(MessageThread::class)->findOrCreateReadonlyFor([$character1]);
$thread2 = $em->getRepository(MessageThread::class)->findOrCreateReadonlyFor([$character2]); $thread2 = $em->getRepository(MessageThread::class)->findOrCreateReadonlyFor([$character2]);
@@ -154,8 +154,8 @@ class MessageModelTest extends CoreModelTestCase
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$mm=new MessageManager(); $mm=new MessageManager();
$character1 = $em->getRepository(Character::class)->find(1); $character1 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$character2 = $em->getRepository(Character::class)->find(2); $character2 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$thread1 = $em->getRepository(MessageThread::class)->findOrCreateReadonlyFor([$character1, $character2]); $thread1 = $em->getRepository(MessageThread::class)->findOrCreateReadonlyFor([$character1, $character2]);
$thread2 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character1, $character2]); $thread2 = $em->getRepository(MessageThread::class)->findOrCreateFor([$character1, $character2]);
@@ -167,8 +167,8 @@ class MessageModelTest extends CoreModelTestCase
$em->flush(); $em->flush();
$em->clear(); $em->clear();
$character1 = $em->getRepository(Character::class)->find(1); $character1 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$character2 = $em->getRepository(Character::class)->find(2); $character2 = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$thread1 = $em->getRepository(MessageThread::class)->findOrCreateReadonlyFor([$character1, $character2]); $thread1 = $em->getRepository(MessageThread::class)->findOrCreateReadonlyFor([$character1, $character2]);
+8 -9
View File
@@ -19,10 +19,10 @@ class MotDModelTest extends CoreModelTestCase
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$author = $em->getRepository(Character::class)->find(1); $author = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
// Test normal message // Test normal message
$motd1 = $em->getRepository(MotD::class)->find(1); $motd1 = $em->getRepository(MotD::class)->find("20000000-0000-0000-0000-000000000001");
$this->assertSame("This is the title", $motd1->getTitle()); $this->assertSame("This is the title", $motd1->getTitle());
$this->assertSame("This is the body of the message", $motd1->getBody()); $this->assertSame("This is the body of the message", $motd1->getBody());
$this->assertSame($author, $motd1->getAuthor()); $this->assertSame($author, $motd1->getAuthor());
@@ -30,14 +30,14 @@ class MotDModelTest extends CoreModelTestCase
$this->assertFalse($motd1->getSystemMessage()); $this->assertFalse($motd1->getSystemMessage());
// Test System message // Test System message
$motd2 = $em->getRepository(MotD::class)->find(2); $motd2 = $em->getRepository(MotD::class)->find("20000000-0000-0000-0000-000000000002");
$this->assertTrue($motd2->getSystemMessage()); $this->assertTrue($motd2->getSystemMessage());
$this->assertNotSame($motd2->getAuthor(), $motd2->getApparantAuthor()); $this->assertNotSame($motd2->getAuthor(), $motd2->getApparantAuthor());
$this->assertSame($author, $motd2->getAuthor()); $this->assertSame($author, $motd2->getAuthor());
$this->assertNotSame("Deleted Character Name", $motd2->getAuthor()->getDisplayName()); $this->assertNotSame("Deleted Character Name", $motd2->getAuthor()->getDisplayName());
// Test message with unknown author // Test message with unknown author
$motd3 = $em->getRepository(Motd::class)->find(3); $motd3 = $em->getRepository(Motd::class)->find("20000000-0000-0000-0000-000000000003");
$this->assertSame("Deleted Testcharacter", $motd3->getAuthor()->getDisplayName()); $this->assertSame("Deleted Testcharacter", $motd3->getAuthor()->getDisplayName());
} }
@@ -45,7 +45,7 @@ class MotDModelTest extends CoreModelTestCase
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$time1 = $em->getRepository(MotD::class)->find(1)->getCreationTime(); $time1 = $em->getRepository(MotD::class)->find("20000000-0000-0000-0000-000000000001")->getCreationTime();
$time2 = new \DateTime("2016-05-03 14:19:12"); $time2 = new \DateTime("2016-05-03 14:19:12");
$time3 = $time2->setTimezone(new \DateTimeZone("Europe/Zurich")); $time3 = $time2->setTimezone(new \DateTimeZone("Europe/Zurich"));
$time4 = new \DateTime("2016-05-03 14:19:12"); $time4 = new \DateTime("2016-05-03 14:19:12");
@@ -63,13 +63,13 @@ class MotDModelTest extends CoreModelTestCase
{ {
return [ return [
[[ [[
"author" => 1, "author" => "10000000-0000-0000-0000-000000000001",
"title" => "ABC_\"EFG", "title" => "ABC_\"EFG",
"body" => "Lorem îpsum etc pp", "body" => "Lorem îpsum etc pp",
"systemMessage" => false, "systemMessage" => false,
]], ]],
[[ [[
"author" => 1, "author" => "10000000-0000-0000-0000-000000000001",
"title" => "AnotherOne", "title" => "AnotherOne",
"body" => "Test a Second One", "body" => "Test a Second One",
"systemMessage" => true, "systemMessage" => true,
@@ -87,10 +87,9 @@ class MotDModelTest extends CoreModelTestCase
$motdCreationArguments["author"] = $em->getRepository(Character::class)->find($motdCreationArguments["author"]); $motdCreationArguments["author"] = $em->getRepository(Character::class)->find($motdCreationArguments["author"]);
$motd = MotD::create($motdCreationArguments); $motd = MotD::create($motdCreationArguments);
$motd->save($em);
$id = $motd->getId(); $id = $motd->getId();
$em->persist($motd);
$em->flush(); $em->flush();
$em->clear(); $em->clear();
+37 -33
View File
@@ -3,8 +3,6 @@ declare(strict_types=1);
namespace LotGD\Core\Tests\Models; namespace LotGD\Core\Tests\Models;
use Doctrine\Common\Collections\ArrayCollection;
use LotGD\Core\Exceptions\ArgumentException; use LotGD\Core\Exceptions\ArgumentException;
use LotGD\Core\Models\{Scene, SceneConnection, SceneConnectionGroup}; use LotGD\Core\Models\{Scene, SceneConnection, SceneConnectionGroup};
use LotGD\Core\Tests\CoreModelTestCase; use LotGD\Core\Tests\CoreModelTestCase;
@@ -54,6 +52,8 @@ class SceneModelTest extends CoreModelTestCase
// create new scene, flush and clear. Number of scenes in db should be +1 // create new scene, flush and clear. Number of scenes in db should be +1
$newScene = Scene::create($this->getTestSceneData()); $newScene = Scene::create($this->getTestSceneData());
$id = $newScene->getId();
$newScene->save($em); $newScene->save($em);
$this->flushAndClear(); $this->flushAndClear();
unset($newScene); unset($newScene);
@@ -63,7 +63,7 @@ class SceneModelTest extends CoreModelTestCase
$this->assertSame($n1 + 1, $n2); $this->assertSame($n1 + 1, $n2);
// fetch new scene, delete, flush and clear. // fetch new scene, delete, flush and clear.
$newScene = $em->getRepository(Scene::class)->findOneBy($this->getTestSceneData()); $newScene = $em->getRepository(Scene::class)->find($id);
$newScene->delete($em); $newScene->delete($em);
$this->flushAndClear(); $this->flushAndClear();
@@ -87,7 +87,7 @@ class SceneModelTest extends CoreModelTestCase
// create new scene, connect to another one. Number of scenes must be +1, number of connections must be +1 // create new scene, connect to another one. Number of scenes must be +1, number of connections must be +1
// this tests for cascade=persist // this tests for cascade=persist
$scene = Scene::create($this->getTestSceneData()); $scene = Scene::create($this->getTestSceneData());
$scene->connect($em->getRepository(Scene::class)->find(1)); $scene->connect($em->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001"));
$scene->save($em); $scene->save($em);
$this->flushAndClear(); $this->flushAndClear();
unset($scene); unset($scene);
@@ -144,7 +144,7 @@ class SceneModelTest extends CoreModelTestCase
public function testGetters() public function testGetters()
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$scene = $em->getRepository(Scene::class)->find(2); $scene = $em->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000002");
$this->assertEquals("The Forest", $scene->getTitle()); $this->assertEquals("The Forest", $scene->getTitle());
$this->assertEquals("This is a very dangerous and dark forest", $scene->getDescription()); $this->assertEquals("This is a very dangerous and dark forest", $scene->getDescription());
@@ -154,7 +154,7 @@ class SceneModelTest extends CoreModelTestCase
public function testIfHasConnectionGroupReturnsTrueIfConnectionGroupExists() public function testIfHasConnectionGroupReturnsTrueIfConnectionGroupExists()
{ {
$scene = $this->getEntityManager()->getRepository(Scene::class)->find(1); $scene = $this->getEntityManager()->getRepository(Scene::class)->find( "30000000-0000-0000-0000-000000000001");
$this->assertTrue($scene->hasConnectionGroup("lotgd/tests/village/outside")); $this->assertTrue($scene->hasConnectionGroup("lotgd/tests/village/outside"));
$this->assertTrue($scene->hasConnectionGroup("lotgd/tests/village/market")); $this->assertTrue($scene->hasConnectionGroup("lotgd/tests/village/market"));
@@ -163,14 +163,14 @@ class SceneModelTest extends CoreModelTestCase
public function testIfHasConnectionGroupReturnsFalseIfConnectionGroupDoesNotExist() public function testIfHasConnectionGroupReturnsFalseIfConnectionGroupDoesNotExist()
{ {
$scene2 = $this->getEntityManager()->getRepository(Scene::class)->find(2); $scene2 = $this->getEntityManager()->getRepository(Scene::class)->find( "30000000-0000-0000-0000-000000000002");
$this->assertFalse($scene2->hasConnectionGroup("lotgd/tests/village/outside")); $this->assertFalse($scene2->hasConnectionGroup("lotgd/tests/village/outside"));
$this->assertFalse($scene2->hasConnectionGroup("lotgd/tests/village/market")); $this->assertFalse($scene2->hasConnectionGroup("lotgd/tests/village/market"));
$this->assertFalse($scene2->hasConnectionGroup("lotgd/tests/village/empty")); $this->assertFalse($scene2->hasConnectionGroup("lotgd/tests/village/empty"));
$scene1 = $this->getEntityManager()->getRepository(Scene::class)->find(1); $scene1 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
$this->assertFalse($scene1->hasConnectionGroup("lotgd/tests/village/23426")); $this->assertFalse($scene1->hasConnectionGroup("lotgd/tests/village/23426"));
} }
@@ -178,7 +178,7 @@ class SceneModelTest extends CoreModelTestCase
public function testIfAddConnectionGroupWorks() public function testIfAddConnectionGroupWorks()
{ {
$connectionGroup = new SceneConnectionGroup("lotgd/tests/village/new", "New Street"); $connectionGroup = new SceneConnectionGroup("lotgd/tests/village/new", "New Street");
$scene = $this->getEntityManager()->getRepository(Scene::class)->find(1); $scene = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
$this->assertFalse($scene->hasConnectionGroup("lotgd/tests/village/new")); $this->assertFalse($scene->hasConnectionGroup("lotgd/tests/village/new"));
@@ -191,8 +191,9 @@ class SceneModelTest extends CoreModelTestCase
public function testIfAddConnectionGroupThrowsArgumentExceptionIfGroupIsAlreadyAssignedToItself() public function testIfAddConnectionGroupThrowsArgumentExceptionIfGroupIsAlreadyAssignedToItself()
{ {
$scene = $this->getEntityManager()->getRepository(Scene::class)->find(1); $scene = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
$connectionGroup = $this->getEntityManager()->getRepository(SceneConnectionGroup::class)->findOneBy(["scene" => 1, "name" => "lotgd/tests/village/outside"]); $connectionGroup = $this->getEntityManager()->getRepository(SceneConnectionGroup::class)
->findOneBy(["scene" => "30000000-0000-0000-0000-000000000001", "name" => "lotgd/tests/village/outside"]);
$this->expectException(ArgumentException::class); $this->expectException(ArgumentException::class);
$scene->addConnectionGroup($connectionGroup); $scene->addConnectionGroup($connectionGroup);
@@ -200,8 +201,9 @@ class SceneModelTest extends CoreModelTestCase
public function testIfAddConnectionGroupThrowsArgumentExceptionIfGroupIsAlreadyAssignedToSomwhereElse() public function testIfAddConnectionGroupThrowsArgumentExceptionIfGroupIsAlreadyAssignedToSomwhereElse()
{ {
$scene = $this->getEntityManager()->getRepository(Scene::class)->find(2); $scene = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000002");
$connectionGroup = $this->getEntityManager()->getRepository(SceneConnectionGroup::class)->findOneBy(["scene" => 1, "name" => "lotgd/tests/village/outside"]); $connectionGroup = $this->getEntityManager()->getRepository(SceneConnectionGroup::class)
->findOneBy(["scene" => "30000000-0000-0000-0000-000000000001", "name" => "lotgd/tests/village/outside"]);
$this->expectException(ArgumentException::class); $this->expectException(ArgumentException::class);
$scene->addConnectionGroup($connectionGroup); $scene->addConnectionGroup($connectionGroup);
@@ -209,8 +211,9 @@ class SceneModelTest extends CoreModelTestCase
public function testifDropConnectionGroupWorks() public function testifDropConnectionGroupWorks()
{ {
$scene = $this->getEntityManager()->getRepository(Scene::class)->find(1); $scene = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
$connectionGroup = $this->getEntityManager()->getRepository(SceneConnectionGroup::class)->findOneBy(["scene" => 1, "name" => "lotgd/tests/village/outside"]); $connectionGroup = $this->getEntityManager()->getRepository(SceneConnectionGroup::class)
->findOneBy(["scene" => "30000000-0000-0000-0000-000000000001", "name" => "lotgd/tests/village/outside"]);
$this->assertTrue($scene->hasConnectionGroup("lotgd/tests/village/outside")); $this->assertTrue($scene->hasConnectionGroup("lotgd/tests/village/outside"));
@@ -223,8 +226,9 @@ class SceneModelTest extends CoreModelTestCase
public function testIfDropConnectionGroupThrowsArgumentExceptionIfEntityIsRemovedFromNonOwningScene() public function testIfDropConnectionGroupThrowsArgumentExceptionIfEntityIsRemovedFromNonOwningScene()
{ {
$scene = $this->getEntityManager()->getRepository(Scene::class)->find(2); $scene = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000002");
$connectionGroup = $this->getEntityManager()->getRepository(SceneConnectionGroup::class)->findOneBy(["scene" => 1, "name" => "lotgd/tests/village/outside"]); $connectionGroup = $this->getEntityManager()->getRepository(SceneConnectionGroup::class)
->findOneBy(["scene" => "30000000-0000-0000-0000-000000000001", "name" => "lotgd/tests/village/outside"]);
$this->expectException(ArgumentException::class); $this->expectException(ArgumentException::class);
$scene->dropConnectionGroup($connectionGroup); $scene->dropConnectionGroup($connectionGroup);
@@ -232,8 +236,8 @@ class SceneModelTest extends CoreModelTestCase
public function testIfGetConnectedScenesReturnsConnectedScenes() public function testIfGetConnectedScenesReturnsConnectedScenes()
{ {
$scene1 = $this->getEntityManager()->getRepository(Scene::class)->find(1); $scene1 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
$scene2 = $this->getEntityManager()->getRepository(Scene::class)->find(2); $scene2 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000002");
$this->assertCount(3, $scene1->getConnectedScenes()); $this->assertCount(3, $scene1->getConnectedScenes());
$this->assertCount(1, $scene2->getConnectedScenes()); $this->assertCount(1, $scene2->getConnectedScenes());
@@ -246,9 +250,9 @@ class SceneModelTest extends CoreModelTestCase
public function testIfIsConnectedToReturnsExpectedReturnValue() public function testIfIsConnectedToReturnsExpectedReturnValue()
{ {
$scene1 = $this->getEntityManager()->getRepository(Scene::class)->find(1); $scene1 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
$scene2 = $this->getEntityManager()->getRepository(Scene::class)->find(2); $scene2 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000002");
$scene5 = $this->getEntityManager()->getRepository(Scene::class)->find(5); $scene5 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000005");
$this->assertTrue($scene1->isConnectedTo($scene2)); $this->assertTrue($scene1->isConnectedTo($scene2));
$this->assertTrue($scene2->isConnectedTo($scene1)); $this->assertTrue($scene2->isConnectedTo($scene1));
@@ -260,8 +264,8 @@ class SceneModelTest extends CoreModelTestCase
public function testIfTwoScenesCanGetConnected() public function testIfTwoScenesCanGetConnected()
{ {
$scene1 = $this->getEntityManager()->getRepository(Scene::class)->find(2); $scene1 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000002");
$scene2 = $this->getEntityManager()->getRepository(Scene::class)->find(5); $scene2 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000005");
$scene1->connect($scene2); $scene1->connect($scene2);
@@ -275,8 +279,8 @@ class SceneModelTest extends CoreModelTestCase
public function testIfASceneConnectionGroupCanGetConnectedToAScene() public function testIfASceneConnectionGroupCanGetConnectedToAScene()
{ {
$scene1 = $this->getEntityManager()->getRepository(Scene::class)->find(1); $scene1 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
$scene2 = $this->getEntityManager()->getRepository(Scene::class)->find(5); $scene2 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000005");
$scene1->getConnectionGroup("lotgd/tests/village/outside")->connect($scene2); $scene1->getConnectionGroup("lotgd/tests/village/outside")->connect($scene2);
@@ -290,8 +294,8 @@ class SceneModelTest extends CoreModelTestCase
public function testIfASceneCanGetConnectedToASceneConnectionGroup() public function testIfASceneCanGetConnectedToASceneConnectionGroup()
{ {
$scene1 = $this->getEntityManager()->getRepository(Scene::class)->find(1); $scene1 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
$scene2 = $this->getEntityManager()->getRepository(Scene::class)->find(5); $scene2 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000005");
$scene2->connect($scene1->getConnectionGroup("lotgd/tests/village/outside")); $scene2->connect($scene1->getConnectionGroup("lotgd/tests/village/outside"));
@@ -305,8 +309,8 @@ class SceneModelTest extends CoreModelTestCase
public function testIfASceneConnectionGroupCanGetConnectedToAnotherSceneConnectionGroup() public function testIfASceneConnectionGroupCanGetConnectedToAnotherSceneConnectionGroup()
{ {
$scene1 = $this->getEntityManager()->getRepository(Scene::class)->find(1); $scene1 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
$scene2 = $this->getEntityManager()->getRepository(Scene::class)->find(5); $scene2 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000005");
$scene2->addConnectionGroup(new SceneConnectionGroup("test/orphaned", "Orphan group")); $scene2->addConnectionGroup(new SceneConnectionGroup("test/orphaned", "Orphan group"));
$scene1 $scene1
@@ -325,7 +329,7 @@ class SceneModelTest extends CoreModelTestCase
public function testIfConnectingASceneToItselfThrowsAnException() public function testIfConnectingASceneToItselfThrowsAnException()
{ {
$scene1 = $this->getEntityManager()->getRepository(Scene::class)->find(1); $scene1 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
$this->expectException(ArgumentException::class); $this->expectException(ArgumentException::class);
$scene1->connect($scene1); $scene1->connect($scene1);
@@ -344,8 +348,8 @@ class SceneModelTest extends CoreModelTestCase
public function testIfConnectingASceneToAnotherAlreadyConnectedSceneThrowsAnException() public function testIfConnectingASceneToAnotherAlreadyConnectedSceneThrowsAnException()
{ {
$scene1 = $this->getEntityManager()->getRepository(Scene::class)->find(1); $scene1 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
$scene2 = $this->getEntityManager()->getRepository(Scene::class)->find(2); $scene2 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000002");
$this->expectException(ArgumentException::class); $this->expectException(ArgumentException::class);
$scene1->connect($scene2); $scene1->connect($scene2);
+44 -30
View File
@@ -40,8 +40,8 @@ class ViewpointTest extends CoreModelTestCase
$em = $this->getEntityManager(); $em = $this->getEntityManager();
// Test character with a characterScene // Test character with a characterScene
$testCharacter = $em->getRepository(Character::class)->find(2); $testCharacter = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$this->assertSame(2, $testCharacter->getId()); $this->assertSame("10000000-0000-0000-0000-000000000002", (string)$testCharacter->getId());
$characterScene = $testCharacter->getViewpoint(); $characterScene = $testCharacter->getViewpoint();
$this->assertInstanceOf(Viewpoint::class, $characterScene); $this->assertInstanceOf(Viewpoint::class, $characterScene);
@@ -49,8 +49,8 @@ class ViewpointTest extends CoreModelTestCase
$this->assertSame("This is the village.", $characterScene->getDescription()); $this->assertSame("This is the village.", $characterScene->getDescription());
// Test character without a characterScene // Test character without a characterScene
$testCharacter = $em->getRepository(Character::class)->find(1); $testCharacter = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000001");
$this->assertSame(1, $testCharacter->getId()); $this->assertSame("10000000-0000-0000-0000-000000000001", (string)$testCharacter->getId());
$characterScene = $testCharacter->getViewpoint(); $characterScene = $testCharacter->getViewpoint();
$this->assertNull($characterScene); $this->assertNull($characterScene);
@@ -63,9 +63,9 @@ class ViewpointTest extends CoreModelTestCase
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$testCharacter = $em->getRepository(Character::class)->find(2); $testCharacter = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$testScene = $em->getRepository(Scene::class)->find(2); $testScene = $em->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000002");
$this->assertSame("The Village", $testCharacter->getViewpoint()->getTitle()); $this->assertSame("The Village", $testCharacter->getViewpoint()->getTitle());
@@ -82,12 +82,12 @@ class ViewpointTest extends CoreModelTestCase
$ag1 = new ActionGroup('id1', 'title1', 42); $ag1 = new ActionGroup('id1', 'title1', 42);
$ag1->setActions([ $ag1->setActions([
new Action(1), new Action("30000000-0000-0000-0000-000000000001"),
new Action(2) new Action("30000000-0000-0000-0000-000000000002")
]); ]);
$ag2 = new ActionGroup('id2', 'title2', 101); $ag2 = new ActionGroup('id2', 'title2', 101);
$ag2->setActions([ $ag2->setActions([
new Action(3) new Action("30000000-0000-0000-0000-000000000003")
]); ]);
$actionGroups = [ $actionGroups = [
@@ -95,19 +95,19 @@ class ViewpointTest extends CoreModelTestCase
$ag2 $ag2
]; ];
$input = $em->getRepository(Viewpoint::class)->find(2); $input = $em->getRepository(Viewpoint::class)->find("10000000-0000-0000-0000-000000000002");
$input->setActionGroups($actionGroups); $input->setActionGroups($actionGroups);
$input->save($em); $input->save($em);
$em->clear(); $em->clear();
$output = $em->getRepository(Viewpoint::class)->find(2); $output = $em->getRepository(Viewpoint::class)->find("10000000-0000-0000-0000-000000000002");
$this->assertEquals($actionGroups, $output->getActionGroups()); $this->assertEquals($actionGroups, $output->getActionGroups());
$this->assertEquals($ag2, $input->findActionGroupById('id2')); $this->assertEquals($ag2, $input->findActionGroupById('id2'));
$this->assertNull($input->findActionGroupById('not-there')); $this->assertNull($input->findActionGroupById('not-there'));
$testAction = new Action(4); $testAction = new Action("30000000-0000-0000-0000-000000000004");
$input->addActionToGroupId($testAction, 'not-there'); $input->addActionToGroupId($testAction, 'not-there');
$this->assertNull($input->findActionById($testAction->getId())); $this->assertNull($input->findActionById($testAction->getId()));
@@ -124,13 +124,13 @@ class ViewpointTest extends CoreModelTestCase
$attachments = [$a1, $a2]; $attachments = [$a1, $a2];
$input = $em->getRepository(Viewpoint::class)->find(2); $input = $em->getRepository(Viewpoint::class)->find("10000000-0000-0000-0000-000000000002");
$input->setAttachments($attachments); $input->setAttachments($attachments);
$input->save($em); $input->save($em);
$em->clear(); $em->clear();
$output = $em->getRepository(Viewpoint::class)->find(2); $output = $em->getRepository(Viewpoint::class)->find("10000000-0000-0000-0000-000000000002");
$this->assertEquals($attachments, $output->getAttachments()); $this->assertEquals($attachments, $output->getAttachments());
$this->assertEquals('baz', $output->getAttachments()[0]->getFoo()); $this->assertEquals('baz', $output->getAttachments()[0]->getFoo());
$this->assertEquals('fiz', $output->getAttachments()[1]->getFoo()); $this->assertEquals('fiz', $output->getAttachments()[1]->getFoo());
@@ -140,9 +140,9 @@ class ViewpointTest extends CoreModelTestCase
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$a1 = new Action(1); $a1 = new Action("30000000-0000-0000-0000-000000000001");
$a2 = new Action(2); $a2 = new Action("30000000-0000-0000-0000-000000000002");
$a3 = new Action(3); $a3 = new Action("30000000-0000-0000-0000-000000000003");
$ag1 = new ActionGroup('id1', 'title1', 42); $ag1 = new ActionGroup('id1', 'title1', 42);
$ag1->setActions([ $ag1->setActions([
@@ -152,7 +152,7 @@ class ViewpointTest extends CoreModelTestCase
]); ]);
$ag2 = new ActionGroup('id2', 'title2', 101); $ag2 = new ActionGroup('id2', 'title2', 101);
$ag2->setActions([ $ag2->setActions([
new Action(4) new Action("30000000-0000-0000-0000-000000000004")
]); ]);
$actionGroups = [ $actionGroups = [
@@ -160,16 +160,16 @@ class ViewpointTest extends CoreModelTestCase
$ag2 $ag2
]; ];
$input = $em->getRepository(Viewpoint::class)->find(2); $input = $em->getRepository(Viewpoint::class)->find("10000000-0000-0000-0000-000000000002");
$input->setActionGroups($actionGroups); $input->setActionGroups($actionGroups);
$input->save($em); $input->save($em);
$em->clear(); $em->clear();
$output = $em->getRepository(Viewpoint::class)->find(2); $output = $em->getRepository(Viewpoint::class)->find("10000000-0000-0000-0000-000000000002");
// Not finding the scene ID should change nothing. // Not finding the scene ID should change nothing.
$output->removeActionsWithSceneId(1000); $output->removeActionsWithSceneId("30000000-0000-0000-0000-000000001000");
$this->assertEquals($actionGroups, $output->getActionGroups()); $this->assertEquals($actionGroups, $output->getActionGroups());
$ag1_output = new ActionGroup('id1', 'title1', 42); $ag1_output = new ActionGroup('id1', 'title1', 42);
@@ -182,14 +182,14 @@ class ViewpointTest extends CoreModelTestCase
$ag1_output, $ag1_output,
$ag2 $ag2
]; ];
$output->removeActionsWithSceneId(2); $output->removeActionsWithSceneId("30000000-0000-0000-0000-000000000002");
$this->assertEquals($actionGroupsWithout2, $output->getActionGroups()); $this->assertEquals($actionGroupsWithout2, $output->getActionGroups());
} }
public function testChangingSceneDescription() public function testChangingSceneDescription()
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$testCharacter = $em->getRepository(Character::class)->find(2); $testCharacter = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$characterScene = $testCharacter->getViewpoint(); $characterScene = $testCharacter->getViewpoint();
$this->assertSame("This is the village.", $characterScene->getDescription()); $this->assertSame("This is the village.", $characterScene->getDescription());
@@ -201,7 +201,7 @@ class ViewpointTest extends CoreModelTestCase
public function testClearingSceneDescription() public function testClearingSceneDescription()
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$testCharacter = $em->getRepository(Character::class)->find(2); $testCharacter = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$characterScene = $testCharacter->getViewpoint(); $characterScene = $testCharacter->getViewpoint();
$characterScene->clearDescription(); $characterScene->clearDescription();
@@ -215,9 +215,9 @@ class ViewpointTest extends CoreModelTestCase
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$a1 = new Action(1); $a1 = new Action("30000000-0000-0000-0000-000000000001");
$a2 = new Action(2); $a2 = new Action("30000000-0000-0000-0000-000000000002");
$a3 = new Action(3); $a3 = new Action("30000000-0000-0000-0000-000000000003");
$ag1 = new ActionGroup('id1', 'title1', 42); $ag1 = new ActionGroup('id1', 'title1', 42);
$ag1->setActions([ $ag1->setActions([
@@ -227,7 +227,7 @@ class ViewpointTest extends CoreModelTestCase
]); ]);
$ag2 = new ActionGroup('id2', 'title2', 101); $ag2 = new ActionGroup('id2', 'title2', 101);
$ag2->setActions([ $ag2->setActions([
new Action(4) new Action("30000000-0000-0000-0000-000000000004")
]); ]);
$actionGroups = [ $actionGroups = [
@@ -235,14 +235,14 @@ class ViewpointTest extends CoreModelTestCase
$ag2 $ag2
]; ];
$input = $em->getRepository(Viewpoint::class)->find(2); $input = $em->getRepository(Viewpoint::class)->find("10000000-0000-0000-0000-000000000002");
$input->setActionGroups($actionGroups); $input->setActionGroups($actionGroups);
$input->save($em); $input->save($em);
$em->clear(); $em->clear();
/** @var Viewpoint $viewpoint */ /** @var Viewpoint $viewpoint */
$viewpoint = $em->getRepository(Viewpoint::class)->find(2); $viewpoint = $em->getRepository(Viewpoint::class)->find("10000000-0000-0000-0000-000000000002");
$actionGroupId1 = $viewpoint->findActionGroupById("id1"); $actionGroupId1 = $viewpoint->findActionGroupById("id1");
$actionGroupId2 = $viewpoint->findActionGroupById("id2"); $actionGroupId2 = $viewpoint->findActionGroupById("id2");
@@ -259,4 +259,18 @@ class ViewpointTest extends CoreModelTestCase
$this->assertNull($viewpoint->findActionById("anId")); $this->assertNull($viewpoint->findActionById("anId"));
} }
public function testIfViewpointCanGetRemovedAndDeleted()
{
$em = $this->getEntityManager();
$testCharacter = $em->getRepository(Character::class)->find("10000000-0000-0000-0000-000000000002");
$this->getEntityManager()->remove($testCharacter->getViewpoint());
$testCharacter->setViewpoint(null);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$viewpoint = $em->getRepository(Viewpoint::class)->findOneBy(["owner" => "10000000-0000-0000-0000-000000000002"]);
$this->assertNull($viewpoint, "Viewpoint is not null");
}
} }
+63 -5
View File
@@ -13,6 +13,7 @@ use LotGD\Core\EventHandler;
use LotGD\Core\EventManager; use LotGD\Core\EventManager;
use LotGD\Core\EventSubscription; use LotGD\Core\EventSubscription;
use LotGD\Core\LibraryConfiguration; use LotGD\Core\LibraryConfiguration;
use LotGD\Core\Models\Character;
use LotGD\Core\ModuleManager; use LotGD\Core\ModuleManager;
use LotGD\Core\Module; use LotGD\Core\Module;
use LotGD\Core\Exceptions\ModuleAlreadyExistsException; use LotGD\Core\Exceptions\ModuleAlreadyExistsException;
@@ -201,11 +202,53 @@ class ModuleManagerTest extends CoreModelTestCase
$this->assertEquals($name, $modules[1]->getLibrary()); $this->assertEquals($name, $modules[1]->getLibrary());
} }
public function testRegisterWithFailedEvents()
{
$class = FakeModule::class;
$name = 'lotgd/tests2';
$subscriptions = array(
'/pattern1/',
'#asasd/',
);
$library = $this->getMockBuilder(LibraryConfiguration::class)
->disableOriginalConstructor()
->getMock();
$library->method('getName')->willReturn($name);
$library->method('getRootNamespace')->willReturn('LotGD\\Core\\Tests\\FakeModule\\');
$library->method('getSubscriptionPatterns')->willReturn($subscriptions);
$eventManager = new EventManager($this->g);
$this->game->method('getEventManager')->willReturn($eventManager);
$eventsBefore = count($eventManager->getSubscriptions());
$subscriptionThrownException = false;
try {
$this->mm->register($library);
} catch(\Throwable $e) {
$subscriptionThrownException = true;
}
$this->assertTrue($subscriptionThrownException);
// Assert module has not been installed.
$modules = $this->mm->getModules();
$this->assertArrayNotHasKey(1, $modules);
// Assert events are not registered
$eventsAfter = count($eventManager->getSubscriptions());
// Randomly flush
$this->getEntityManager()->flush();
$this->assertSame($eventsBefore, $eventsAfter, "Events after failed subscription are actually more.");
}
public function testRegisteringDefectiveModule() public function testRegisteringDefectiveModule()
{ {
$class = DefectiveModule::class; $class = DefectiveModule::class;
$name = "lotgd/tests3"; $name = "lotgd/tests3";
$subscriptions = []; $subscriptions = ["#e/lotgd/core/tests/dat-event#"];
$library = $this->getMockBuilder(LibraryConfiguration::class) $library = $this->getMockBuilder(LibraryConfiguration::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@@ -213,11 +256,12 @@ class ModuleManagerTest extends CoreModelTestCase
$library->method('getRootNamespace')->willReturn('LotGD\\Core\\Tests\\DefectiveModule\\'); $library->method('getRootNamespace')->willReturn('LotGD\\Core\\Tests\\DefectiveModule\\');
$library->method('getSubscriptionPatterns')->willReturn($subscriptions); $library->method('getSubscriptionPatterns')->willReturn($subscriptions);
$eventManager = $this->getMockBuilder(EventManager::class) // Defective Module adds a character. Count the characters before.
->disableOriginalConstructor() $charactersBefore = count($this->getEntityManager()->getRepository(Character::class)->findAll());
->getMock();
$eventManager = new EventManager($this->g);
$this->game->method('getEventManager')->willReturn($eventManager); $this->game->method('getEventManager')->willReturn($eventManager);
$modulesBefore = $this->mm->getModules(); $modulesBefore = $this->mm->getModules();
try { try {
// onRegister throws an exception. This exception needs to be captured and handled by mm->register without actually // onRegister throws an exception. This exception needs to be captured and handled by mm->register without actually
@@ -229,7 +273,21 @@ class ModuleManagerTest extends CoreModelTestCase
} }
$modulesAfter = $this->mm->getModules(); $modulesAfter = $this->mm->getModules();
$this->assertFalse($exceptionCaptured); $this->assertTrue($exceptionCaptured);
$this->assertCount(count($modulesBefore), $modulesAfter); $this->assertCount(count($modulesBefore), $modulesAfter);
// Make sure there are no event leftovers.
$subscriptions_db = $eventManager->getSubscriptions();
$found = 0;
foreach($subscriptions_db as $subscription) {
if (in_array($subscription->getPattern(), $subscriptions)) {
$found++;
}
}
$this->assertSame(0, $found);
// Count characters. Must stay the same!
$charactersAfter = count($this->getEntityManager()->getRepository(Character::class)->findAll());
$this->assertSame($charactersBefore, $charactersAfter, "Modules flushed did not get not added to the database.");
} }
} }
+13 -13
View File
@@ -1,48 +1,48 @@
characters: characters:
- -
id: 1 id: "d363c077-234a-433d-834e-f1a1d3b281d8"
name: "Player" name: "Player"
displayName: "The Player" displayName: "The Player"
health: 100 health: 100
maxhealth: 100 maxhealth: 100
level: 10 level: 10
- -
id: 2 id: "4d01c29b-d825-4bc7-9e6e-63525155fd37"
name: "High Level Char" name: "High Level Char"
displayName: "High Level Char" displayName: "High Level Char"
health: 1000 health: 1000
maxhealth: 1000 maxhealth: 1000
level: 100 level: 100
- -
id: 3 id: "c3792b61-4e34-4710-9871-65a68ac30bb4"
name: "Low Level Char" name: "Low Level Char"
displayName: "Low Level Char" displayName: "Low Level Char"
health: 10 health: 10
maxhealth: 10 maxhealth: 10
level: 1 level: 1
- -
id: 4 id: "6565b418-55f5-4a6b-8d92-a9ef81329912"
name: "Low Damage Char" name: "Low Damage Char"
displayName: "Low Damage Char" displayName: "Low Damage Char"
health: 500 health: 500
maxhealth: 500 maxhealth: 500
level: 0 level: 0
- -
id: 10 id: "539e4bb0-84d1-49ed-a697-ff449991e9b7"
name: "Level 10 Character" name: "Level 10 Character"
displayName: "Level 10 Character" displayName: "Level 10 Character"
health: 100 health: 100
maxhealth: 100 maxhealth: 100
level: 10 level: 10
- -
id: 11 id: "24d71c26-f915-401c-8b3e-1932edf650ce"
name: "Level 11 Character" name: "Level 11 Character"
displayName: "Level 11 Character" displayName: "Level 11 Character"
health: 110 health: 110
maxhealth: 110 maxhealth: 110
level: 11 level: 11
- -
id: 13 id: "1a9f63f2-3006-4e12-b272-4fd6be518a93"
name: "Level 13 Character" name: "Level 13 Character"
displayName: "Level 13 Character" displayName: "Level 13 Character"
health: 130 health: 130
@@ -50,26 +50,26 @@ characters:
level: 13 level: 13
monsters: monsters:
- -
id: 1 id: "de84c507-9673-44e7-b665-9e43416b9c2f"
name: "Evil Monster" name: "Evil Monster"
level: 5 level: 5
- -
id: 2 id: "b636df29-f72d-4e2d-9850-982e783a9e94"
name: "High Dragon" name: "High Dragon"
level: 100 level: 100
- -
id: 3 id: "c004bcb6-a7c1-4f9a-abc2-1711c64e23a0"
name: "Stone" name: "Stone"
level: 1 level: 1
- -
id: 10 id: "f1d1f672-e308-420e-939f-cbb39285b222"
name: "Level 10 Monster" name: "Level 10 Monster"
level: 10 level: 10
- -
id: 11 id: "7ca9c141-aaf8-44a5-9d04-b6f9923f3c66"
name: "Level 11 Monster" name: "Level 11 Monster"
level: 11 level: 11
- -
id: 13 id: "09540b93-63c9-4d82-8501-f569f63dfc4c"
name: "Level 13 Monster" name: "Level 13 Monster"
level: 13 level: 13
+4 -4
View File
@@ -1,18 +1,18 @@
characters: characters:
- -
id: 1 id: "10000000-0000-0000-0000-000000000001"
name: "Testcharacter 1" name: "Testcharacter 1"
displayName: "Testcharacter 1" displayName: "Testcharacter 1"
health: 0 health: 0
maxhealth: 100 maxhealth: 100
- -
id: 2 id: "10000000-0000-0000-0000-000000000002"
name: "Testcharacter 2" name: "Testcharacter 2"
displayName: "Testcharacter 2" displayName: "Testcharacter 2"
health: 90 health: 90
maxhealth: 90 maxhealth: 90
- -
id: 3 id: "10000000-0000-0000-0000-000000000003"
name: "Testcharacter 3" name: "Testcharacter 3"
displayName: "Testcharacter 3 (deleted)" displayName: "Testcharacter 3 (deleted)"
health: 90 health: 90
@@ -20,6 +20,6 @@ characters:
deletedAt: "2011-11-11 11:11:11" deletedAt: "2011-11-11 11:11:11"
character_properties: character_properties:
- -
owner_id: 1 owner_id: "10000000-0000-0000-0000-000000000001"
propertyName: "test" propertyName: "test"
propertyValue: 's:5:"hallo";' propertyValue: 's:5:"hallo";'
+15
View File
@@ -0,0 +1,15 @@
characters:
-
id: "10000000-0000-0000-0000-000000000001"
name: "Testcharacter 1"
displayName: "Testcharacter 1"
level: 1
health: 13
maxhealth: 100
-
id: "10000000-0000-0000-0000-000000000002"
name: "Testcharacter 2"
displayName: "Testcharacter 2"
level: 2
health: 90
maxhealth: 90
+25 -25
View File
@@ -1,19 +1,19 @@
characters: characters:
- -
id: 1 id: "10000000-0000-0000-0000-000000000001"
name: "Char without a Scene" name: "Char without a Scene"
displayName: "A" displayName: "A"
- -
id: 2 id: "10000000-0000-0000-0000-000000000002"
name: "Char with a Scene" name: "Char with a Scene"
displayName: "B" displayName: "B"
- -
id: 3 id: "10000000-0000-0000-0000-000000000003"
name: "Char without a Scene" name: "Char without a Scene"
displayName: "C" displayName: "C"
viewpoints: viewpoints:
- -
owner_id: 2 owner_id: "10000000-0000-0000-0000-000000000002"
title: "The Village" title: "The Village"
description: "This is the village." description: "This is the village."
template: "lotgd/tests/village" template: "lotgd/tests/village"
@@ -22,74 +22,74 @@ viewpoints:
actionGroups: "a:0:{}" actionGroups: "a:0:{}"
scenes: scenes:
- -
id: 1 id: "30000000-0000-0000-0000-000000000001"
title: "The Village" title: "The Village"
description: "This is the village." description: "This is the village."
template: "lotgd/tests/village" template: "lotgd/tests/village"
- -
id: 2 id: "30000000-0000-0000-0000-000000000002"
title: "The Forest" title: "The Forest"
description: "This is a very dangerous and dark forest" description: "This is a very dangerous and dark forest"
template: "lotgd/tests/forest" template: "lotgd/tests/forest"
- -
id: 3 id: "30000000-0000-0000-0000-000000000003"
title: "The Weaponry" title: "The Weaponry"
description: "This is the place where you can buy awesome weapons" description: "This is the place where you can buy awesome weapons"
template: "lotgd/tests/weaponry" template: "lotgd/tests/weaponry"
- -
id: 4 id: "30000000-0000-0000-0000-000000000004"
title: "Parent Scene" title: "Parent Scene"
description: "This is a parent scene that connects to two children." description: "This is a parent scene that connects to two children."
template: "lotgd/tests/none" template: "lotgd/tests/none"
- -
id: 5 id: "30000000-0000-0000-0000-000000000005"
title: "Child Scene 1" title: "Child Scene 1"
description: "This is a parent scene that connects to two children." description: "This is a parent scene that connects to two children."
template: "lotgd/tests/none" template: "lotgd/tests/none"
- -
id: 6 id: "30000000-0000-0000-0000-000000000006"
title: "Child Scene 2" title: "Child Scene 2"
description: "This is a parent scene that connects to two children." description: "This is a parent scene that connects to two children."
template: "lotgd/tests/none" template: "lotgd/tests/none"
- -
id: 7 id: "30000000-0000-0000-0000-000000000007"
title: "Parameter test" title: "Parameter test"
description: "This is a parameter test" description: "This is a parameter test"
template: "lotgd/tests/paramaters" template: "lotgd/tests/paramaters"
scene_connection_groups: scene_connection_groups:
- -
scene: 4 scene: "30000000-0000-0000-0000-000000000004"
name: "lotgd/tests/none/child1" name: "lotgd/tests/none/child1"
title: "Child 1" title: "Child 1"
- -
scene: 4 scene: "30000000-0000-0000-0000-000000000004"
name: "lotgd/tests/none/child2" name: "lotgd/tests/none/child2"
title: "Child 2" title: "Child 2"
scene_connections: scene_connections:
- -
outgoingScene: 1 outgoingScene: "30000000-0000-0000-0000-000000000001"
incomingScene: 2 incomingScene: "30000000-0000-0000-0000-000000000002"
directionality: 0 directionality: 0
- -
outgoingScene: 1 outgoingScene: "30000000-0000-0000-0000-000000000001"
incomingScene: 3 incomingScene: "30000000-0000-0000-0000-000000000003"
directionality: 0 directionality: 0
- -
outgoingScene: 1 outgoingScene: "30000000-0000-0000-0000-000000000001"
incomingScene: 4 incomingScene: "30000000-0000-0000-0000-000000000004"
directionality: 0 directionality: 0
- -
outgoingScene: 4 outgoingScene: "30000000-0000-0000-0000-000000000004"
incomingScene: 5 incomingScene: "30000000-0000-0000-0000-000000000005"
outgoingConnectionGroupName: "lotgd/tests/none/child1" outgoingConnectionGroupName: "lotgd/tests/none/child1"
directionality: 0 directionality: 0
- -
outgoingScene: 4 outgoingScene: "30000000-0000-0000-0000-000000000004"
incomingScene: 6 incomingScene: "30000000-0000-0000-0000-000000000006"
outgoingConnectionGroupName: "lotgd/tests/none/child2" outgoingConnectionGroupName: "lotgd/tests/none/child2"
directionality: 0 directionality: 0
- -
outgoingScene: 5 outgoingScene: "30000000-0000-0000-0000-000000000005"
incomingScene: 6 incomingScene: "30000000-0000-0000-0000-000000000006"
directionality: 1 directionality: 1
+7 -7
View File
@@ -1,19 +1,19 @@
characters: characters:
- -
id: 1 id: "10000000-0000-0000-0000-000000000001"
name: "Testcharacter 1" name: "Testcharacter 1"
displayName: "Testcharacter 1" displayName: "Testcharacter 1"
- -
id: 2 id: "10000000-0000-0000-0000-000000000002"
name: "Testcharacter 2" name: "Testcharacter 2"
displayName: "Testcharacter 2" displayName: "Testcharacter 2"
- -
id: 3 id: "10000000-0000-0000-0000-000000000003"
name: "Testcharacter 1" name: "Testcharacter 1"
displayName: "Deleted Testcharacter" displayName: "Deleted Testcharacter"
deletedAt: "2011-11-11 11:11:11" deletedAt: "2011-11-11 11:11:11"
- -
id: 4 id: "10000000-0000-0000-0000-000000000004"
name: "Testcharacter 3" name: "Testcharacter 3"
displayName: "Testcharacter 3" displayName: "Testcharacter 3"
message_threads: message_threads:
@@ -23,7 +23,7 @@ message_threads:
messages: messages:
- -
id: 1 id: 1
author_id: 1 author_id: "10000000-0000-0000-0000-000000000001"
thread_id: 1 thread_id: 1
message: "Hi!" message: "Hi!"
createdAt: "2000-01-01 00:00:01" createdAt: "2000-01-01 00:00:01"
@@ -31,7 +31,7 @@ messages:
message_threads_x_characters: message_threads_x_characters:
- -
messagethread_id: 1 messagethread_id: 1
character_id: 1 character_id: "10000000-0000-0000-0000-000000000001"
- -
messagethread_id: 1 messagethread_id: 1
character_id: 2 character_id: "10000000-0000-0000-0000-000000000002"
+9 -9
View File
@@ -1,18 +1,18 @@
characters: characters:
- -
id: 1 id: "10000000-0000-0000-0000-000000000001"
name: "Testcharacter 1" name: "Testcharacter 1"
displayName: "Testcharacter 1" displayName: "Testcharacter 1"
health: 0 health: 0
maxhealth: 100 maxhealth: 100
- -
id: 2 id: "10000000-0000-0000-0000-000000000002"
name: "Testcharacter 2" name: "Testcharacter 2"
displayName: "Testcharacter 2" displayName: "Testcharacter 2"
health: 90 health: 90
maxhealth: 90 maxhealth: 90
- -
id: 3 id: "10000000-0000-0000-0000-000000000003"
name: "Testcharacter 1" name: "Testcharacter 1"
displayName: "Deleted Testcharacter" displayName: "Deleted Testcharacter"
health: 200 health: 200
@@ -20,22 +20,22 @@ characters:
deletedAt: "2011-11-11 11:11:11" deletedAt: "2011-11-11 11:11:11"
motd: motd:
- -
id: 1 id: "20000000-0000-0000-0000-000000000001"
author_id: 1 author_id: "10000000-0000-0000-0000-000000000001"
title: "This is the title" title: "This is the title"
body: "This is the body of the message" body: "This is the body of the message"
creationTime: "2016-05-03 14:19:12" creationTime: "2016-05-03 14:19:12"
systemMessage: false systemMessage: false
- -
id: 2 id: "20000000-0000-0000-0000-000000000002"
author_id: 1 author_id: "10000000-0000-0000-0000-000000000001"
title: "This is a system message" title: "This is a system message"
body: "This is the body of the system message" body: "This is the body of the system message"
creationTime: "2016-05-04 14:19:12" creationTime: "2016-05-04 14:19:12"
systemMessage: true systemMessage: true
- -
id: 3 id: "20000000-0000-0000-0000-000000000003"
author_id: 3 author_id: "10000000-0000-0000-0000-000000000003"
title: "This is an old message." title: "This is an old message."
body: "This is an old message." body: "This is an old message."
creationTime: "2002-12-09 15:13:59" creationTime: "2002-12-09 15:13:59"
+15 -15
View File
@@ -1,53 +1,53 @@
scenes: scenes:
- -
id: 1 id: "30000000-0000-0000-0000-000000000001"
title: "The Village" title: "The Village"
description: "This is the village." description: "This is the village."
template: "lotgd/tests/village" template: "lotgd/tests/village"
- -
id: 2 id: "30000000-0000-0000-0000-000000000002"
title: "The Forest" title: "The Forest"
description: "This is a very dangerous and dark forest" description: "This is a very dangerous and dark forest"
template: "lotgd/tests/forest" template: "lotgd/tests/forest"
- -
id: 3 id: "30000000-0000-0000-0000-000000000003"
title: "The Weaponry" title: "The Weaponry"
description: "This is the place where you can buy awesome weapons" description: "This is the place where you can buy awesome weapons"
template: "lotgd/tests/weaponry" template: "lotgd/tests/weaponry"
- -
id: 4 id: "30000000-0000-0000-0000-000000000004"
title: "Another Village" title: "Another Village"
description: "This is another village" description: "This is another village"
template: "lotgd/tests/village" template: "lotgd/tests/village"
- -
id: 5 id: "30000000-0000-0000-0000-000000000005"
title: "Orphan" title: "Orphan"
description: "This is an orphan scene" description: "This is an orphan scene"
template: "lotgd/tests/orphan" template: "lotgd/tests/orphan"
scene_connection_groups: scene_connection_groups:
- -
scene: 1 scene: "30000000-0000-0000-0000-000000000001"
name: "lotgd/tests/village/outside" name: "lotgd/tests/village/outside"
title: "Outside" title: "Outside"
- -
scene: 1 scene: "30000000-0000-0000-0000-000000000001"
name: "lotgd/tests/village/market" name: "lotgd/tests/village/market"
title: "Market" title: "Market"
- -
scene: 1 scene: "30000000-0000-0000-0000-000000000001"
name: "lotgd/tests/village/empty" name: "lotgd/tests/village/empty"
title: "Empty" title: "Empty"
- -
scene: 2 scene: "30000000-0000-0000-0000-000000000002"
name: "lotgd/tests/forest/category" name: "lotgd/tests/forest/category"
title: "Empty" title: "Empty"
scene_connections: scene_connections:
- -
outgoingScene: 1 outgoingScene: "30000000-0000-0000-0000-000000000001"
incomingScene: 2 incomingScene: "30000000-0000-0000-0000-000000000002"
- -
outgoingScene: 1 outgoingScene: "30000000-0000-0000-0000-000000000001"
incomingScene: 3 incomingScene: "30000000-0000-0000-0000-000000000003"
- -
outgoingScene: 1 outgoingScene: "30000000-0000-0000-0000-000000000001"
incomingScene: 4 incomingScene: "30000000-0000-0000-0000-000000000004"
+10 -10
View File
@@ -1,15 +1,15 @@
characters: characters:
- -
id: 1 id: "10000000-0000-0000-0000-000000000001"
name: "Char without a Scene" name: "Char without a Scene"
displayName: "A" displayName: "A"
- -
id: 2 id: "10000000-0000-0000-0000-000000000002"
name: "Char with a Scene" name: "Char with a Scene"
displayName: "B" displayName: "B"
viewpoints: viewpoints:
- -
owner_id: 2 owner_id: "10000000-0000-0000-0000-000000000002"
title: "The Village" title: "The Village"
description: "This is the village." description: "This is the village."
template: "lotgd/tests/village" template: "lotgd/tests/village"
@@ -18,24 +18,24 @@ viewpoints:
actionGroups: "a:0:{}" actionGroups: "a:0:{}"
scenes: scenes:
- -
id: 1 id: "30000000-0000-0000-0000-000000000001"
title: "The Village" title: "The Village"
description: "This is the village." description: "This is the village."
template: "lotgd/tests/village" template: "lotgd/tests/village"
- -
id: 2 id: "30000000-0000-0000-0000-000000000002"
title: "The Forest" title: "The Forest"
description: "This is a very dangerous and dark forest" description: "This is a very dangerous and dark forest"
template: "lotgd/tests/forest" template: "lotgd/tests/forest"
- -
id: 3 id: "30000000-0000-0000-0000-000000000003"
title: "The Weaponry" title: "The Weaponry"
description: "This is the place where you can buy awesome weapons" description: "This is the place where you can buy awesome weapons"
template: "lotgd/tests/weaponry" template: "lotgd/tests/weaponry"
scene_connections: scene_connections:
- -
outgoingScene: 1 outgoingScene: "30000000-0000-0000-0000-000000000001"
incomingScene: 2 incomingScene: "30000000-0000-0000-0000-000000000002"
- -
outgoingScene: 1 outgoingScene: "30000000-0000-0000-0000-000000000001"
incomingScene: 3 incomingScene: "30000000-0000-0000-0000-000000000003"