Skip to content

Commit

Permalink
Changed character id to uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
Vassyli committed Oct 8, 2018
1 parent 0aaba1b commit 04b3b6a
Show file tree
Hide file tree
Showing 20 changed files with 348 additions and 131 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"monolog/monolog": "^1.12",
"symfony/console": "^3.0",
"symfony/yaml": "^3.0",
"d11wtq/boris": "^1.0"
"d11wtq/boris": "^1.0",
"ramsey/uuid-doctrine": "^1.5"
},
"repositories": [
{
Expand Down
188 changes: 186 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\EventManager as DoctrineEventManager;
use Doctrine\Common\Util\Debug;
use Doctrine\DBAL\DBALException;
use Doctrine\ORM\Events as DoctrineEvents;
use Doctrine\ORM\ {
EntityManager,
Expand Down Expand Up @@ -173,6 +174,11 @@ protected function createEntityManager(\PDO $pdo): EntityManagerInterface
// Create entity manager
$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
$metaData = $entityManager->getMetadataFactory()->getAllMetadata();
$schemaTool = new SchemaTool($entityManager);
Expand Down
14 changes: 12 additions & 2 deletions src/Models/BasicEnemy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,36 @@
namespace LotGD\Core\Models;

use Doctrine\ORM\Mapping\MappedSuperclass;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

/**
* @MappedSuperclass
*/
abstract class BasicEnemy implements FighterInterface
{
/** @Id @Column(type="integer") @GeneratedValue */
/** @Id @Column(type="uuid", unique=True) */
protected $id;
/** @Column(type="string", length=50); */
protected $name;
/** @Column(type="integer"); */
protected $level;
/** @var int */
protected $health;

/**
* BasicEnemy constructor. Sets uuid upon creation.
* @throws \Exception
*/
public function __construct() {
$this->id = Uuid::uuid4();
}

/**
* Returns the enemy's id
* @return int
*/
public function getId(): int
public function getId(): UuidInterface
{
return $this->id;
}
Expand Down
8 changes: 6 additions & 2 deletions src/Models/Character.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use LotGD\Core\Tools\Model\{
Creator, ExtendableModel, GameAware, PropertyManager, SoftDeletable
};
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

/**
* Model for a character
Expand All @@ -32,7 +34,7 @@ class Character implements CharacterInterface, CreateableInterface, GameAwareInt
use GameAware;
use ExtendableModel;

/** @Id @Column(type="integer") @GeneratedValue */
/** @Id @Column(type="uuid", unique=True) */
private $id;
/** @Column(type="string", length=50); */
private $name;
Expand Down Expand Up @@ -90,6 +92,8 @@ public static function createAtFullHealth(array $arguments): self
*/
public function __construct()
{
$this->id = Uuid::uuid4();

$this->properties = new ArrayCollection();
$this->buffs = new ArrayCollection();
$this->messageThreads = new ArrayCollection();
Expand All @@ -99,7 +103,7 @@ public function __construct()
* Returns the entity's id
* @return int The id
*/
public function getId(): int
public function getId(): UuidInterface
{
return $this->id;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Models/CharacterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

namespace LotGD\Core\Models;

use Ramsey\Uuid\UuidInterface;

/**
* Interface for the character model and all objects that mimick such a model.
*/
interface CharacterInterface extends FighterInterface
{
public function getId(): int;
public function getId(): UuidInterface;
public function getName(): string;
public function getDisplayName(): string;
public function getHealth(): int;
Expand Down
3 changes: 2 additions & 1 deletion src/Tools/Model/MockCharacter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
};
use LotGD\Core\Exceptions\IsNullException;
use LotGD\Core\Models\Viewpoint;
use Ramsey\Uuid\UuidInterface;

/**
* Provides basic implementation to mock CharacterInterface.
Expand All @@ -21,7 +22,7 @@ public function __call($name, $arguments)
throw new IsNullException();
}

public function getId(): int
public function getId(): UuidInterface
{
throw new IsNullException();
}
Expand Down
Loading

0 comments on commit 04b3b6a

Please sign in to comment.