Added some documentation to resource packs namespace

This commit is contained in:
Dylan K. Taylor 2017-03-18 16:07:03 +00:00
parent cc0b4d888e
commit 0d37d0d896
3 changed files with 50 additions and 3 deletions

View File

@ -25,15 +25,46 @@ namespace pocketmine\resourcepacks;
interface ResourcePack{ interface ResourcePack{
/**
* Returns the human-readable name of the resource pack
* @return string
*/
public function getPackName() : string; public function getPackName() : string;
/**
* Returns the pack's UUID as a human-readable string
* @return string
*/
public function getPackId() : string; public function getPackId() : string;
/**
* Returns the size of the pack on disk in bytes.
* @return int
*/
public function getPackSize() : int; public function getPackSize() : int;
/**
* Returns a version number for the pack in the format major.minor.patch
* @return string
*/
public function getPackVersion() : string; public function getPackVersion() : string;
/**
* Returns the raw SHA256 sum of the compressed resource pack zip. This is used by clients to validate pack downloads.
* @return string byte-array length 32 bytes
*/
public function getSha256() : string; public function getSha256() : string;
/**
* Returns a chunk of the resource pack zip as a byte-array for sending to clients.
*
* Note that resource packs must **always** be in zip archive format for sending.
* A folder resource loader may need to perform on-the-fly compression for this purpose.
*
* @param int $start Offset to start reading the chunk from
* @param int $length Maximum length of data to return.
*
* @return string byte-array
*/
public function getPackChunk(int $start, int $length) : string; public function getPackChunk(int $start, int $length) : string;
} }

View File

@ -46,6 +46,10 @@ class ResourcePackManager{
/** @var ResourcePack[] */ /** @var ResourcePack[] */
private $uuidList = []; private $uuidList = [];
/**
* @param Server $server
* @param string $path Path to resource-packs directory.
*/
public function __construct(Server $server, string $path){ public function __construct(Server $server, string $path){
$this->server = $server; $this->server = $server;
$this->path = $path; $this->path = $path;
@ -103,6 +107,7 @@ class ResourcePackManager{
} }
/** /**
* Returns whether players must accept resource packs in order to join.
* @return bool * @return bool
*/ */
public function resourcePacksRequired() : bool{ public function resourcePacksRequired() : bool{
@ -110,6 +115,7 @@ class ResourcePackManager{
} }
/** /**
* Returns an array of resource packs in use, sorted in order of priority.
* @return ResourcePack[] * @return ResourcePack[]
*/ */
public function getResourceStack() : array{ public function getResourceStack() : array{
@ -117,8 +123,9 @@ class ResourcePackManager{
} }
/** /**
* @param string $id * Returns the resource pack matching the specified UUID string, or null if the ID was not recognized.
* *
* @param string $id
* @return ResourcePack|null * @return ResourcePack|null
*/ */
public function getPackById(string $id){ public function getPackById(string $id){
@ -126,6 +133,7 @@ class ResourcePackManager{
} }
/** /**
* Returns an array of pack IDs for packs currently in use.
* @return string[] * @return string[]
*/ */
public function getPackIdList() : array{ public function getPackIdList() : array{

View File

@ -25,13 +25,19 @@ namespace pocketmine\resourcepacks;
class ZippedResourcePack implements ResourcePack{ class ZippedResourcePack implements ResourcePack{
/**
* Performs basic validation checks on a resource pack's manifest.json.
* TODO: add more manifest validation
*
* @param \stdClass $manifest
* @return bool
*/
public static function verifyManifest(\stdClass $manifest){ public static function verifyManifest(\stdClass $manifest){
if(!isset($manifest->format_version) or !isset($manifest->header) or !isset($manifest->modules)){ if(!isset($manifest->format_version) or !isset($manifest->header) or !isset($manifest->modules)){
return false; return false;
} }
//Right now we don't care about anything else, only the stuff we're sending to clients. //Right now we don't care about anything else, only the stuff we're sending to clients.
//TODO: add more manifest validation
return return
isset($manifest->header->description) and isset($manifest->header->description) and
isset($manifest->header->name) and isset($manifest->header->name) and
@ -52,7 +58,9 @@ class ZippedResourcePack implements ResourcePack{
/** @var resource */ /** @var resource */
protected $fileResource; protected $fileResource;
/**
* @param string $zipPath Path to the resource pack zip
*/
public function __construct(string $zipPath){ public function __construct(string $zipPath){
$this->path = $zipPath; $this->path = $zipPath;