swf2ass/src/SpriteDefinition.php

40 lines
1.2 KiB
PHP

<?php
namespace swf2ass;
class SpriteDefinition implements MultiFrameObjectDefinition {
public int $id;
private SWFTreeProcessor $swf;
private ?ViewFrame $currentFrame = null;
public function __construct(int $id, SWFTreeProcessor $swf) {
$this->id = $id;
$this->swf = $swf;
}
public function getObjectId(): int {
return $this->id;
}
public function getShapeList(?float $ratio): DrawPathList {
$list = new DrawPathList();
if($this->currentFrame !== null){
foreach ($this->currentFrame->render(0, [], null, null)->getObjects() as $object) {
$list = $list->merge($object->drawPathList);
}
}
return $list;
}
public function nextFrame(): ViewFrame {
//TODO: figure out why this can return null. missing shapes?
return $this->currentFrame = $this->swf->nextFrame() ?? new ViewFrame($this->getObjectId(), new DrawPathList());
}
public function getSafeObject() : SpriteDefinition{
return new SpriteDefinition($this->id, new SWFTreeProcessor($this->id, $this->swf->getTags(), $this->swf->getObjectCollection()));
}
}