136 lines
3.8 KiB
PHP
136 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace swf2ass;
|
|
|
|
|
|
use swf2ass\actions\ActionList;
|
|
|
|
class ViewLayout {
|
|
private ?ViewLayout $parent;
|
|
|
|
/** @var ViewLayout[] */
|
|
private array $depthMap = [];
|
|
|
|
private ?ObjectDefinition $object;
|
|
|
|
private ?ColorTransform $colorTransform = null;
|
|
private ?MatrixTransform $matrixTransform = null;
|
|
|
|
private int $objectId;
|
|
|
|
private ?float $ratio = null;
|
|
|
|
public function __construct(int $objectId, ?ObjectDefinition $object, ?ViewLayout $parent = null) {
|
|
$this->objectId = $objectId;
|
|
if ($object !== null and $objectId !== $object->getObjectId()) {
|
|
throw new \LogicException();
|
|
}
|
|
$this->parent = $parent;
|
|
$this->object = $object;
|
|
}
|
|
|
|
public function getObjectId(): int {
|
|
return $this->object !== null ? $this->object->getObjectId() : -1;
|
|
}
|
|
|
|
public function getObject(): ?ObjectDefinition {
|
|
return $this->object;
|
|
}
|
|
|
|
/**
|
|
* @return ViewLayout[]
|
|
*/
|
|
public function getDepthMap(): array {
|
|
return $this->depthMap;
|
|
}
|
|
|
|
public function get(int $depth): ?ViewLayout {
|
|
return $this->depthMap[$depth] ?? null;
|
|
}
|
|
|
|
public function place(int $depth, ViewLayout $ob) {
|
|
if ($this->object !== null) {
|
|
throw new \LogicException("Cannot have ObjectDefinition and children at the same time");
|
|
}
|
|
if (isset($this->depthMap[$depth]) and $this->depthMap[$depth] !== $ob) {
|
|
throw new \Exception("Depth $depth already exists: tried replacing object " . $this->depthMap[$depth]->getObjectId() . " with " . $ob->getObjectId());
|
|
}
|
|
$this->depthMap[$depth] = $ob;
|
|
}
|
|
|
|
public function replace(int $depth, ViewLayout $ob) {
|
|
if ($this->object !== null) {
|
|
throw new \LogicException("Cannot have ObjectDefinition and children at the same time");
|
|
}
|
|
$oldObject = $this->get($depth);
|
|
if ($oldObject !== null) {
|
|
$ob->colorTransform = $ob->colorTransform ?? $oldObject->colorTransform;
|
|
$ob->matrixTransform = $ob->matrixTransform ?? $oldObject->matrixTransform;
|
|
}
|
|
$this->depthMap[$depth] = $ob;
|
|
}
|
|
|
|
public function remove(int $depth) {
|
|
unset($this->depthMap[$depth]);
|
|
}
|
|
|
|
public function hasFrame(): bool {
|
|
foreach ($this->depthMap as $ob) {
|
|
if ($ob->hasFrame()) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
//TODO
|
|
|
|
return false;
|
|
}
|
|
|
|
public function getMatrixTransform(): ?MatrixTransform {
|
|
return $this->matrixTransform;
|
|
}
|
|
|
|
public function getColorTransform(): ?ColorTransform {
|
|
return $this->colorTransform;
|
|
}
|
|
|
|
public function setMatrixTransform(?MatrixTransform $transform) {
|
|
$this->matrixTransform = $transform;
|
|
}
|
|
|
|
public function setColorTransform(?ColorTransform $transform) {
|
|
$this->colorTransform = $transform;
|
|
}
|
|
|
|
public function getRatio() : ?float{
|
|
return $this->ratio;
|
|
}
|
|
|
|
public function setRatio(?float $ratio){
|
|
$this->ratio = $ratio;
|
|
}
|
|
|
|
public function nextFrame(ActionList $actionList): ViewFrame {
|
|
if ($this->object !== null) {
|
|
if ($this->object instanceof MultiFrameObjectDefinition) {
|
|
$frame = $this->object->nextFrame();
|
|
} else {
|
|
$frame = new ViewFrame($this->getObjectId(), $this->object->getShapeList($this->ratio));
|
|
}
|
|
} else {
|
|
$frame = new ViewFrame($this->getObjectId(), null);
|
|
|
|
ksort($this->depthMap);
|
|
|
|
foreach ($this->depthMap as $depth => $child) {
|
|
$f = $child->nextFrame($actionList);
|
|
$frame->addChild($depth, $f);
|
|
}
|
|
}
|
|
|
|
$frame->setColorTransform($this->colorTransform);
|
|
$frame->setMatrixTransform($this->matrixTransform);
|
|
|
|
return $frame;
|
|
}
|
|
} |