From b1942e675ad1a69c640085412ad33802e29d229b Mon Sep 17 00:00:00 2001 From: Vassyli Date: Tue, 13 Apr 2021 19:05:30 +0200 Subject: [PATCH] Fixes #164 by introducing a PostLoad lifecycle callback for the viewpoint entity. --- src/Game.php | 3 ++- src/Models/Viewpoint.php | 13 +++++++++++++ tests/Models/ViewpointTest.php | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Game.php b/src/Game.php index 0dcc6b3..c269f79 100644 --- a/src/Game.php +++ b/src/Game.php @@ -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; } diff --git a/src/Models/Viewpoint.php b/src/Models/Viewpoint.php index 80a94ba..5511f2c 100644 --- a/src/Models/Viewpoint.php +++ b/src/Models/Viewpoint.php @@ -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 diff --git a/tests/Models/ViewpointTest.php b/tests/Models/ViewpointTest.php index 642fe20..73150c7 100644 --- a/tests/Models/ViewpointTest.php +++ b/tests/Models/ViewpointTest.php @@ -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());