From af98ab0f36499fb7482e3606c76c04abef688b9f Mon Sep 17 00:00:00 2001 From: Vassyli Date: Sat, 18 Mar 2017 16:05:16 +0100 Subject: [PATCH] Added viewpoint restoration points Added an API for model viewpoint to create a restoration point that can be saved. Changing the scene from the restoration point can replay a scene without doing the calculations done to render it. --- src/Models/Viewpoint.php | 34 +++++++- src/Models/ViewpointRestorationPoint.php | 98 ++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 src/Models/ViewpointRestorationPoint.php diff --git a/src/Models/Viewpoint.php b/src/Models/Viewpoint.php index b80e9fc..1f53b42 100644 --- a/src/Models/Viewpoint.php +++ b/src/Models/Viewpoint.php @@ -56,7 +56,7 @@ class Viewpoint implements CreateableInterface } /** - * Copies the static data from a scene to this Viewpoint entity + * Copies the static data from a scene to this Viewpoint entity. * @param \LotGD\Core\Models\Scene $scene */ public function changeFromScene(Scene $scene) @@ -71,6 +71,38 @@ class Viewpoint implements CreateableInterface $this->setData([]); } + /** + * Returns a restoration point that can be used to reconstruct the current viewpoint. + * @return ViewpointRestorationPoint + */ + public function getRestorationPoint(): ViewpointRestorationPoint + { + $restoration = new ViewpointRestorationPoint( + $this->getTitle(), + $this->getDescription(), + $this->getTemplate(), + $this->getActionGroups(), + $this->getAttachments(), + $this->getData() + ); + + return $restoration; + } + + /** + * Changes the current viewpoint to the state saved in the given restoration point. + * @param ViewpointRestorationPoint $restoration + */ + public function changeFromRestorationPoint(ViewpointRestorationPoint $restoration) + { + $this->setTitle($restoration->getTitle()); + $this->setDescription($restoration->getDescription()); + $this->setTemplate($restoration->getTemplate()); + $this->getActionGroups($restoration->getActionGroups()); + $this->setAttachments($restoration->getAttachments()); + $this->setData($restoration->getData()); + } + /** * Sets the template scene used to create this viewpoint. * @param Scene $scene diff --git a/src/Models/ViewpointRestorationPoint.php b/src/Models/ViewpointRestorationPoint.php new file mode 100644 index 0000000..57eb59a --- /dev/null +++ b/src/Models/ViewpointRestorationPoint.php @@ -0,0 +1,98 @@ +title = $title; + $this->description = $description; + $this->template = $template; + $this->actionGroups = $actionGroups; + $this->attachements = $attachements; + $this->data = $data; + } + + /** + * Title of the viewpoint. + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * Description of the viewpoint. + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * Template of the viewpoint. + * @return string + */ + public function getTemplate(): string + { + return $this->template; + } + + /** + * Action groups of the viewpoint. + * @return array + */ + public function getActionGroups(): array + { + return $this->actionGroups; + } + + /** + * Attachements of the viewpoint. + * @return array + */ + public function getAttachements(): array + { + return $this->attachements; + } + + /** + * Date of the viewpoint. + * @return array + */ + public function getData(): array + { + return $this->data; + } +} \ No newline at end of file