@@ -12,13 +12,14 @@ discard block |
||
12 | 12 | interface IReader { |
13 | 13 | /// @brief Reads an integer |
14 | 14 | /** |
15 | - * @param $length Length of the integer in bytes. |
|
15 | + * @param integer $length Length of the integer in bytes. |
|
16 | 16 | */ |
17 | 17 | public function ReadInt($length); |
18 | 18 | |
19 | 19 | /// @brief Reads a string |
20 | 20 | /** |
21 | 21 | * @param $length Length of the string to read in bytes |
22 | + * @return string|false |
|
22 | 23 | */ |
23 | 24 | public function Read($length); |
24 | 25 | |
@@ -30,24 +31,32 @@ discard block |
||
30 | 31 | * memory-wise, but it simplifies the code and c2e files don't |
31 | 32 | * tend to get big enough to make this inefficiency a concern on |
32 | 33 | * any reasonably modern hardware. |
34 | + * @return string |
|
33 | 35 | */ |
34 | 36 | public function GetSubString($start,$length=FALSE); |
35 | 37 | /// @brief Gets the position of the cursor |
36 | 38 | /** |
37 | 39 | * This is analagous to ftell in C or PHP. |
40 | + * @return integer |
|
38 | 41 | */ |
39 | 42 | public function GetPosition(); |
40 | 43 | /// @brief Changes the current position in the reader's stream |
41 | 44 | /** |
42 | 45 | * This is analagous to fseek in C or PHP. |
46 | + * @return void |
|
43 | 47 | */ |
44 | 48 | public function Seek($position); |
45 | 49 | /// @brief Advances the position of the reader by $count. |
50 | + |
|
51 | + /** |
|
52 | + * @return void |
|
53 | + */ |
|
46 | 54 | public function Skip($count); |
47 | 55 | /// @brief Reads a c-style string at the current position. |
48 | 56 | /** |
49 | 57 | * C-style means that the string is terminated by a NUL (0) |
50 | 58 | * character. |
59 | + * @return string |
|
51 | 60 | */ |
52 | 61 | public function ReadCString(); //read a string of unknown length until the first NUL |
53 | 62 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | * tend to get big enough to make this inefficiency a concern on |
32 | 32 | * any reasonably modern hardware. |
33 | 33 | */ |
34 | - public function GetSubString($start,$length=FALSE); |
|
34 | + public function GetSubString($start, $length = FALSE); |
|
35 | 35 | /// @brief Gets the position of the cursor |
36 | 36 | /** |
37 | 37 | * This is analagous to ftell in C or PHP. |
@@ -50,12 +50,20 @@ discard block |
||
50 | 50 | public function Skip($count) { |
51 | 51 | $this->position += $count; |
52 | 52 | } |
53 | + |
|
54 | + /** |
|
55 | + * @param integer $characters |
|
56 | + */ |
|
53 | 57 | public function ReadInt($characters) { |
54 | 58 | return BytesToIntLilEnd($this->Read($characters)); |
55 | 59 | } |
56 | 60 | public function GetPosition() { |
57 | 61 | return $this->position; |
58 | 62 | } |
63 | + |
|
64 | + /** |
|
65 | + * @param integer $start |
|
66 | + */ |
|
59 | 67 | public function GetSubString($start,$length = FALSE) { |
60 | 68 | if($length == FALSE) { |
61 | 69 | $length = strlen($this->string)-$start; |
@@ -65,6 +73,9 @@ discard block |
||
65 | 73 | } |
66 | 74 | } |
67 | 75 | |
76 | +/** |
|
77 | + * @param false|string $string |
|
78 | + */ |
|
68 | 79 | function BytesToIntLilEnd($string) { //little endian |
69 | 80 | if($string == "") { |
70 | 81 | return false; |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | $this->position = 0; |
24 | 24 | } |
25 | 25 | public function Read($characters) { |
26 | - if($characters > 0) { |
|
27 | - if($this->position+$characters > strlen($this->string)) { |
|
26 | + if ($characters > 0) { |
|
27 | + if ($this->position+$characters > strlen($this->string)) { |
|
28 | 28 | return false; |
29 | 29 | } |
30 | - $str = substr($this->string,$this->position,$characters); |
|
30 | + $str = substr($this->string, $this->position, $characters); |
|
31 | 31 | |
32 | 32 | $this->position += $characters; |
33 | 33 | return $str; |
@@ -36,13 +36,13 @@ discard block |
||
36 | 36 | } |
37 | 37 | public function ReadCString() { |
38 | 38 | $string = ''; |
39 | - while(($char = $this->Read(1)) !== false) { |
|
40 | - $string.=$char; |
|
41 | - if($char == "\0") { |
|
39 | + while (($char = $this->Read(1)) !== false) { |
|
40 | + $string .= $char; |
|
41 | + if ($char == "\0") { |
|
42 | 42 | break; |
43 | 43 | } |
44 | 44 | } |
45 | - return substr($string,0,-1); |
|
45 | + return substr($string, 0, -1); |
|
46 | 46 | } |
47 | 47 | public function Seek($position) { |
48 | 48 | $this->position = $position; |
@@ -56,23 +56,23 @@ discard block |
||
56 | 56 | public function GetPosition() { |
57 | 57 | return $this->position; |
58 | 58 | } |
59 | - public function GetSubString($start,$length = FALSE) { |
|
60 | - if($length == FALSE) { |
|
59 | + public function GetSubString($start, $length = FALSE) { |
|
60 | + if ($length == FALSE) { |
|
61 | 61 | $length = strlen($this->string)-$start; |
62 | 62 | } |
63 | - $str = substr($this->string,$start,$length); |
|
63 | + $str = substr($this->string, $start, $length); |
|
64 | 64 | return $str; |
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | 68 | function BytesToIntLilEnd($string) { //little endian |
69 | - if($string == "") { |
|
69 | + if ($string == "") { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | $length = strlen($string); |
73 | 73 | $int = 0; |
74 | - for($i=0;$i<$length;$i++) { |
|
75 | - $int += ord($string{$i})<<($i*8); |
|
74 | + for ($i = 0; $i < $length; $i++) { |
|
75 | + $int += ord($string{$i}) << ($i*8); |
|
76 | 76 | } |
77 | 77 | return $int; |
78 | 78 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once(dirname(__FILE__) . '/AbstractTestCase.php'); |
|
3 | -require_once(dirname(__FILE__) . '/../support/FileReader.php'); |
|
4 | -require_once(dirname(__FILE__) . '/../support/StringReader.php'); |
|
2 | +require_once(dirname(__FILE__).'/AbstractTestCase.php'); |
|
3 | +require_once(dirname(__FILE__).'/../support/FileReader.php'); |
|
4 | +require_once(dirname(__FILE__).'/../support/StringReader.php'); |
|
5 | 5 | |
6 | 6 | class ReaderTest extends c2ephpAbstractTestCase { |
7 | 7 | |
@@ -10,19 +10,19 @@ discard block |
||
10 | 10 | */ |
11 | 11 | public function testStringReader($string) { |
12 | 12 | $stringReader = new StringReader($string); |
13 | - $this->assertEquals($string[0],$stringReader->Read(1)); |
|
14 | - $this->assertEquals($string[1],$stringReader->Read(1)); |
|
13 | + $this->assertEquals($string[0], $stringReader->Read(1)); |
|
14 | + $this->assertEquals($string[1], $stringReader->Read(1)); |
|
15 | 15 | $stringReader->skip(2); |
16 | - $this->assertEquals($string[4],$stringReader->Read(1)); |
|
17 | - $this->assertEquals(substr($string,3,8),$stringReader->GetSubString(3,8)); |
|
18 | - $this->assertEquals($string[5],$stringReader->Read(1)); |
|
16 | + $this->assertEquals($string[4], $stringReader->Read(1)); |
|
17 | + $this->assertEquals(substr($string, 3, 8), $stringReader->GetSubString(3, 8)); |
|
18 | + $this->assertEquals($string[5], $stringReader->Read(1)); |
|
19 | 19 | |
20 | - $this->assertEquals($string,$stringReader->GetSubString(0)); |
|
20 | + $this->assertEquals($string, $stringReader->GetSubString(0)); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | public function generateStrings() { |
24 | 24 | return array( |
25 | - array('striiing','blimp!!!!!!!'), |
|
25 | + array('striiing', 'blimp!!!!!!!'), |
|
26 | 26 | ); |
27 | 27 | } |
28 | 28 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once(dirname(__FILE__) . '/../agents/PRAYFile.php'); |
|
3 | -require_once(dirname(__FILE__) . '/../support/FileReader.php'); |
|
2 | +require_once(dirname(__FILE__).'/../agents/PRAYFile.php'); |
|
3 | +require_once(dirname(__FILE__).'/../support/FileReader.php'); |
|
4 | 4 | |
5 | 5 | abstract class c2ephpAbstractTestCase extends PHPUnit_Framework_TestCase { |
6 | 6 | /// @brief Agent Files fixture |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | ); |
28 | 28 | |
29 | 29 | $prayfiles = array(); |
30 | - foreach($files as $info) { |
|
30 | + foreach ($files as $info) { |
|
31 | 31 | |
32 | 32 | $prayfiles[] = array(new PRAYFile(new FileReader($info['path'])), $info); |
33 | 33 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | |
45 | 45 | |
46 | 46 | $prayfiles = array(); |
47 | - foreach($files as $info) { |
|
47 | + foreach ($files as $info) { |
|
48 | 48 | |
49 | 49 | $prayfiles[] = array(new PRAYFile(new FileReader($info['path'])), $info); |
50 | 50 | } |
@@ -4,16 +4,16 @@ |
||
4 | 4 | class PRAYFileTest extends c2ephpAbstractTestCase { |
5 | 5 | |
6 | 6 | /** |
7 | - * @dataProvider createAgentFiles |
|
8 | - */ |
|
7 | + * @dataProvider createAgentFiles |
|
8 | + */ |
|
9 | 9 | public function testCreatePRAYFile(PRAYFile $prayfile) { |
10 | 10 | $this->assertInstanceOf('PRAYFile',$prayfile); |
11 | 11 | $this->assertNotNull($prayfile); |
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
15 | - * @dataProvider createAgentFiles |
|
16 | - */ |
|
15 | + * @dataProvider createAgentFiles |
|
16 | + */ |
|
17 | 17 | public function testNumberOfBlocks(PRAYFile $prayfile,$fixtureInfo) { |
18 | 18 | $this->assertNotNull($prayfile); |
19 | 19 | $this->assertEquals($fixtureInfo['block count'],sizeof($prayfile->GetBlocks())); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once(dirname(__FILE__) . '/AbstractTestCase.php'); |
|
2 | +require_once(dirname(__FILE__).'/AbstractTestCase.php'); |
|
3 | 3 | |
4 | 4 | class PRAYFileTest extends c2ephpAbstractTestCase { |
5 | 5 | |
@@ -7,56 +7,56 @@ discard block |
||
7 | 7 | * @dataProvider createAgentFiles |
8 | 8 | */ |
9 | 9 | public function testCreatePRAYFile(PRAYFile $prayfile) { |
10 | - $this->assertInstanceOf('PRAYFile',$prayfile); |
|
10 | + $this->assertInstanceOf('PRAYFile', $prayfile); |
|
11 | 11 | $this->assertNotNull($prayfile); |
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
15 | 15 | * @dataProvider createAgentFiles |
16 | 16 | */ |
17 | - public function testNumberOfBlocks(PRAYFile $prayfile,$fixtureInfo) { |
|
17 | + public function testNumberOfBlocks(PRAYFile $prayfile, $fixtureInfo) { |
|
18 | 18 | $this->assertNotNull($prayfile); |
19 | - $this->assertEquals($fixtureInfo['block count'],sizeof($prayfile->GetBlocks())); |
|
19 | + $this->assertEquals($fixtureInfo['block count'], sizeof($prayfile->GetBlocks())); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @dataProvider createAgentFiles |
24 | 24 | */ |
25 | - public function testFirstAgentDescription(PRAYFile $prayfile,$info) { |
|
25 | + public function testFirstAgentDescription(PRAYFile $prayfile, $info) { |
|
26 | 26 | $this->assertNotNull($prayfile); |
27 | 27 | $blocks = $prayfile->GetBlocks(PRAY_BLOCK_AGNT); |
28 | - $this->assertEquals($info['first agent desc'],$blocks[0]->GetAgentDescription()); |
|
28 | + $this->assertEquals($info['first agent desc'], $blocks[0]->GetAgentDescription()); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * @dataProvider createAgentFiles |
33 | 33 | */ |
34 | - public function testChangeAGNTAndRecompile(PRAYFile $prayfile,$info) { |
|
34 | + public function testChangeAGNTAndRecompile(PRAYFile $prayfile, $info) { |
|
35 | 35 | $this->assertNotNull($prayfile); |
36 | 36 | $blocks = $prayfile->GetBlocks(PRAY_BLOCK_AGNT); |
37 | - $blocks[0]->SetTag('Agent Description','Testing'); |
|
38 | - $this->assertEquals('Testing',$blocks[0]->GetAgentDescription()); |
|
37 | + $blocks[0]->SetTag('Agent Description', 'Testing'); |
|
38 | + $this->assertEquals('Testing', $blocks[0]->GetAgentDescription()); |
|
39 | 39 | $data = $prayfile->Compile(); |
40 | 40 | $newfile = new PRAYFile(new StringReader($data)); |
41 | - $this->assertEquals($info['block count'],sizeof($newfile->GetBlocks())); |
|
41 | + $this->assertEquals($info['block count'], sizeof($newfile->GetBlocks())); |
|
42 | 42 | $newfile->GetBlocks('AGNT'); |
43 | - $this->assertEquals('Testing',$blocks[0]->GetAgentDescription()); |
|
43 | + $this->assertEquals('Testing', $blocks[0]->GetAgentDescription()); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @dataProvider createCreatureFiles |
48 | 48 | */ |
49 | - public function testChangeGLSTAndRecompile(PRAYFILE $prayfile,$info) { |
|
49 | + public function testChangeGLSTAndRecompile(PRAYFILE $prayfile, $info) { |
|
50 | 50 | $this->assertNotNull($prayfile); |
51 | 51 | $blocks = $prayfile->GetBlocks(PRAY_BLOCK_GLST); |
52 | - $this->assertEquals($info['events count'],$blocks[0]->GetHistory()->CountEvents()); |
|
52 | + $this->assertEquals($info['events count'], $blocks[0]->GetHistory()->CountEvents()); |
|
53 | 53 | $blocks[0]->GetHistory()->RemoveEvent(0); |
54 | - $this->assertEquals($info['events count']-1,$blocks[0]->GetHistory()->CountEvents()); |
|
54 | + $this->assertEquals($info['events count']-1, $blocks[0]->GetHistory()->CountEvents()); |
|
55 | 55 | |
56 | 56 | $data = $prayfile->Compile(); |
57 | 57 | $newfile = new PRAYFile(new StringReader($data)); |
58 | 58 | $blocks = $newfile->GetBlocks(PRAY_BLOCK_GLST); |
59 | - $this->assertEquals($info['events count']-1,$blocks[0]->GetHistory()->CountEvents()); |
|
59 | + $this->assertEquals($info['events count']-1, $blocks[0]->GetHistory()->CountEvents()); |
|
60 | 60 | |
61 | 61 | } |
62 | 62 | } |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | * @param $reader An IReader or GD image resource. |
26 | 26 | * @param $encoding The encoding of the C16 frame (555 or 565). Defaults to 565 |
27 | 27 | */ |
28 | - public function C16Frame($reader,$encoding='565') |
|
28 | + public function C16Frame($reader, $encoding = '565') |
|
29 | 29 | { |
30 | - if($reader instanceof IReader) { |
|
30 | + if ($reader instanceof IReader) { |
|
31 | 31 | $this->reader = $reader; |
32 | 32 | $this->encoding = $encoding; |
33 | 33 | $this->offset = $this->reader->ReadInt(4); |
@@ -35,17 +35,17 @@ discard block |
||
35 | 35 | $width = $this->reader->ReadInt(2); |
36 | 36 | $height = $this->reader->ReadInt(2); |
37 | 37 | |
38 | - parent::SpriteFrame($width,$height); |
|
38 | + parent::SpriteFrame($width, $height); |
|
39 | 39 | |
40 | - for($x = 0; $x < ($height - 1); $x++) |
|
40 | + for ($x = 0; $x < ($height-1); $x++) |
|
41 | 41 | { |
42 | 42 | $this->lineOffset[$x] = $this->reader->ReadInt(4); |
43 | 43 | } |
44 | - } else if(is_resource($reader)) { |
|
45 | - if(get_resource_type($reader) == 'gd') { |
|
44 | + } else if (is_resource($reader)) { |
|
45 | + if (get_resource_type($reader) == 'gd') { |
|
46 | 46 | |
47 | - $this->encoding = ($encoding=='555')?'555':'565'; |
|
48 | - parent::SpriteFrame(imagesx($reader),imagesy($reader),true); |
|
47 | + $this->encoding = ($encoding == '555') ? '555' : '565'; |
|
48 | + parent::SpriteFrame(imagesx($reader), imagesy($reader), true); |
|
49 | 49 | $this->gdImage = $reader; |
50 | 50 | } |
51 | 51 | } else { |
@@ -70,37 +70,37 @@ discard block |
||
70 | 70 | $image = imagecreatetruecolor($this->GetWidth(), |
71 | 71 | $this->GetHeight()); |
72 | 72 | $this->reader->Seek($this->offset); |
73 | - for($y = 0; $y < $this->GetHeight(); $y++) |
|
73 | + for ($y = 0; $y < $this->GetHeight(); $y++) |
|
74 | 74 | { |
75 | - for($x = 0; $x < $this->GetWidth();) |
|
75 | + for ($x = 0; $x < $this->GetWidth();) |
|
76 | 76 | { |
77 | 77 | $run = $this->reader->ReadInt(2); |
78 | - if(($run & 0x0001) > 0) |
|
78 | + if (($run & 0x0001) > 0) |
|
79 | 79 | $run_type = "colour"; |
80 | 80 | else |
81 | 81 | $run_type = "black"; |
82 | 82 | $run_length = ($run & 0x7FFF) >> 1; |
83 | - if($run_type == "black") |
|
83 | + if ($run_type == "black") |
|
84 | 84 | { |
85 | - $z = $x + $run_length; |
|
86 | - for(;$x < $z; $x++) |
|
85 | + $z = $x+$run_length; |
|
86 | + for (;$x < $z; $x++) |
|
87 | 87 | { |
88 | 88 | imagesetpixel($image, $x, $y, imagecolorallocate($image, 0, 0, 0)); |
89 | 89 | } |
90 | 90 | } |
91 | 91 | else //colour run |
92 | 92 | { |
93 | - $z = $x + $run_length; |
|
94 | - for(;$x < $z; $x++) |
|
93 | + $z = $x+$run_length; |
|
94 | + for (;$x < $z; $x++) |
|
95 | 95 | { |
96 | 96 | $pixel = $this->reader->ReadInt(2); |
97 | - if($this->encoding == "565") |
|
97 | + if ($this->encoding == "565") |
|
98 | 98 | { |
99 | 99 | $red = ($pixel & 0xF800) >> 8; |
100 | 100 | $green = ($pixel & 0x07E0) >> 3; |
101 | 101 | $blue = ($pixel & 0x001F) << 3; |
102 | 102 | } |
103 | - else if($this->encoding == "555") |
|
103 | + else if ($this->encoding == "555") |
|
104 | 104 | { |
105 | 105 | $red = ($pixel & 0x7C00) >> 7; |
106 | 106 | $green = ($pixel & 0x03E0) >> 2; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | imagesetpixel($image, $x, $y, $colour); |
111 | 111 | } |
112 | 112 | } |
113 | - if($x == $this->GetWidth()) |
|
113 | + if ($x == $this->GetWidth()) |
|
114 | 114 | $this->reader->Skip(2); |
115 | 115 | } |
116 | 116 | } |
@@ -127,21 +127,21 @@ discard block |
||
127 | 127 | public function Encode() { |
128 | 128 | $data = ''; |
129 | 129 | $lineOffsets = array(); |
130 | - for($y = 0; $y < $this->GetHeight(); $y++) { |
|
130 | + for ($y = 0; $y < $this->GetHeight(); $y++) { |
|
131 | 131 | $wasblack = 0; |
132 | 132 | $runlength = 0; |
133 | - if($y > 0) { |
|
133 | + if ($y > 0) { |
|
134 | 134 | $lineOffsets[] = strlen($data); |
135 | 135 | } |
136 | 136 | $colourRunData = ''; |
137 | - for($x = 0; $x < $this->GetWidth(); $x++) { |
|
137 | + for ($x = 0; $x < $this->GetWidth(); $x++) { |
|
138 | 138 | |
139 | - $pixel = $this->GetPixel($x,$y); |
|
140 | - if($pixel['red'] > 255 || $pixel['green'] > 255 || $pixel['blue'] > 255) { |
|
139 | + $pixel = $this->GetPixel($x, $y); |
|
140 | + if ($pixel['red'] > 255 || $pixel['green'] > 255 || $pixel['blue'] > 255) { |
|
141 | 141 | throw new Exception('Pixel colour out of range.'); |
142 | 142 | } |
143 | 143 | $newpixel = 0; |
144 | - if($this->encoding == '555') { |
|
144 | + if ($this->encoding == '555') { |
|
145 | 145 | $newpixel = (($pixel['red'] << 7) & 0xF800) | (($pixel['green'] << 2) & 0x03E0) | (($pixel['blue'] >> 3) & 0x001F); |
146 | 146 | } else { |
147 | 147 | $newpixel = (($pixel['red'] << 8) & 0xF800) | (($pixel['green'] << 3) & 0x07E0) | (($pixel['blue'] >> 3) & 0x001F); |
@@ -149,48 +149,48 @@ discard block |
||
149 | 149 | |
150 | 150 | |
151 | 151 | // if isblack !== wasblack |
152 | - if(($newpixel == 0) !== $wasblack || $runlength > 32766) { |
|
152 | + if (($newpixel == 0) !== $wasblack || $runlength > 32766) { |
|
153 | 153 | //end the run if this isn't the first run |
154 | - if($wasblack !== 0) { |
|
154 | + if ($wasblack !== 0) { |
|
155 | 155 | |
156 | 156 | //output data. |
157 | 157 | $run = $runlength << 1; |
158 | - if($wasblack) { |
|
159 | - $data .= pack('v',$run); |
|
158 | + if ($wasblack) { |
|
159 | + $data .= pack('v', $run); |
|
160 | 160 | |
161 | 161 | } else { |
162 | 162 | $run = $run | 1; |
163 | - $data .= pack('v',$run); |
|
163 | + $data .= pack('v', $run); |
|
164 | 164 | $data .= $colourRunData; |
165 | 165 | $colourRunData = ''; |
166 | 166 | } |
167 | 167 | } |
168 | 168 | //start a new run |
169 | - if($newpixel == 0) { |
|
169 | + if ($newpixel == 0) { |
|
170 | 170 | $wasblack = true; |
171 | 171 | $colourRunData = ''; |
172 | 172 | } else { |
173 | 173 | $wasblack = false; |
174 | - $colourRunData = pack('v',$newpixel); |
|
174 | + $colourRunData = pack('v', $newpixel); |
|
175 | 175 | } |
176 | 176 | $runlength = 1; |
177 | 177 | |
178 | 178 | } else { |
179 | - if(!$wasblack) { |
|
180 | - $colourRunData .= pack('v',$newpixel); |
|
179 | + if (!$wasblack) { |
|
180 | + $colourRunData .= pack('v', $newpixel); |
|
181 | 181 | } |
182 | 182 | $runlength++; |
183 | 183 | } |
184 | 184 | |
185 | - if($x == ($this->GetWidth()-1)) { |
|
185 | + if ($x == ($this->GetWidth()-1)) { |
|
186 | 186 | //end run and output data. |
187 | 187 | $run = $runlength << 1; |
188 | - if($wasblack) { |
|
189 | - $data .= pack('v',$run); |
|
188 | + if ($wasblack) { |
|
189 | + $data .= pack('v', $run); |
|
190 | 190 | |
191 | 191 | } else { |
192 | 192 | $run = $run | 1; |
193 | - $data .= pack('v',$run); |
|
193 | + $data .= pack('v', $run); |
|
194 | 194 | $data .= $colourRunData; |
195 | 195 | $colourRunData = ''; |
196 | 196 | } |
@@ -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 | { |
@@ -87,8 +88,7 @@ discard block |
||
87 | 88 | { |
88 | 89 | imagesetpixel($image, $x, $y, imagecolorallocate($image, 0, 0, 0)); |
89 | 90 | } |
90 | - } |
|
91 | - else //colour run |
|
91 | + } else //colour run |
|
92 | 92 | { |
93 | 93 | $z = $x + $run_length; |
94 | 94 | for(;$x < $z; $x++) |
@@ -99,8 +99,7 @@ discard block |
||
99 | 99 | $red = ($pixel & 0xF800) >> 8; |
100 | 100 | $green = ($pixel & 0x07E0) >> 3; |
101 | 101 | $blue = ($pixel & 0x001F) << 3; |
102 | - } |
|
103 | - else if($this->encoding == "555") |
|
102 | + } else if($this->encoding == "555") |
|
104 | 103 | { |
105 | 104 | $red = ($pixel & 0x7C00) >> 7; |
106 | 105 | $green = ($pixel & 0x03E0) >> 2; |
@@ -110,8 +109,9 @@ discard block |
||
110 | 109 | imagesetpixel($image, $x, $y, $colour); |
111 | 110 | } |
112 | 111 | } |
113 | - if($x == $this->GetWidth()) |
|
114 | - $this->reader->Skip(2); |
|
112 | + if($x == $this->GetWidth()) { |
|
113 | + $this->reader->Skip(2); |
|
114 | + } |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | $this->gdImage = $image; |
@@ -15,31 +15,31 @@ |
||
15 | 15 | * Reads in the IReader and creates SPRFrames as required. |
16 | 16 | * @param $reader An IReader to read from. |
17 | 17 | */ |
18 | - public function SPRFile(IReader $reader) { |
|
19 | - parent::SpriteFile('SPR'); |
|
20 | - $frameCount = $reader->ReadInt(2); |
|
18 | + public function SPRFile(IReader $reader) { |
|
19 | + parent::SpriteFile('SPR'); |
|
20 | + $frameCount = $reader->ReadInt(2); |
|
21 | 21 | |
22 | - for($i=0;$i<$frameCount;$i++) { |
|
23 | - $offset = $reader->ReadInt(4); |
|
24 | - $width = $reader->ReadInt(2); |
|
25 | - $height = $reader->ReadInt(2); |
|
26 | - $this->AddFrame(new SPRFrame($reader,$width,$height,$offset)); |
|
27 | - } |
|
28 | - } |
|
22 | + for($i=0;$i<$frameCount;$i++) { |
|
23 | + $offset = $reader->ReadInt(4); |
|
24 | + $width = $reader->ReadInt(2); |
|
25 | + $height = $reader->ReadInt(2); |
|
26 | + $this->AddFrame(new SPRFrame($reader,$width,$height,$offset)); |
|
27 | + } |
|
28 | + } |
|
29 | 29 | |
30 | 30 | /// @brief Compiles the SPR file into a binary string |
31 | - public function Compile() { |
|
32 | - $data = pack('v',$this->GetFrameCount()); |
|
33 | - $offset = 2+(8*$this->GetFrameCount()); |
|
34 | - foreach($this->GetFrames() as $frame) { |
|
35 | - $data .= pack('V',$offset); |
|
36 | - $data .= pack('vv',$frame->GetWidth(),$frame->GetHeight()); |
|
37 | - $offset += $frame->GetWidth()*$frame->GetHeight(); |
|
38 | - } |
|
39 | - foreach($this->GetFrames() as $frame) { |
|
40 | - $data .= $frame->Encode(); |
|
41 | - } |
|
42 | - return $data; |
|
43 | - } |
|
31 | + public function Compile() { |
|
32 | + $data = pack('v',$this->GetFrameCount()); |
|
33 | + $offset = 2+(8*$this->GetFrameCount()); |
|
34 | + foreach($this->GetFrames() as $frame) { |
|
35 | + $data .= pack('V',$offset); |
|
36 | + $data .= pack('vv',$frame->GetWidth(),$frame->GetHeight()); |
|
37 | + $offset += $frame->GetWidth()*$frame->GetHeight(); |
|
38 | + } |
|
39 | + foreach($this->GetFrames() as $frame) { |
|
40 | + $data .= $frame->Encode(); |
|
41 | + } |
|
42 | + return $data; |
|
43 | + } |
|
44 | 44 | } |
45 | 45 | ?> |
@@ -19,24 +19,24 @@ |
||
19 | 19 | parent::SpriteFile('SPR'); |
20 | 20 | $frameCount = $reader->ReadInt(2); |
21 | 21 | |
22 | - for($i=0;$i<$frameCount;$i++) { |
|
22 | + for ($i = 0; $i < $frameCount; $i++) { |
|
23 | 23 | $offset = $reader->ReadInt(4); |
24 | 24 | $width = $reader->ReadInt(2); |
25 | 25 | $height = $reader->ReadInt(2); |
26 | - $this->AddFrame(new SPRFrame($reader,$width,$height,$offset)); |
|
26 | + $this->AddFrame(new SPRFrame($reader, $width, $height, $offset)); |
|
27 | 27 | } |
28 | 28 | } |
29 | 29 | |
30 | 30 | /// @brief Compiles the SPR file into a binary string |
31 | 31 | public function Compile() { |
32 | - $data = pack('v',$this->GetFrameCount()); |
|
32 | + $data = pack('v', $this->GetFrameCount()); |
|
33 | 33 | $offset = 2+(8*$this->GetFrameCount()); |
34 | - foreach($this->GetFrames() as $frame) { |
|
35 | - $data .= pack('V',$offset); |
|
36 | - $data .= pack('vv',$frame->GetWidth(),$frame->GetHeight()); |
|
34 | + foreach ($this->GetFrames() as $frame) { |
|
35 | + $data .= pack('V', $offset); |
|
36 | + $data .= pack('vv', $frame->GetWidth(), $frame->GetHeight()); |
|
37 | 37 | $offset += $frame->GetWidth()*$frame->GetHeight(); |
38 | 38 | } |
39 | - foreach($this->GetFrames() as $frame) { |
|
39 | + foreach ($this->GetFrames() as $frame) { |
|
40 | 40 | $data .= $frame->Encode(); |
41 | 41 | } |
42 | 42 | return $data; |
@@ -443,9 +443,9 @@ |
||
443 | 443 | case 'untl': |
444 | 444 | case 'next': |
445 | 445 | case 'ever': |
446 | - case 'repe'; |
|
447 | - $this->currentIndent--; |
|
448 | - break; |
|
446 | + case 'repe'; |
|
447 | + $this->currentIndent--; |
|
448 | + break; |
|
449 | 449 | } |
450 | 450 | } |
451 | 451 |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -define('FORMAT_C1','C1'); |
|
4 | -define('FORMAT_C2','C2'); |
|
5 | -define('FORMAT_C3','C3'); |
|
6 | -define('FORMAT_DS','DS'); |
|
3 | +define('FORMAT_C1', 'C1'); |
|
4 | +define('FORMAT_C2', 'C2'); |
|
5 | +define('FORMAT_C3', 'C3'); |
|
6 | +define('FORMAT_DS', 'DS'); |
|
7 | 7 | |
8 | 8 | |
9 | 9 | /// @brief Class for highlighting CAOS |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | require_once(dirname(__FILE__).'/'.$format.'/Operators.php'); |
64 | 64 | |
65 | 65 | //put into arrays |
66 | - $this->caosCommandVariables = call_user_func(array($format.'CAOSCommandVariables','GetTokens')); |
|
67 | - $this->caosCommands = call_user_func(array($format.'CAOSCommands','GetTokens')); |
|
68 | - $this->caosVariables = call_user_func(array($format.'CAOSVariables','GetTokens')); |
|
69 | - $this->caosOperators = call_user_func(array($format.'CAOSOperators','GetTokens')); |
|
70 | - $this->caosFlowControls = call_user_func(array($format.'CAOSFlowControls','GetTokens')); |
|
66 | + $this->caosCommandVariables = call_user_func(array($format.'CAOSCommandVariables', 'GetTokens')); |
|
67 | + $this->caosCommands = call_user_func(array($format.'CAOSCommands', 'GetTokens')); |
|
68 | + $this->caosVariables = call_user_func(array($format.'CAOSVariables', 'GetTokens')); |
|
69 | + $this->caosOperators = call_user_func(array($format.'CAOSOperators', 'GetTokens')); |
|
70 | + $this->caosFlowControls = call_user_func(array($format.'CAOSFlowControls', 'GetTokens')); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /// @brief Highlights the given CAOS script. |
@@ -78,21 +78,21 @@ discard block |
||
78 | 78 | * @param $script the CAOS script as a string. |
79 | 79 | */ |
80 | 80 | public function HighlightScript($script) { |
81 | - if(strpos($script,"\r") !== false) { |
|
82 | - $script = str_replace("\r\n","\n",$script); //get rid of mac and windows newlines. |
|
83 | - $script = str_replace("\r","\n",$script); |
|
81 | + if (strpos($script, "\r") !== false) { |
|
82 | + $script = str_replace("\r\n", "\n", $script); //get rid of mac and windows newlines. |
|
83 | + $script = str_replace("\r", "\n", $script); |
|
84 | 84 | } |
85 | 85 | //remove tabs and spaces before newlines. |
86 | - $script = str_replace(" \n","\n",$script); |
|
87 | - $script = str_replace("\t",'',$script); |
|
86 | + $script = str_replace(" \n", "\n", $script); |
|
87 | + $script = str_replace("\t", '', $script); |
|
88 | 88 | $script = $this->SmartRemoveMultipleSpaces($script); |
89 | - $this->scriptLines = explode("\n",$script); |
|
89 | + $this->scriptLines = explode("\n", $script); |
|
90 | 90 | |
91 | 91 | //now that we have the lines, we can make the list of subroutines. |
92 | 92 | $this->ScanForSubroutines(); |
93 | 93 | $this->currentLine = 0; |
94 | 94 | $this->highlightedLines = array(); |
95 | - while(($line = $this->HighlightNextLine()) !== false) { |
|
95 | + while (($line = $this->HighlightNextLine()) !== false) { |
|
96 | 96 | |
97 | 97 | $this->highlightedLines[] = $line; |
98 | 98 | } |
@@ -111,22 +111,22 @@ discard block |
||
111 | 111 | $newString = array(); |
112 | 112 | $inString = false; |
113 | 113 | $inComment = false; |
114 | - for($i=0;$i<strlen($text);$i++) { |
|
114 | + for ($i = 0; $i < strlen($text); $i++) { |
|
115 | 115 | $character = $text{$i}; |
116 | - if($character == '"') { |
|
116 | + if ($character == '"') { |
|
117 | 117 | $inString = !$inString; |
118 | - } else if($character == '*') { |
|
118 | + } else if ($character == '*') { |
|
119 | 119 | $inComment = true; |
120 | - } else if($character == "\n" ) { |
|
120 | + } else if ($character == "\n") { |
|
121 | 121 | $inComment = false; |
122 | - } else if(!$inString && !$inComment && $character == ' ') { |
|
123 | - while($i+2 < strlen($text) && $text{$i+1} == ' ') { |
|
122 | + } else if (!$inString && !$inComment && $character == ' ') { |
|
123 | + while ($i+2 < strlen($text) && $text{$i+1} == ' ') { |
|
124 | 124 | $i++; |
125 | 125 | } |
126 | 126 | } |
127 | 127 | $newString[] = $character; |
128 | 128 | } |
129 | - return trim(implode('',$newString)); |
|
129 | + return trim(implode('', $newString)); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /// @endcond |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | */ |
141 | 141 | private function ScanForSubroutines() { |
142 | 142 | //expects $scriptLines to be filled out |
143 | - foreach($this->scriptLines as $line) { |
|
144 | - $words = explode(' ',strtolower($line)); |
|
145 | - if($words[0] == 'subr') { |
|
143 | + foreach ($this->scriptLines as $line) { |
|
144 | + $words = explode(' ', strtolower($line)); |
|
145 | + if ($words[0] == 'subr') { |
|
146 | 146 | $this->scriptSubroutines[] = $words[1]; |
147 | 147 | } |
148 | 148 | } |
@@ -158,20 +158,20 @@ discard block |
||
158 | 158 | * CAOS highlighted and contains a lot of strange logic. |
159 | 159 | */ |
160 | 160 | private function HighlightNextLine() { |
161 | - if(sizeof($this->scriptLines) <= $this->currentLine) { |
|
161 | + if (sizeof($this->scriptLines) <= $this->currentLine) { |
|
162 | 162 | return false; |
163 | 163 | } |
164 | 164 | $line = $this->scriptLines[$this->currentLine]; |
165 | 165 | //$line = $this->SmartRemoveMultipleSpaces($line); |
166 | - if(strlen($line) == 0 && $this->currentIndent > 0) { |
|
166 | + if (strlen($line) == 0 && $this->currentIndent > 0) { |
|
167 | 167 | $highlightedLine = $this->CreateIndentForThisLine('')."\n"; |
168 | 168 | $this->currentLine++; |
169 | 169 | return $highlightedLine; |
170 | - } else if(strlen($line) == 0) { |
|
170 | + } else if (strlen($line) == 0) { |
|
171 | 171 | $this->currentLine++; |
172 | 172 | return ''; |
173 | 173 | } |
174 | - $words = explode(' ',$line); |
|
174 | + $words = explode(' ', $line); |
|
175 | 175 | |
176 | 176 | $this->SetIndentForThisLine($words[0]); |
177 | 177 | |
@@ -182,83 +182,83 @@ discard block |
||
182 | 182 | $firstToken = ''; |
183 | 183 | |
184 | 184 | //if last line is a comment and this line starts with scrp set last line's indent to 0 (remove whitespace at front) |
185 | - if(in_array($words[0],array('scrp','rscr'))) { |
|
186 | - if(!empty($this->scriptLines[$this->currentLine-1])) { |
|
187 | - if($this->scriptLines[$this->currentLine-1]{0} == '*') { |
|
185 | + if (in_array($words[0], array('scrp', 'rscr'))) { |
|
186 | + if (!empty($this->scriptLines[$this->currentLine-1])) { |
|
187 | + if ($this->scriptLines[$this->currentLine-1]{0} == '*') { |
|
188 | 188 | $this->highlightedLines[$this->currentLine-1] = ltrim($this->highlightedLines[$this->currentLine-1]); |
189 | 189 | } |
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
193 | - for($this->currentWord=0;$this->currentWord<sizeof($words);$this->currentWord++) { |
|
193 | + for ($this->currentWord = 0; $this->currentWord < sizeof($words); $this->currentWord++) { |
|
194 | 194 | |
195 | 195 | $word = $words[$this->currentWord]; |
196 | 196 | $highlightedWord = $word; |
197 | - if($inString) { |
|
198 | - if($this->currentWord == sizeof($words)-1) { |
|
199 | - if(strpos($word,'"') === false) { |
|
197 | + if ($inString) { |
|
198 | + if ($this->currentWord == sizeof($words)-1) { |
|
199 | + if (strpos($word, '"') === false) { |
|
200 | 200 | $highlightedWord = htmlentities($word).'</span>'; |
201 | - $highlightedLineBeforeString = substr($highlightedLine,0,$whenStringBegan); |
|
202 | - $highlightedLineAfterString = substr($highlightedLine,$whenStringBegan); |
|
201 | + $highlightedLineBeforeString = substr($highlightedLine, 0, $whenStringBegan); |
|
202 | + $highlightedLineAfterString = substr($highlightedLine, $whenStringBegan); |
|
203 | 203 | $highlightedLineAfterString .= $highlightedWord; |
204 | - $highlightedLineAfterString = str_replace('<span class="string">','<span class="error">',$highlightedLineAfterString); |
|
204 | + $highlightedLineAfterString = str_replace('<span class="string">', '<span class="error">', $highlightedLineAfterString); |
|
205 | 205 | $highlightedLine = $highlightedLineBeforeString.$highlightedLineAfterString; |
206 | 206 | $inString = false; |
207 | 207 | continue; |
208 | 208 | |
209 | 209 | } |
210 | 210 | } |
211 | - if(($position = strpos($word,'"')) !== false) { |
|
212 | - $firstHalf = substr($word,0,$position); |
|
213 | - $secondHalf = substr($word,$position+1); |
|
211 | + if (($position = strpos($word, '"')) !== false) { |
|
212 | + $firstHalf = substr($word, 0, $position); |
|
213 | + $secondHalf = substr($word, $position+1); |
|
214 | 214 | |
215 | 215 | $highlightedWord = htmlentities($firstHalf).'"</span>'; //end the string |
216 | - if($secondHalf != '') { |
|
216 | + if ($secondHalf != '') { |
|
217 | 217 | $highlightedWord .= '<span class="error">'.htmlentities($secondHalf).'</span>'; |
218 | 218 | } |
219 | - $inString=false; |
|
219 | + $inString = false; |
|
220 | 220 | } else { |
221 | 221 | $highlightedLine .= $word.' '; |
222 | 222 | continue; |
223 | 223 | } |
224 | - } else if($inByteString) { |
|
225 | - if($this->currentWord == sizeof($words)-1) { |
|
226 | - if(strpos($word,']') === false) { |
|
224 | + } else if ($inByteString) { |
|
225 | + if ($this->currentWord == sizeof($words)-1) { |
|
226 | + if (strpos($word, ']') === false) { |
|
227 | 227 | $highlightedWord = htmlentities($word).'</span>'; |
228 | - $highlightedLineBeforeString = substr($highlightedLine,0,$whenStringBegan); |
|
229 | - $highlightedLineAfterString = substr($highlightedLine,$whenStringBegan); |
|
228 | + $highlightedLineBeforeString = substr($highlightedLine, 0, $whenStringBegan); |
|
229 | + $highlightedLineAfterString = substr($highlightedLine, $whenStringBegan); |
|
230 | 230 | $highlightedLineAfterString .= $highlightedWord; |
231 | - $highlightedLineAfterString = str_replace('<span class="bytestring">','<span class="error">',$highlightedLineAfterString); |
|
231 | + $highlightedLineAfterString = str_replace('<span class="bytestring">', '<span class="error">', $highlightedLineAfterString); |
|
232 | 232 | $highlightedLine = $highlightedLineBeforeString.$highlightedLineAfterString; |
233 | 233 | continue; |
234 | 234 | } |
235 | 235 | } |
236 | - if(($position = strpos($word,']')) !== false) { |
|
237 | - $firstHalf = substr($word,0,$position); |
|
238 | - $secondHalf = substr($word,$position+1); |
|
236 | + if (($position = strpos($word, ']')) !== false) { |
|
237 | + $firstHalf = substr($word, 0, $position); |
|
238 | + $secondHalf = substr($word, $position+1); |
|
239 | 239 | |
240 | 240 | $highlightedWord = htmlentities($firstHalf).']</span>'; //end the string |
241 | - if($secondHalf != '') { |
|
241 | + if ($secondHalf != '') { |
|
242 | 242 | $highlightedWord .= '<span class="error">'.htmlentities($secondHalf).'</span>'; |
243 | 243 | } |
244 | - $inByteString=false; |
|
244 | + $inByteString = false; |
|
245 | 245 | } else { |
246 | 246 | $highlightedLine .= $word.' '; |
247 | 247 | continue; |
248 | 248 | } |
249 | - } else if($firstToken != '') { |
|
249 | + } else if ($firstToken != '') { |
|
250 | 250 | //sort out unquoted strings |
251 | - if($this->currentWord == 1) { |
|
252 | - if($firstToken == 'subr') { |
|
253 | - if(strlen($word) == 4 || $this->scriptFormat != FORMAT_C2) { |
|
251 | + if ($this->currentWord == 1) { |
|
252 | + if ($firstToken == 'subr') { |
|
253 | + if (strlen($word) == 4 || $this->scriptFormat != FORMAT_C2) { |
|
254 | 254 | $highlightedWord = '<span class="label">'.$word.'</span>'; |
255 | 255 | } else { |
256 | 256 | $highlightedWord = '<span class="error">'.$word.'</span>'; |
257 | 257 | } |
258 | - } else if($firstToken == 'gsub') { |
|
259 | - if(in_array($word,$this->scriptSubroutines)) { |
|
258 | + } else if ($firstToken == 'gsub') { |
|
259 | + if (in_array($word, $this->scriptSubroutines)) { |
|
260 | 260 | //C3/DS allow for any length of subroutine name, C2 and C1 probably only allow 4-character names. |
261 | - if(in_array($this->scriptFormat,array(FORMAT_C3,FORMAT_DS)) || strlen($word) == 4) { |
|
261 | + if (in_array($this->scriptFormat, array(FORMAT_C3, FORMAT_DS)) || strlen($word) == 4) { |
|
262 | 262 | $highlightedWord = '<span class="label">'.$word.'</span>'; |
263 | 263 | } else { |
264 | 264 | $highlightedWord = '<span class="error">'.$word.'</span>'; |
@@ -267,29 +267,29 @@ discard block |
||
267 | 267 | $highlightedWord = '<span class="error">'.$word.'</span>'; |
268 | 268 | } |
269 | 269 | } |
270 | - if($this->scriptFormat == FORMAT_C2) { |
|
271 | - if(in_array(strtolower($firstToken),array('tokn','snde','sndc','sndl','sndq','plbs'))) { |
|
272 | - if(strlen($word) == 4) { |
|
270 | + if ($this->scriptFormat == FORMAT_C2) { |
|
271 | + if (in_array(strtolower($firstToken), array('tokn', 'snde', 'sndc', 'sndl', 'sndq', 'plbs'))) { |
|
272 | + if (strlen($word) == 4) { |
|
273 | 273 | $highlightedWord = '<span class="string">'.$word.'</span>'; |
274 | 274 | } else { |
275 | 275 | $highlightedWord = '<span class="error">'.$word.'</span>'; |
276 | 276 | } |
277 | 277 | } |
278 | 278 | } |
279 | - } else if($this->currentWord == 2) { |
|
280 | - if($this->scriptFormat == 'C2') { |
|
281 | - if(preg_match('/^new: (scen|simp|cbtn|comp|vhcl|lift|bkbd|cbub)$/i',$firstToken)) { |
|
282 | - if(strlen($word) == 4) { |
|
279 | + } else if ($this->currentWord == 2) { |
|
280 | + if ($this->scriptFormat == 'C2') { |
|
281 | + if (preg_match('/^new: (scen|simp|cbtn|comp|vhcl|lift|bkbd|cbub)$/i', $firstToken)) { |
|
282 | + if (strlen($word) == 4) { |
|
283 | 283 | $highlightedWord = '<span class="string">'.$word.'</span>'; |
284 | 284 | } else { |
285 | 285 | $highlightedWord = '<span class="error">'.$word.'</span>'; |
286 | 286 | } |
287 | 287 | } |
288 | 288 | } |
289 | - } else if($this->currentWord == sizeof($words)-1) { |
|
290 | - if($this->scriptFormat == 'C2') { |
|
291 | - if(strtolower($firstToken) == 'rmsc') { |
|
292 | - if(strlen($word) == 4) { |
|
289 | + } else if ($this->currentWord == sizeof($words)-1) { |
|
290 | + if ($this->scriptFormat == 'C2') { |
|
291 | + if (strtolower($firstToken) == 'rmsc') { |
|
292 | + if (strlen($word) == 4) { |
|
293 | 293 | $highlightedWord = '<span class="string">'.$word.'</span>'; |
294 | 294 | } else { |
295 | 295 | $highlightedWord = '<span class="error">'.$word.'</span>'; |
@@ -298,17 +298,17 @@ discard block |
||
298 | 298 | } |
299 | 299 | } |
300 | 300 | } |
301 | - if($highlightedWord == $word) { |
|
301 | + if ($highlightedWord == $word) { |
|
302 | 302 | $highlightedWord = $this->TryToHighlightToken($word); |
303 | - if($this->currentWord == 0) { |
|
303 | + if ($this->currentWord == 0) { |
|
304 | 304 | $firstToken = $word; |
305 | 305 | } |
306 | 306 | //Highlight two-word block. |
307 | - if($highlightedWord == $word && $this->currentWord < sizeof($words)-1) { |
|
307 | + if ($highlightedWord == $word && $this->currentWord < sizeof($words)-1) { |
|
308 | 308 | $wordPair = $word.' '.$words[$this->currentWord+1]; |
309 | 309 | $highlightedWord = $this->TryToHighlightToken($wordPair); |
310 | - if($highlightedWord != $wordPair) { |
|
311 | - if($this->currentWord == 0) { |
|
310 | + if ($highlightedWord != $wordPair) { |
|
311 | + if ($this->currentWord == 0) { |
|
312 | 312 | $firstToken = $wordPair; |
313 | 313 | } |
314 | 314 | $this->currentWord++; |
@@ -316,46 +316,46 @@ discard block |
||
316 | 316 | $highlightedWord = $word; |
317 | 317 | } |
318 | 318 | } |
319 | - if($highlightedWord == $word) { //invalid caos command |
|
320 | - if($word{0} == '"' && $this->scriptFormat != FORMAT_C2) { //if it begins a string. (C2 has no strings) |
|
319 | + if ($highlightedWord == $word) { //invalid caos command |
|
320 | + if ($word{0} == '"' && $this->scriptFormat != FORMAT_C2) { //if it begins a string. (C2 has no strings) |
|
321 | 321 | $whenStringBegan = strlen($highlightedLine); |
322 | 322 | $highlightedWord = '<span class="string">'.htmlentities($word); |
323 | - if($word{strlen($word)-1} == '"') { |
|
323 | + if ($word{strlen($word)-1} == '"') { |
|
324 | 324 | $highlightedWord .= '</span>'; //end the string |
325 | 325 | $inString = false; |
326 | - } else if($this->currentWord == sizeof($words)-1) { |
|
326 | + } else if ($this->currentWord == sizeof($words)-1) { |
|
327 | 327 | $highlightedWord = '<span class="error">'.htmlentities($word).'</span>'; |
328 | 328 | $inString = false; |
329 | 329 | } else { |
330 | 330 | $inString = true; |
331 | 331 | } |
332 | - } else if($word{0} == '[') { //begins a bytestring |
|
332 | + } else if ($word{0} == '[') { //begins a bytestring |
|
333 | 333 | $highlightedWord = '<span class="bytestring">'.htmlentities($word); |
334 | 334 | $whenStringBegan = strlen($highlightedLine); |
335 | - if($this->scriptFormat == 'C2') { |
|
335 | + if ($this->scriptFormat == 'C2') { |
|
336 | 336 | //c2 bytestrings are part of the original term, on they're own they're wrong! |
337 | 337 | $highlightedWord = '<span class="error">'.htmlentities($word); |
338 | 338 | } |
339 | - if($word{strlen($word)-1} == ']') { |
|
339 | + if ($word{strlen($word)-1} == ']') { |
|
340 | 340 | $highlightedWord .= '</span>'; |
341 | 341 | $inByteString = false; |
342 | - } else if($this->currentWord == sizeof($words)-1) { |
|
342 | + } else if ($this->currentWord == sizeof($words)-1) { |
|
343 | 343 | $highlightedWord = '<span class="error">'.htmlentities($word).'</span>'; |
344 | 344 | $inByteString = false; |
345 | 345 | } else { |
346 | 346 | $inByteString = true; |
347 | 347 | } |
348 | - } else if(is_numeric($word)) { |
|
348 | + } else if (is_numeric($word)) { |
|
349 | 349 | $highlightedWord = '<span class="number">'.htmlentities($word).'</span>'; |
350 | - } else if($word{0} == '*') { // because of SmartRemoveMultipleSpaces, prints exactly as written :) |
|
350 | + } else if ($word{0} == '*') { // because of SmartRemoveMultipleSpaces, prints exactly as written :) |
|
351 | 351 | $highlightedWord = '<span class="comment">'; |
352 | - for($i=$this->currentWord;$i<sizeof($words);$i++) |
|
352 | + for ($i = $this->currentWord; $i < sizeof($words); $i++) |
|
353 | 353 | { |
354 | - if($i!=$this->currentWord) |
|
354 | + if ($i != $this->currentWord) |
|
355 | 355 | { |
356 | - $highlightedWord.=' '; |
|
356 | + $highlightedWord .= ' '; |
|
357 | 357 | } |
358 | - $highlightedWord.= htmlentities($words[$i]); |
|
358 | + $highlightedWord .= htmlentities($words[$i]); |
|
359 | 359 | } |
360 | 360 | $highlightedWord .= '</span>'; |
361 | 361 | $highlightedLine .= $highlightedWord; |
@@ -387,27 +387,27 @@ discard block |
||
387 | 387 | |
388 | 388 | //first position commands + flow controls only |
389 | 389 | //2nd position commands + command variables + variables only. |
390 | - if(in_array($lcword,$this->caosCommands)) { |
|
390 | + if (in_array($lcword, $this->caosCommands)) { |
|
391 | 391 | $word = '<span class="command">'.htmlentities($word).'</span>'; |
392 | - } else if(in_array($lcword,$this->caosVariables)) { |
|
392 | + } else if (in_array($lcword, $this->caosVariables)) { |
|
393 | 393 | $word = '<span class="variable">'.htmlentities($word).'</span>'; |
394 | 394 | //vaXX, ovXX |
395 | - } else if(in_array($this->scriptFormat,array('C2','C3','DS')) && preg_match("/^(va|ov)[0-9]{2}$/", $lcword)) { |
|
395 | + } else if (in_array($this->scriptFormat, array('C2', 'C3', 'DS')) && preg_match("/^(va|ov)[0-9]{2}$/", $lcword)) { |
|
396 | 396 | $word = '<span class="variable">'.htmlentities($word).'</span>'; |
397 | 397 | //mvXX |
398 | - } else if(in_array($this->scriptFormat,array('C3','DS')) && preg_match('/^(mv)[0-9]{2}$/',$lcword)) { |
|
398 | + } else if (in_array($this->scriptFormat, array('C3', 'DS')) && preg_match('/^(mv)[0-9]{2}$/', $lcword)) { |
|
399 | 399 | $word = '<span class="variable">'.htmlentities($word).'</span>'; |
400 | 400 | //obvX |
401 | - } else if(in_array($this->scriptFormat,array('C1','C2')) && preg_match('/^(obv)[0-9]$/',$lcword)) { |
|
401 | + } else if (in_array($this->scriptFormat, array('C1', 'C2')) && preg_match('/^(obv)[0-9]$/', $lcword)) { |
|
402 | 402 | $word = '<span class="variable">'.htmlentities($word).'</span>'; |
403 | - } else if($this->scriptFormat == 'C2' && preg_match('/^([Aa][Nn][Ii][Mm]|[Pp][Rr][Ll][Dd])(\[[0-9]+R?\])$/',$word,$matches)) { |
|
403 | + } else if ($this->scriptFormat == 'C2' && preg_match('/^([Aa][Nn][Ii][Mm]|[Pp][Rr][Ll][Dd])(\[[0-9]+R?\])$/', $word, $matches)) { |
|
404 | 404 | $word = '<span class="variable">'.strtolower($matches[1]).'</span><span class="bytestring">'.$matches[2].'</span>'; |
405 | - } else if(in_array($lcword,$this->caosOperators)) { |
|
405 | + } else if (in_array($lcword, $this->caosOperators)) { |
|
406 | 406 | $word = '<span class="operator">'.htmlentities($word).'</span>'; |
407 | - } else if(in_array($lcword,$this->caosFlowControls)) { |
|
407 | + } else if (in_array($lcword, $this->caosFlowControls)) { |
|
408 | 408 | $word = '<span class="flowcontrol">'.htmlentities($word).'</span>'; |
409 | - } else if(in_array($lcword,$this->caosCommandVariables)) { |
|
410 | - if($this->currentWord == 0) { |
|
409 | + } else if (in_array($lcword, $this->caosCommandVariables)) { |
|
410 | + if ($this->currentWord == 0) { |
|
411 | 411 | $word = '<span class="command">'.htmlentities($word).'</span>'; |
412 | 412 | } else { |
413 | 413 | $word = '<span class="variable">'.htmlentities($word).'</span>'; |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * @param $firstword The first word of the line |
427 | 427 | */ |
428 | 428 | private function SetIndentForThisLine($firstword) { |
429 | - switch($firstword) { |
|
429 | + switch ($firstword) { |
|
430 | 430 | case 'scrp': |
431 | 431 | case 'endm': |
432 | 432 | case 'rscr': |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | * Sets the indent for the next line |
457 | 457 | */ |
458 | 458 | private function SetIndentForNextLine($firstword) { |
459 | - switch($firstword) { |
|
459 | + switch ($firstword) { |
|
460 | 460 | case 'scrp': |
461 | 461 | case 'rscr': |
462 | 462 | case 'iscr': |
@@ -490,14 +490,14 @@ discard block |
||
490 | 490 | */ |
491 | 491 | private function CreateIndentForThisLine($firstword) { |
492 | 492 | $indent = ''; |
493 | - if(in_array($firstword,array('scrp','rscr'))) { |
|
494 | - if(!empty($this->previousLineCode)) { |
|
495 | - if($this->previousLineCode{0} != '*') { |
|
493 | + if (in_array($firstword, array('scrp', 'rscr'))) { |
|
494 | + if (!empty($this->previousLineCode)) { |
|
495 | + if ($this->previousLineCode{0} != '*') { |
|
496 | 496 | $indent = "\n"; |
497 | 497 | } |
498 | 498 | } |
499 | 499 | } |
500 | - for($i=0;$i<$this->currentIndent;$i++) { |
|
500 | + for ($i = 0; $i < $this->currentIndent; $i++) { |
|
501 | 501 | $indent .= "\t"; |
502 | 502 | } |
503 | 503 | return $indent; |
@@ -5,93 +5,93 @@ |
||
5 | 5 | /// @brief DS CAOS dictionary of tokens that can act like commands or variables |
6 | 6 | class DSCAOSCommandVariables { |
7 | 7 | /// @brief Returns an array of tokens. |
8 | - public static function GetTokens() { |
|
9 | - return array( |
|
10 | - 'attr', |
|
11 | - 'base', |
|
12 | - 'bhvr', |
|
13 | - 'clik', //I have no experience using this, but I think this is right. |
|
14 | - 'gall', |
|
15 | - 'hand', |
|
16 | - 'mira', |
|
17 | - 'paus', |
|
18 | - 'plne', |
|
19 | - 'pose', |
|
20 | - 'rnge', |
|
21 | - 'targ', |
|
22 | - 'tick', |
|
8 | + public static function GetTokens() { |
|
9 | + return array( |
|
10 | + 'attr', |
|
11 | + 'base', |
|
12 | + 'bhvr', |
|
13 | + 'clik', //I have no experience using this, but I think this is right. |
|
14 | + 'gall', |
|
15 | + 'hand', |
|
16 | + 'mira', |
|
17 | + 'paus', |
|
18 | + 'plne', |
|
19 | + 'pose', |
|
20 | + 'rnge', |
|
21 | + 'targ', |
|
22 | + 'tick', |
|
23 | 23 | |
24 | - //camera |
|
25 | - 'meta', |
|
26 | - 'trck', |
|
27 | - 'wdow', |
|
24 | + //camera |
|
25 | + 'meta', |
|
26 | + 'trck', |
|
27 | + 'wdow', |
|
28 | 28 | |
29 | - //compound |
|
30 | - 'page', |
|
31 | - 'ptxt', |
|
29 | + //compound |
|
30 | + 'page', |
|
31 | + 'ptxt', |
|
32 | 32 | |
33 | - //creatures |
|
34 | - 'aslp', |
|
35 | - 'dead', |
|
36 | - 'dirn', |
|
37 | - 'drea', |
|
38 | - 'face', |
|
39 | - 'ins#', |
|
40 | - 'mind', |
|
41 | - 'motr', |
|
42 | - 'norn', |
|
43 | - 'uncs', |
|
44 | - 'zomb', |
|
33 | + //creatures |
|
34 | + 'aslp', |
|
35 | + 'dead', |
|
36 | + 'dirn', |
|
37 | + 'drea', |
|
38 | + 'face', |
|
39 | + 'ins#', |
|
40 | + 'mind', |
|
41 | + 'motr', |
|
42 | + 'norn', |
|
43 | + 'uncs', |
|
44 | + 'zomb', |
|
45 | 45 | |
46 | - //files |
|
46 | + //files |
|
47 | 47 | |
48 | - //input |
|
49 | - 'pure', |
|
48 | + //input |
|
49 | + 'pure', |
|
50 | 50 | |
51 | - //map |
|
52 | - 'perm', |
|
51 | + //map |
|
52 | + 'perm', |
|
53 | 53 | |
54 | - //motion |
|
55 | - 'accg', |
|
56 | - 'admp', |
|
57 | - 'aero', |
|
58 | - 'avel', |
|
59 | - 'elas', |
|
60 | - 'fdmp', |
|
61 | - 'fric', |
|
62 | - 'fvel', |
|
63 | - 'sdmp', |
|
64 | - 'spin', |
|
65 | - 'svel', |
|
66 | - 'varc', |
|
54 | + //motion |
|
55 | + 'accg', |
|
56 | + 'admp', |
|
57 | + 'aero', |
|
58 | + 'avel', |
|
59 | + 'elas', |
|
60 | + 'fdmp', |
|
61 | + 'fric', |
|
62 | + 'fvel', |
|
63 | + 'sdmp', |
|
64 | + 'spin', |
|
65 | + 'svel', |
|
66 | + 'varc', |
|
67 | 67 | |
68 | - //ports |
|
68 | + //ports |
|
69 | 69 | |
70 | - //resources |
|
70 | + //resources |
|
71 | 71 | |
72 | - //caos |
|
72 | + //caos |
|
73 | 73 | |
74 | - //sounds |
|
75 | - 'vois', |
|
74 | + //sounds |
|
75 | + 'vois', |
|
76 | 76 | |
77 | - //time |
|
78 | - 'buzz', |
|
79 | - 'wpau', |
|
80 | - 'targ', |
|
77 | + //time |
|
78 | + 'buzz', |
|
79 | + 'wpau', |
|
80 | + 'targ', |
|
81 | 81 | |
82 | - //vehicles |
|
83 | - 'cabp', |
|
84 | - 'cabv', |
|
82 | + //vehicles |
|
83 | + 'cabp', |
|
84 | + 'cabv', |
|
85 | 85 | |
86 | - //world |
|
87 | - 'delw', |
|
88 | - 'load', |
|
86 | + //world |
|
87 | + 'delw', |
|
88 | + 'load', |
|
89 | 89 | |
90 | - //net |
|
91 | - 'net: line', |
|
92 | - 'net: pass' |
|
93 | - ); |
|
94 | - } |
|
90 | + //net |
|
91 | + 'net: line', |
|
92 | + 'net: pass' |
|
93 | + ); |
|
94 | + } |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /// @endcond |