cleaned up map object

This commit is contained in:
kremsy 2014-01-12 20:56:25 +01:00 committed by Steffen Schröder
parent 57a6f40b74
commit 7ca3e8ded5
2 changed files with 32 additions and 29 deletions

View File

@ -3,7 +3,6 @@
namespace ManiaControl\Maps;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
/**
* Map Class
@ -35,20 +34,14 @@ class Map {
public $startTime = -1;
public $lastUpdate = 0;
/**
* Private Properties
*/
private $maniaControl = null;
/**
* Create a new Map Object from Rpc Data
*
* @param \ManiaControl\ManiaControl $maniaControl
* @param array $rpc_infos
* @param array $rpc_infos
* @internal param \ManiaControl\ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl, $rpc_infos = null) {
$this->maniaControl = $maniaControl;
$this->startTime = time();
public function __construct($rpc_infos = null) {
$this->startTime = time();
if(!$rpc_infos) {
return;
@ -68,20 +61,6 @@ class Map {
}
$this->authorNick = $this->authorLogin;
$mapsDirectory = $this->maniaControl->server->getMapsDirectory();
if($this->maniaControl->server->checkAccess($mapsDirectory)) {
$mapFetcher = new \GBXChallMapFetcher(true);
try {
$mapFetcher->processFile($mapsDirectory . $this->fileName);
$this->authorNick = FORMATTER::stripDirtyCodes($mapFetcher->authorNick);
$this->authorEInfo = $mapFetcher->authorEInfo;
$this->authorZone = $mapFetcher->authorZone;
$this->comment = $mapFetcher->comment;
} catch(\Exception $e) {
trigger_error($e->getMessage());
}
}
}
/**

View File

@ -6,6 +6,7 @@ use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\FileUtil;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
@ -183,6 +184,31 @@ class MapManager implements CallbackListener {
return true;
}
/**
* Initializes a Map
*
* @param $rpcMap
* @return Map
*/
public function initializeMap($rpcMap) {
$map = new Map($rpcMap);
$this->saveMap($map);
$mapsDirectory = $this->maniaControl->server->getMapsDirectory();
if($this->maniaControl->server->checkAccess($mapsDirectory)) {
$mapFetcher = new \GBXChallMapFetcher(true);
try {
$mapFetcher->processFile($mapsDirectory . $map->fileName);
$map->authorNick = FORMATTER::stripDirtyCodes($mapFetcher->authorNick);
$map->authorEInfo = $mapFetcher->authorEInfo;
$map->authorZone = $mapFetcher->authorZone;
$map->comment = $mapFetcher->comment;
} catch(\Exception $e) {
trigger_error($e->getMessage());
}
}
return $map;
}
/**
* Updates the full Map list, needed on Init, addMap and on ShuffleMaps
@ -201,8 +227,7 @@ class MapManager implements CallbackListener {
// Map already exists, only update index
$tempList[$rpcMap["UId"]] = $this->maps[$rpcMap["UId"]];
} else { // Insert Map Object
$map = new Map($this->maniaControl, $rpcMap);
$this->saveMap($map);
$map = $this->initializeMap($rpcMap);
$tempList[$map->uid] = $map;
}
}
@ -229,8 +254,7 @@ class MapManager implements CallbackListener {
$this->currentMap = $this->maps[$rpcMap["UId"]];
return true;
}
$map = new Map($this->maniaControl, $rpcMap);
$this->saveMap($map);
$map = $this->initializeMap($rpcMap);
$this->maps[$map->uid] = $map;
$this->currentMap = $map;
return true;