1
|
|
|
<?php |
2
|
|
|
require_once(dirname(__FILE__).'/COBBlock.php'); |
3
|
|
|
|
4
|
|
|
/// @brief Defines the bock to represent a file block in a COB file. |
5
|
|
|
class COBFileBlock extends COBBlock { |
6
|
|
|
|
7
|
|
|
/// @cond INTERNAL_DOCS |
8
|
|
|
// |
9
|
|
|
private $fileType; |
10
|
|
|
private $fileName; |
11
|
|
|
|
12
|
|
|
private $reserved; |
13
|
|
|
private $contents; |
14
|
|
|
|
15
|
|
|
/// @endcond |
16
|
|
|
|
17
|
|
|
/// @brief Constructs a new COBFileBlock |
18
|
|
|
/** |
19
|
|
|
* @param string $type The file type |
20
|
|
|
* @param $name The file name (including extension) |
21
|
|
|
* @param $contents The contents of the file |
22
|
|
|
*/ |
23
|
|
|
public function COBFileBlock($type, $name, $contents) { |
24
|
|
|
parent::COBBlock(COB_BLOCK_FILE); |
|
|
|
|
25
|
|
|
$this->fileType = $type; |
26
|
|
|
$this->fileName = $name; |
27
|
|
|
$this->contents = $contents; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/// @brief Add the reserved data associated with this file block |
31
|
|
|
/** |
32
|
|
|
* @param $reserved The reserved data |
33
|
|
|
*/ |
34
|
|
|
public function AddReserved($reserved) { |
35
|
|
|
$this->reserved = $reserved; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/// @brief Supposedly compiles the block into binary. Throws an error to say it's not implemented. |
39
|
|
|
/** @return string |
40
|
|
|
*/ |
41
|
|
|
public function Compile() { |
42
|
|
|
// TODO: implement |
43
|
|
|
throw new Exception("COBAgentBlock::Compile not implemented"); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/// @brief Get the name of the file |
47
|
|
|
public function GetName() { |
48
|
|
|
return $this->fileName; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/// @brief Get the file's type |
52
|
|
|
/** |
53
|
|
|
* @return 'sprite' or 'sound' - i.e. one of the |
|
|
|
|
54
|
|
|
* COB_DEPENDENCY_* constants in COBAgentBlock |
55
|
|
|
*/ |
56
|
|
|
public function GetFileType() { |
57
|
|
|
return $this->fileType; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/// @brief Get the contents of the file. |
61
|
|
|
public function GetContents() { |
62
|
|
|
return $this->contents; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/// @brief Get the reserved data |
66
|
|
|
/** |
67
|
|
|
* Reserved data was never officially used. |
68
|
|
|
* @return A 4-byte integer. |
69
|
|
|
*/ |
70
|
|
|
public function GetReserved() { |
71
|
|
|
return $this->reserved; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/// @cond INTERNAL_DOCS |
75
|
|
|
|
76
|
|
|
/// @brief Creates a new COBFileBlock from an IReader |
77
|
|
|
/** |
78
|
|
|
* @param $reader The reader the data's coming from |
79
|
|
|
*/ |
80
|
|
|
public static function CreateFromReader(IReader $reader) { |
81
|
|
|
$type = ($reader->ReadInt(2) == 0) ? 'sprite' : 'sound'; |
82
|
|
|
$reserved = $reader->ReadInt(4); |
83
|
|
|
$size = $reader->ReadInt(4); |
84
|
|
|
$fileName = $reader->ReadCString(); |
85
|
|
|
$contents = $reader->Read($size); |
86
|
|
|
$block = new COBFileBlock($type, $fileName, $contents); |
87
|
|
|
$block->AddReserved($reserved); |
88
|
|
|
return $block; |
89
|
|
|
} |
90
|
|
|
/// @endcond |
91
|
|
|
} |
92
|
|
|
?> |
|
|
|
|
93
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.