2013-11-12 15:48:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Maps;
|
|
|
|
|
2014-01-28 16:54:23 +01:00
|
|
|
use ManiaControl\ManiaExchange\MXMapInfo;
|
2014-05-13 16:40:05 +02:00
|
|
|
use ManiaControl\Utils\Formatter;
|
2013-11-12 15:48:25 +01:00
|
|
|
|
|
|
|
/**
|
2014-05-02 17:50:30 +02:00
|
|
|
* Map Model Class
|
2013-11-12 15:48:25 +01:00
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
|
|
|
* @copyright 2014 ManiaControl Team
|
2014-04-18 01:29:36 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2013-11-12 15:48:25 +01:00
|
|
|
*/
|
|
|
|
class Map {
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-01-06 15:54:22 +01:00
|
|
|
* Public Properties
|
2013-11-12 15:48:25 +01:00
|
|
|
*/
|
2013-11-25 02:01:15 +01:00
|
|
|
public $index = -1;
|
2013-11-12 15:48:25 +01:00
|
|
|
public $name = 'undefined';
|
2014-05-15 15:13:18 +02:00
|
|
|
public $rawName = null;
|
|
|
|
public $uid = null;
|
|
|
|
public $fileName = null;
|
|
|
|
public $environment = null;
|
2014-04-18 01:29:36 +02:00
|
|
|
public $authorTime = -1;
|
2014-01-05 13:56:05 +01:00
|
|
|
public $goldTime = -1;
|
|
|
|
public $copperPrice = -1;
|
2014-05-15 15:13:18 +02:00
|
|
|
public $mapType = null;
|
|
|
|
public $mapStyle = null;
|
2013-11-25 19:46:29 +01:00
|
|
|
public $nbCheckpoints = -1;
|
2014-02-16 22:38:14 +01:00
|
|
|
public $nbLaps = -1;
|
2014-01-09 23:21:44 +01:00
|
|
|
/** @var MXMapInfo $mx */
|
2013-11-12 15:48:25 +01:00
|
|
|
public $mx = null;
|
2014-05-15 15:13:18 +02:00
|
|
|
public $authorLogin = null;
|
|
|
|
public $authorNick = null;
|
|
|
|
public $authorZone = null;
|
|
|
|
public $authorEInfo = null;
|
|
|
|
public $comment = null;
|
|
|
|
public $titleUid = null;
|
2014-01-05 13:56:05 +01:00
|
|
|
public $startTime = -1;
|
2014-01-09 23:21:44 +01:00
|
|
|
public $lastUpdate = 0;
|
2014-05-11 16:02:29 +02:00
|
|
|
public $karma = null;
|
2014-04-18 01:29:36 +02:00
|
|
|
|
2013-11-12 15:48:25 +01:00
|
|
|
/**
|
2014-01-06 15:54:22 +01:00
|
|
|
* Create a new Map Object from Rpc Data
|
2013-11-12 15:48:25 +01:00
|
|
|
*
|
2014-01-16 18:08:32 +01:00
|
|
|
* @param \Maniaplanet\DedicatedServer\Structures\Map $mpMap
|
2014-01-12 20:56:25 +01:00
|
|
|
* @internal param \ManiaControl\ManiaControl $maniaControl
|
2013-11-12 15:48:25 +01:00
|
|
|
*/
|
2014-01-16 18:08:32 +01:00
|
|
|
public function __construct($mpMap = null) {
|
2014-01-12 20:56:25 +01:00
|
|
|
$this->startTime = time();
|
2014-01-08 21:52:42 +01:00
|
|
|
|
2014-02-16 00:51:30 +01:00
|
|
|
if (!$mpMap) {
|
2014-01-08 21:52:42 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-05-13 14:32:30 +02:00
|
|
|
$this->name = Formatter::stripDirtyCodes($mpMap->name);
|
2014-03-12 13:07:02 +01:00
|
|
|
$this->rawName = $mpMap->name;
|
2014-02-16 00:51:30 +01:00
|
|
|
$this->uid = $mpMap->uId;
|
|
|
|
$this->fileName = $mpMap->fileName;
|
|
|
|
$this->authorLogin = $mpMap->author;
|
|
|
|
$this->environment = $mpMap->environnement;
|
2014-04-18 01:29:36 +02:00
|
|
|
$this->authorTime = $mpMap->authorTime;
|
2014-02-16 00:51:30 +01:00
|
|
|
$this->goldTime = $mpMap->goldTime;
|
|
|
|
$this->copperPrice = $mpMap->copperPrice;
|
|
|
|
$this->mapType = $mpMap->mapType;
|
|
|
|
$this->mapStyle = $mpMap->mapStyle;
|
|
|
|
$this->nbCheckpoints = $mpMap->nbCheckpoints;
|
2014-02-16 22:38:14 +01:00
|
|
|
$this->nbLaps = $mpMap->nbLaps;
|
2014-01-08 21:52:42 +01:00
|
|
|
|
2013-12-16 08:38:35 +01:00
|
|
|
$this->authorNick = $this->authorLogin;
|
2014-01-09 23:21:44 +01:00
|
|
|
}
|
2014-01-08 21:52:42 +01:00
|
|
|
|
2014-05-09 18:42:17 +02:00
|
|
|
/**
|
|
|
|
* Get the escaped Map Name
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getEscapedName() {
|
|
|
|
return Formatter::escapeText($this->name);
|
|
|
|
}
|
|
|
|
|
2014-03-12 13:07:02 +01:00
|
|
|
/**
|
2014-06-14 14:32:29 +02:00
|
|
|
* Get the Game Type of the Map
|
2014-03-12 13:07:02 +01:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getGame() {
|
2014-05-02 17:50:30 +02:00
|
|
|
switch ($this->environment) {
|
2014-03-12 13:07:02 +01:00
|
|
|
case 'Storm':
|
2014-06-14 14:32:29 +02:00
|
|
|
return 'sm';
|
2014-03-12 13:07:02 +01:00
|
|
|
case 'Canyon':
|
|
|
|
case 'Stadium':
|
|
|
|
case 'Valley':
|
2014-06-14 14:32:29 +02:00
|
|
|
return 'tm';
|
2014-03-12 13:07:02 +01:00
|
|
|
}
|
2014-06-14 14:32:29 +02:00
|
|
|
return null;
|
2014-03-12 13:07:02 +01:00
|
|
|
}
|
|
|
|
|
2014-01-09 23:21:44 +01:00
|
|
|
/**
|
|
|
|
* Checks if a map Update is available
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function updateAvailable() {
|
2014-01-15 20:40:14 +01:00
|
|
|
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($this->mx && ($this->lastUpdate < strtotime($this->mx->updated) || $this->uid !== $this->mx->uid)) {
|
2014-01-09 23:21:44 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-12 15:48:25 +01:00
|
|
|
}
|
2014-05-11 20:33:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Var_Dump the Map
|
|
|
|
*/
|
|
|
|
public function dump() {
|
|
|
|
var_dump(json_decode(json_encode($this)));
|
|
|
|
}
|
2013-11-12 15:48:25 +01:00
|
|
|
}
|