-
Notifications
You must be signed in to change notification settings - Fork 3
/
SpriteFrame.php
45 lines (36 loc) · 1.08 KB
/
SpriteFrame.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Trojal\PhpRo;
use Trojal\PhpRo\DataReader;
class SpriteFrame
{
public function __construct($header, DataReader $dataReader)
{
$this->header = $header;
$this->dataReader = $dataReader;
}
public function requireData()
{
if (isset($this->data))
return $this;
$data = $this
->dataReader
->seek($this->header['offset'])
->read($this->header['frameLength']);
$frameData = null;
if ($this->header['type'] == PHPRO_FRAME_TYPE_PALETTE) {
while ($data) {
if (ord($data[0]) == 0 && $this->header['version'] != 0) {
$data = substr($data, 1);
$frameData .= str_repeat(chr(0), ord($data[0]));
} else {
$frameData .= $data[0];
}
$data = substr($data, 1);
}
} else if ($this->header['type'] == PHPRO_FRAME_TYPE_RGBA) {
$frameData = $data;
}
$this->data = $frameData;
return $this;
}
}