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.
This commit is contained in:
Vassyli
2017-03-18 16:05:16 +01:00
parent 03fc114775
commit af98ab0f36
2 changed files with 131 additions and 1 deletions
+33 -1
View File
@@ -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
+98
View File
@@ -0,0 +1,98 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Models;
/**
* Represents a complete set of viewpoint data used to restore a saved viewpoint.
* @package LotGD\Core\Models
*/
class ViewpointRestorationPoint
{
private $title;
private $description;
private $template;
private $actionGroups;
private $attachements;
private $data;
/**
* ViewpointRestorationPoint constructor.
* @param string $title
* @param string $description
* @param string $template
* @param array $actionGroups
* @param array $attachements
* @param array $data
*/
public function __construct(
string $title,
string $description,
string $template,
array $actionGroups,
array $attachements,
array $data
)
{
$this->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;
}
}