Fixes #164 by introducing a PostLoad lifecycle callback for the viewpoint entity.

This commit is contained in:
Vassyli
2021-04-13 19:05:30 +02:00
parent e2455be738
commit b1942e675a
3 changed files with 17 additions and 1 deletions
+2 -1
View File
@@ -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;
}
+13
View File
@@ -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
+2
View File
@@ -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());