@@ -89,8 +89,7 @@ |
||
| 89 | 89 | $red = ($pixel & 0xF800) >> 8; |
| 90 | 90 | $green = ($pixel & 0x07E0) >> 3; |
| 91 | 91 | $blue = ($pixel & 0x001F) << 3; |
| 92 | - } |
|
| 93 | - else if ($this->encoding == "555") |
|
| 92 | + } else if ($this->encoding == "555") |
|
| 94 | 93 | { |
| 95 | 94 | $red = ($pixel & 0x7C00) >> 7; |
| 96 | 95 | $green = ($pixel & 0x03E0) >> 2; |
@@ -75,10 +75,11 @@ discard block |
||
| 75 | 75 | for ($x = 0; $x < $this->GetWidth();) |
| 76 | 76 | { |
| 77 | 77 | $run = $this->reader->ReadInt(2); |
| 78 | - if (($run & 0x0001) > 0) |
|
| 79 | - $run_type = "colour"; |
|
| 80 | - else |
|
| 81 | - $run_type = "black"; |
|
| 78 | + if (($run & 0x0001) > 0) { |
|
| 79 | + $run_type = "colour"; |
|
| 80 | + } else { |
|
| 81 | + $run_type = "black"; |
|
| 82 | + } |
|
| 82 | 83 | $run_length = ($run & 0x7FFF) >> 1; |
| 83 | 84 | if ($run_type == "black") |
| 84 | 85 | { |
@@ -98,8 +99,7 @@ discard block |
||
| 98 | 99 | $red = ($pixel & 0xF800) >> 8; |
| 99 | 100 | $green = ($pixel & 0x07E0) >> 3; |
| 100 | 101 | $blue = ($pixel & 0x001F) << 3; |
| 101 | - } |
|
| 102 | - else if ($this->encoding == "555") |
|
| 102 | + } else if ($this->encoding == "555") |
|
| 103 | 103 | { |
| 104 | 104 | $red = ($pixel & 0x7C00) >> 7; |
| 105 | 105 | $green = ($pixel & 0x03E0) >> 2; |
@@ -109,8 +109,9 @@ discard block |
||
| 109 | 109 | imagesetpixel($image, $x, $y, $colour); |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | - if ($x == $this->GetWidth()) |
|
| 113 | - $this->reader->Skip(2); |
|
| 112 | + if ($x == $this->GetWidth()) { |
|
| 113 | + $this->reader->Skip(2); |
|
| 114 | + } |
|
| 114 | 115 | } |
| 115 | 116 | } |
| 116 | 117 | $this->gdImage = $image; |
@@ -3,113 +3,113 @@ |
||
| 3 | 3 | /// @brief Superclass for all SpriteFile types |
| 4 | 4 | abstract class SpriteFile { |
| 5 | 5 | |
| 6 | - /// @cond INTERNAL_DOCS |
|
| 6 | + /// @cond INTERNAL_DOCS |
|
| 7 | 7 | |
| 8 | - private $frames = array(); |
|
| 9 | - private $spritefiletype; |
|
| 10 | - /// @endcond |
|
| 8 | + private $frames = array(); |
|
| 9 | + private $spritefiletype; |
|
| 10 | + /// @endcond |
|
| 11 | 11 | |
| 12 | - /// @cond INTERNAL_DOCS |
|
| 12 | + /// @cond INTERNAL_DOCS |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @param string $filetype |
|
| 16 | - */ |
|
| 17 | - public function SpriteFile($filetype) { |
|
| 14 | + /** |
|
| 15 | + * @param string $filetype |
|
| 16 | + */ |
|
| 17 | + public function SpriteFile($filetype) { |
|
| 18 | 18 | $this->spritefiletype = $filetype; |
| 19 | - } |
|
| 20 | - /// @endcond |
|
| 19 | + } |
|
| 20 | + /// @endcond |
|
| 21 | 21 | |
| 22 | - /// @brief Gets a SpriteFrame from the SpriteFile. |
|
| 23 | - /** |
|
| 24 | - * @param $frame The 0-based index of the frame to get. |
|
| 25 | - * @return A SpriteFrame |
|
| 26 | - */ |
|
| 27 | - public function GetFrame($frame) { |
|
| 28 | - return $this->frames[$frame]; |
|
| 29 | - } |
|
| 30 | - /// @brief Gets the entire frame array. |
|
| 31 | - /** |
|
| 32 | - * @return An array of SpriteFrames |
|
| 33 | - */ |
|
| 34 | - public function GetFrames() { |
|
| 35 | - return $this->frames; |
|
| 36 | - } |
|
| 22 | + /// @brief Gets a SpriteFrame from the SpriteFile. |
|
| 23 | + /** |
|
| 24 | + * @param $frame The 0-based index of the frame to get. |
|
| 25 | + * @return A SpriteFrame |
|
| 26 | + */ |
|
| 27 | + public function GetFrame($frame) { |
|
| 28 | + return $this->frames[$frame]; |
|
| 29 | + } |
|
| 30 | + /// @brief Gets the entire frame array. |
|
| 31 | + /** |
|
| 32 | + * @return An array of SpriteFrames |
|
| 33 | + */ |
|
| 34 | + public function GetFrames() { |
|
| 35 | + return $this->frames; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /// @brief Compiles the SpriteFile into a binary string |
|
| 39 | - /** |
|
| 40 | - * @return A binary string containing the SpriteFile's data and frames. |
|
| 41 | - */ |
|
| 42 | - public abstract function Compile(); |
|
| 38 | + /// @brief Compiles the SpriteFile into a binary string |
|
| 39 | + /** |
|
| 40 | + * @return A binary string containing the SpriteFile's data and frames. |
|
| 41 | + */ |
|
| 42 | + public abstract function Compile(); |
|
| 43 | 43 | |
| 44 | - /// @brief Adds a SpriteFrame to the SpriteFile |
|
| 45 | - /** |
|
| 46 | - * If necessary, this function converts the SpriteFrame to the |
|
| 47 | - * correct format. |
|
| 48 | - * At the moment, this can only add a SpriteFrame to the end of the |
|
| 49 | - * SpriteFile. TODO: I aim to fix this by the CCSF 2011. |
|
| 50 | - * @internal |
|
| 51 | - * This process uses some magic which require all types of |
|
| 52 | - * SpriteFile and SpriteFrame to use 3-character identifiers. |
|
| 53 | - * This means that if you want to make your own sprite formats |
|
| 54 | - * you'll need to override this function and provide all our magic |
|
| 55 | - * plus your own. |
|
| 56 | - * @endinternal |
|
| 57 | - * @param $frame A SpriteFrame |
|
| 58 | - * @param $position Where to put the frame. Currently un-used. |
|
| 59 | - */ |
|
| 60 | - public function AddFrame(SpriteFrame $frame, $position = false) { |
|
| 61 | - /* |
|
| 44 | + /// @brief Adds a SpriteFrame to the SpriteFile |
|
| 45 | + /** |
|
| 46 | + * If necessary, this function converts the SpriteFrame to the |
|
| 47 | + * correct format. |
|
| 48 | + * At the moment, this can only add a SpriteFrame to the end of the |
|
| 49 | + * SpriteFile. TODO: I aim to fix this by the CCSF 2011. |
|
| 50 | + * @internal |
|
| 51 | + * This process uses some magic which require all types of |
|
| 52 | + * SpriteFile and SpriteFrame to use 3-character identifiers. |
|
| 53 | + * This means that if you want to make your own sprite formats |
|
| 54 | + * you'll need to override this function and provide all our magic |
|
| 55 | + * plus your own. |
|
| 56 | + * @endinternal |
|
| 57 | + * @param $frame A SpriteFrame |
|
| 58 | + * @param $position Where to put the frame. Currently un-used. |
|
| 59 | + */ |
|
| 60 | + public function AddFrame(SpriteFrame $frame, $position = false) { |
|
| 61 | + /* |
|
| 62 | 62 | if($position === false) { |
| 63 | 63 | $position = sizeof($this->frames); |
| 64 | 64 | } else if($position < 0) { |
| 65 | 65 | $position = sizeof($this->frames) - $position; |
| 66 | 66 | } |
| 67 | 67 | */ |
| 68 | - if ($this->spritefiletype == substr(get_class($frame), 0, 3)) { |
|
| 69 | - //$this->frames[$position] = $frame; |
|
| 70 | - $this->frames[] = $frame; |
|
| 71 | - } else { |
|
| 72 | - //$this->frames[$position] = $frame->ToSpriteFrame($this->spritefiletype); |
|
| 73 | - $this->frames[] = $frame->ToSpriteFrame($this->spritefiletype); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - /// @brief Replaces a frame in the SpriteFile |
|
| 77 | - /** |
|
| 78 | - * Replaces the frame in the given position |
|
| 79 | - * Uses the same magic as AddFrame |
|
| 80 | - * @param $frame A SpriteFrame of any type. |
|
| 81 | - * @param $position Which frame to replace. If negative, counts |
|
| 82 | - * backwards from the end of the frames array. |
|
| 83 | - */ |
|
| 84 | - public function ReplaceFrame(SpriteFrame $frame, $position) { |
|
| 85 | - if ($position < 0) { |
|
| 86 | - $position = sizeof($this->frames)-$position; |
|
| 87 | - } |
|
| 88 | - $this->frames[$position] = $frame->ToSpriteFrame($this->spritefiletype); |
|
| 89 | - } |
|
| 90 | - /// @brief Gets the number of frames currently stored in this SpriteFile. |
|
| 91 | - /** |
|
| 92 | - * @return The number of frames |
|
| 93 | - */ |
|
| 94 | - public function GetFrameCount() { |
|
| 95 | - return sizeof($this->frames); |
|
| 96 | - } |
|
| 97 | - /// @brief Deletes the frame in the given position. |
|
| 98 | - /** |
|
| 99 | - * @param $frame The 0-based index of the frame to delete. |
|
| 100 | - */ |
|
| 101 | - public function DeleteFrame($frame) { |
|
| 102 | - unset($this->frames[$frame]); |
|
| 103 | - } |
|
| 104 | - /// @brief Converts the given frame to PNG. <strong>Deprecated.</strong> |
|
| 105 | - /** |
|
| 106 | - * May be removed in a future release. |
|
| 107 | - * Use GetFrame($frame)->ToPNG() instead. |
|
| 108 | - * @param integer $frame The 0-based index of the frame to delete. |
|
| 109 | - * @return A binary string containing a PNG. |
|
| 110 | - */ |
|
| 111 | - public function ToPNG($frame) { |
|
| 112 | - return $this->frames[$frame]->ToPNG(); |
|
| 113 | - } |
|
| 68 | + if ($this->spritefiletype == substr(get_class($frame), 0, 3)) { |
|
| 69 | + //$this->frames[$position] = $frame; |
|
| 70 | + $this->frames[] = $frame; |
|
| 71 | + } else { |
|
| 72 | + //$this->frames[$position] = $frame->ToSpriteFrame($this->spritefiletype); |
|
| 73 | + $this->frames[] = $frame->ToSpriteFrame($this->spritefiletype); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + /// @brief Replaces a frame in the SpriteFile |
|
| 77 | + /** |
|
| 78 | + * Replaces the frame in the given position |
|
| 79 | + * Uses the same magic as AddFrame |
|
| 80 | + * @param $frame A SpriteFrame of any type. |
|
| 81 | + * @param $position Which frame to replace. If negative, counts |
|
| 82 | + * backwards from the end of the frames array. |
|
| 83 | + */ |
|
| 84 | + public function ReplaceFrame(SpriteFrame $frame, $position) { |
|
| 85 | + if ($position < 0) { |
|
| 86 | + $position = sizeof($this->frames)-$position; |
|
| 87 | + } |
|
| 88 | + $this->frames[$position] = $frame->ToSpriteFrame($this->spritefiletype); |
|
| 89 | + } |
|
| 90 | + /// @brief Gets the number of frames currently stored in this SpriteFile. |
|
| 91 | + /** |
|
| 92 | + * @return The number of frames |
|
| 93 | + */ |
|
| 94 | + public function GetFrameCount() { |
|
| 95 | + return sizeof($this->frames); |
|
| 96 | + } |
|
| 97 | + /// @brief Deletes the frame in the given position. |
|
| 98 | + /** |
|
| 99 | + * @param $frame The 0-based index of the frame to delete. |
|
| 100 | + */ |
|
| 101 | + public function DeleteFrame($frame) { |
|
| 102 | + unset($this->frames[$frame]); |
|
| 103 | + } |
|
| 104 | + /// @brief Converts the given frame to PNG. <strong>Deprecated.</strong> |
|
| 105 | + /** |
|
| 106 | + * May be removed in a future release. |
|
| 107 | + * Use GetFrame($frame)->ToPNG() instead. |
|
| 108 | + * @param integer $frame The 0-based index of the frame to delete. |
|
| 109 | + * @return A binary string containing a PNG. |
|
| 110 | + */ |
|
| 111 | + public function ToPNG($frame) { |
|
| 112 | + return $this->frames[$frame]->ToPNG(); |
|
| 113 | + } |
|
| 114 | 114 | } |
| 115 | 115 | ?> |
@@ -34,8 +34,9 @@ |
||
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $buffer = $reader->ReadInt(2); |
| 37 | - if ($buffer < 1) |
|
| 38 | - throw new Exception('Sprite file appears to contain less than 1 frame.'); |
|
| 37 | + if ($buffer < 1) { |
|
| 38 | + throw new Exception('Sprite file appears to contain less than 1 frame.'); |
|
| 39 | + } |
|
| 39 | 40 | $frameCount = $buffer; |
| 40 | 41 | for ($x = 0; $x < $frameCount; $x++) |
| 41 | 42 | { |
@@ -105,8 +105,9 @@ |
||
| 105 | 105 | * if it does't already. |
| 106 | 106 | */ |
| 107 | 107 | protected function EnsureDecoded() { |
| 108 | - if (!$this->decoded) |
|
| 109 | - $this->Decode(); |
|
| 108 | + if (!$this->decoded) { |
|
| 109 | + $this->Decode(); |
|
| 110 | + } |
|
| 110 | 111 | |
| 111 | 112 | $this->decoded = true; |
| 112 | 113 | } |
@@ -21,12 +21,15 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function FileReader($filename) |
| 23 | 23 | { |
| 24 | - if (!file_exists($filename)) |
|
| 25 | - throw new Exception("File does not exist: ".$filename); |
|
| 26 | - if (!is_file($filename)) |
|
| 27 | - throw new Exception("Target is not a file."); |
|
| 28 | - if (!is_readable($filename)) |
|
| 29 | - throw new Exception("File exists, but is not readable."); |
|
| 24 | + if (!file_exists($filename)) { |
|
| 25 | + throw new Exception("File does not exist: ".$filename); |
|
| 26 | + } |
|
| 27 | + if (!is_file($filename)) { |
|
| 28 | + throw new Exception("Target is not a file."); |
|
| 29 | + } |
|
| 30 | + if (!is_readable($filename)) { |
|
| 31 | + throw new Exception("File exists, but is not readable."); |
|
| 32 | + } |
|
| 30 | 33 | |
| 31 | 34 | $this->fp = fopen($filename, 'rb'); |
| 32 | 35 | } |
@@ -51,8 +54,9 @@ discard block |
||
| 51 | 54 | for ($x = 0; $x < $count; $x++) |
| 52 | 55 | { |
| 53 | 56 | $buffer = (ord(fgetc($this->fp)) << ($x*8)); |
| 54 | - if ($buffer === false) |
|
| 55 | - throw new Exception("Read failure"); |
|
| 57 | + if ($buffer === false) { |
|
| 58 | + throw new Exception("Read failure"); |
|
| 59 | + } |
|
| 56 | 60 | $int += $buffer; |
| 57 | 61 | } |
| 58 | 62 | return $int; |
@@ -13,14 +13,14 @@ |
||
| 13 | 13 | /** |
| 14 | 14 | * If $prayfile is not null, all the data for this block |
| 15 | 15 | * will be read from the PRAYFile. |
| 16 | - * @param PRAYFile $prayfile The PRAYFile that this DFAM block belongs to. |
|
| 17 | - * @param $name The block's name. |
|
| 18 | - * @param $content The binary data of this block. May be null. |
|
| 19 | - * @param $flags The block's flags |
|
| 20 | - */ |
|
| 21 | - public function DFAMBlock($prayfile, $name, $content, $flags) { |
|
| 22 | - parent::TagBlock($prayfile, $name, $content, $flags, PRAY_BLOCK_DFAM); |
|
| 16 | + * @param PRAYFile $prayfile The PRAYFile that this DFAM block belongs to. |
|
| 17 | + * @param $name The block's name. |
|
| 18 | + * @param $content The binary data of this block. May be null. |
|
| 19 | + * @param $flags The block's flags |
|
| 20 | + */ |
|
| 21 | + public function DFAMBlock($prayfile, $name, $content, $flags) { |
|
| 22 | + parent::TagBlock($prayfile, $name, $content, $flags, PRAY_BLOCK_DFAM); |
|
| 23 | 23 | |
| 24 | - } |
|
| 24 | + } |
|
| 25 | 25 | } |
| 26 | 26 | ?> |
@@ -22,17 +22,17 @@ |
||
| 22 | 22 | * @param $name The block's name. |
| 23 | 23 | * @param $content The content of the block as a binary string. |
| 24 | 24 | */ |
| 25 | - public function BinaryBlock($type, $name, $content) { |
|
| 26 | - parent::PrayBlock(null, $name, '', 0, $type); |
|
| 27 | - $this->binarydata = $content; |
|
| 25 | + public function BinaryBlock($type, $name, $content) { |
|
| 26 | + parent::PrayBlock(null, $name, '', 0, $type); |
|
| 27 | + $this->binarydata = $content; |
|
| 28 | 28 | } |
| 29 | 29 | /// @brief Compile the BinaryBlock |
| 30 | 30 | /** |
| 31 | 31 | * @return string compiled BinaryBlock as a binary string. |
| 32 | 32 | */ |
| 33 | - public function Compile() { |
|
| 34 | - return $this->EncodeBlockHeader(strlen($this->binarydata)).$this->binarydata; |
|
| 35 | - } |
|
| 33 | + public function Compile() { |
|
| 34 | + return $this->EncodeBlockHeader(strlen($this->binarydata)).$this->binarydata; |
|
| 35 | + } |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | ?> |
@@ -10,18 +10,18 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class SFAMBlock extends EXPCBlock { |
| 12 | 12 | |
| 13 | - /// @brief Instantiates a new SFAMBlock |
|
| 13 | + /// @brief Instantiates a new SFAMBlock |
|
| 14 | 14 | /** |
| 15 | 15 | * If $prayfile is not null, all the data for this block |
| 16 | 16 | * will be read from the PRAYFile. |
| 17 | - * @param PRAYFile $prayfile The PRAYFile that this DFAM block belongs to. |
|
| 18 | - * @param $name The block's name. |
|
| 19 | - * @param $content The binary data of this block. May be null. |
|
| 20 | - * @param $flags The block's flags |
|
| 21 | - */ |
|
| 22 | - public function SFAMBlock($prayfile, $name, $content, $flags) { |
|
| 23 | - parent::TagBlock($prayfile, $name, $content, $flags, PRAY_BLOCK_SFAM); |
|
| 17 | + * @param PRAYFile $prayfile The PRAYFile that this DFAM block belongs to. |
|
| 18 | + * @param $name The block's name. |
|
| 19 | + * @param $content The binary data of this block. May be null. |
|
| 20 | + * @param $flags The block's flags |
|
| 21 | + */ |
|
| 22 | + public function SFAMBlock($prayfile, $name, $content, $flags) { |
|
| 23 | + parent::TagBlock($prayfile, $name, $content, $flags, PRAY_BLOCK_SFAM); |
|
| 24 | 24 | |
| 25 | - } |
|
| 25 | + } |
|
| 26 | 26 | } |
| 27 | 27 | ?> |