Basic CharacterScene model

Moved basic Scene data to SceneBasics, created CharacterScene and a
getter for the Character model.
This commit is contained in:
Basilius Sauter
2016-04-21 07:32:57 +02:00
parent 9986420b10
commit 7590247f89
4 changed files with 120 additions and 43 deletions
+15 -3
View File
@@ -34,9 +34,8 @@ class Character
private $health = 10;
/** @OneToMany(targetEntity="CharacterProperty", mappedBy="owner", cascade={"persist"}) */
private $properties;
/** @var string fqcn of the property sub class */
private static $propertyClass = CharacterProperty::class;
/** @OneToOne(targetEntity="CharacterScene", mappedBy="owner", cascade={"persist"}) */
private $characterScene;
/** @var array */
private static $fillable = [
@@ -139,4 +138,17 @@ class Character
{
return $this->health;
}
/**
* Returns the current character scene and creates one if it is non-existant
* @return \LotGD\Core\Models\CharacterScene
*/
public function getCharacterScene(): CharacterScene
{
if ($this->characterScene === null) {
$this->characterScene = CharacterScene::create(["owner" => $this]);
}
return $this->characterScene;
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace LotGD\Core\Models;
use LotGD\Core\Tools\Model\Creator;
use LotGD\Core\Tools\Model\SceneBasics;
/**
* A CharacterScene is the current Scene a character is experiencing with
* all changes from modules included.
* @Entity
* @Table(name="character_scene")
*/
class CharacterScene {
use Creator;
use SceneBasics;
/** @Id @OneToOne(targetEntity="Character") */
private $owner;
/** @var array */
private static $fillable = [
"owner"
];
/**
* Returns the owner
* @return \LotGD\Core\Models\Character
*/
public function getOwner(): Character
{
return $this->owner;
}
/**
* Sets the owner
* @param \LotGD\Core\Models\Character $owner
*/
public function setOwner(Character $owner)
{
$this->owner = $owner;
}
/**
* Copies the static data from a scene to a characterScene entity
* @param \LotGD\Core\Models\Scene $scene
*/
public function changeFromScene(Scene $scene) {
$this->setTitle($scene->getTitle());
$this->setDescription($scene->getDescription());
}
}
+2 -40
View File
@@ -10,6 +10,7 @@ use LotGD\Core\Exceptions\NoParentSetException;
use LotGD\Core\Exceptions\WrongParentException;
use LotGD\Core\Tools\Model\Creator;
use LotGD\Core\Tools\Model\Deletor;
use LotGD\Core\Tools\Model\SceneBasics;
/**
* Description of Scene
@@ -20,13 +21,10 @@ class Scene
{
use Creator;
use Deletor;
use SceneBasics;
/** @Id @Column(type="integer") @GeneratedValue */
private $id;
/** @Column(type="string", length=255) */
private $title = "";
/** @Column(type="text") */
private $description = "";
/**
* @ManyToOne(targetEntity="Scene")
@@ -65,42 +63,6 @@ class Scene
return $this->id;
}
/**
* Sets scene title
* @param string $title
*/
public function setTitle(string $title)
{
$this->title = $title;
}
/**
* Returns scene title
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* Sets scene description
* @param string $description
*/
public function setDescription(string $description)
{
$this->description = $description;
}
/**
* Returns scene description
* @return string
*/
public function getDescription(): string
{
return $this->description;
}
/**
* Sets or removes the parent of this scene.
* @param \LotGD\Core\Models\Scene $parent The new parent or NULL
+51
View File
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Tools\Model;
/**
* Provides scene basics
*/
trait SceneBasics
{
/** @Column(type="string", length=255) */
private $title = "";
/** @Column(type="text") */
private $description = "";
/**
* Sets scene title
* @param string $title
*/
public function setTitle(string $title)
{
$this->title = $title;
}
/**
* Returns scene title
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* Sets scene description
* @param string $description
*/
public function setDescription(string $description)
{
$this->description = $description;
}
/**
* Returns scene description
* @return string
*/
public function getDescription(): string
{
return $this->description;
}
}