From 7ca3e8ded55b40236fb30538dd77e928786576f0 Mon Sep 17 00:00:00 2001 From: kremsy Date: Sun, 12 Jan 2014 20:56:25 +0100 Subject: [PATCH] cleaned up map object --- application/core/Maps/Map.php | 29 ++++--------------------- application/core/Maps/MapManager.php | 32 ++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/application/core/Maps/Map.php b/application/core/Maps/Map.php index 4fe04e77..855a3d78 100644 --- a/application/core/Maps/Map.php +++ b/application/core/Maps/Map.php @@ -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()); - } - } } /** diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index 43655aef..866e9c9b 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -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;