Fixes #164 by introducing a PostLoad lifecycle callback for the viewpoint entity.
This commit is contained in:
+2
-1
@@ -249,7 +249,6 @@ class Game
|
||||
public function getViewpoint(): Viewpoint
|
||||
{
|
||||
$v = $this->getCharacter()->getViewpoint();
|
||||
$v->setTwigSceneRenderer($this->getSceneRenderer());
|
||||
|
||||
if ($v === null) {
|
||||
// No viewpoint set up for this user. Run the hook to find the default
|
||||
@@ -274,6 +273,8 @@ class Game
|
||||
$v->save($this->getEntityManager());
|
||||
}
|
||||
|
||||
$v->setTwigSceneRenderer($this->getSceneRenderer());
|
||||
|
||||
return $v;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ use Doctrine\ORM\Mapping\JoinColumn;
|
||||
use Doctrine\ORM\Mapping\ManyToOne;
|
||||
use Doctrine\ORM\Mapping\OneToOne;
|
||||
use Doctrine\ORM\Mapping\Table;
|
||||
use Doctrine\ORM\Mapping\PostLoad;
|
||||
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
|
||||
|
||||
use LotGD\Core\Action;
|
||||
use LotGD\Core\ActionGroup;
|
||||
@@ -28,6 +30,7 @@ use LotGD\Core\Tools\SceneDescription;
|
||||
* all changes from modules included.
|
||||
* @Entity
|
||||
* @Table(name="viewpoints")
|
||||
* @HasLifecycleCallbacks
|
||||
*/
|
||||
class Viewpoint implements CreateableInterface
|
||||
{
|
||||
@@ -69,6 +72,16 @@ class Viewpoint implements CreateableInterface
|
||||
"owner",
|
||||
];
|
||||
|
||||
/**
|
||||
* @PostLoad
|
||||
*/
|
||||
public function onLoad()
|
||||
{
|
||||
foreach ($this->actionGroups as $actionGroup) {
|
||||
$actionGroup->setViewpoint($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the owner.
|
||||
* @return Character
|
||||
|
||||
@@ -126,6 +126,8 @@ class ViewpointTest extends CoreModelTestCase
|
||||
$this->assertSame($should->getTitle(), $is->getTitle());
|
||||
$this->assertSame($should->getSortKey(), $is->getSortKey());
|
||||
$this->assertSame(count($should->getActions()), count($is->getActions()));
|
||||
|
||||
$this->assertSame($output, $is->getViewpoint());
|
||||
}
|
||||
|
||||
$this->assertEquals($ag2->getTitle(), $input->findActionGroupById('id2')->getTitle());
|
||||
|
||||
Reference in New Issue
Block a user