56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace swf2ass;
|
|
|
|
class SpriteDefinition implements MultiFrameObjectDefinition {
|
|
public int $id;
|
|
/** @var ViewFrame[] */
|
|
public array $frames;
|
|
|
|
public int $frameCounter;
|
|
public bool $hasFrames = true;
|
|
|
|
/**
|
|
* @param int $id
|
|
* @param ViewFrame[] $frames
|
|
*/
|
|
public function __construct(int $id, array $frames, int $frameCounter = 0) {
|
|
$this->id = $id;
|
|
$this->frames = $frames;
|
|
$this->frameCounter = $frameCounter % count($this->frames);
|
|
}
|
|
|
|
public function getObjectId(): int {
|
|
return $this->id;
|
|
}
|
|
|
|
public function getShapeList(): DrawPathList {
|
|
$list = new DrawPathList();
|
|
foreach ($this->frames[$this->frameCounter]->render(0, [], ColorTransform::identity(), MatrixTransform::identity())->getObjects() as $object) {
|
|
$list = $list->merge($object->drawPathList);
|
|
}
|
|
return $list;
|
|
}
|
|
|
|
public function hasFrame(): bool {
|
|
return $this->hasFrames;
|
|
}
|
|
|
|
public function getFrameCounter(): int {
|
|
return $this->frameCounter;
|
|
}
|
|
|
|
public function getFrame(int $frameNumber): ?ViewFrame {
|
|
return $this->frames[$frameNumber] ?? null;
|
|
}
|
|
|
|
public function nextFrame(): ViewFrame {
|
|
$f = $this->frames[$this->frameCounter];
|
|
++$this->frameCounter;
|
|
if ($this->frameCounter >= count($this->frames)) {
|
|
$this->frameCounter = count($this->frames) - 1;
|
|
$this->hasFrames = false; //TODO LOOP
|
|
}
|
|
return $f;
|
|
}
|
|
} |