From 7a9627f41d4f2ee08e9bca59229077ba12072849 Mon Sep 17 00:00:00 2001 From: kremsy Date: Sun, 12 Jan 2014 17:15:59 +0100 Subject: [PATCH] improvements on mapadd --- .../ManiaExchangeInfoSearcher.php | 6 +++--- application/core/Maps/MapManager.php | 20 +++++++++---------- application/plugins/CustomVotes.php | 8 ++++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/application/core/ManiaExchange/ManiaExchangeInfoSearcher.php b/application/core/ManiaExchange/ManiaExchangeInfoSearcher.php index 7e05de59..6d1514fc 100644 --- a/application/core/ManiaExchange/ManiaExchangeInfoSearcher.php +++ b/application/core/ManiaExchange/ManiaExchangeInfoSearcher.php @@ -52,7 +52,7 @@ class ManiaExchangeInfoSearcher { //TODO rename to ManiaExchangeManager * * @param $mxMapInfos */ - private function updateMapObjectWithManiaExchangeIds($mxMapInfos) { + public function updateMapObjectsWithManiaExchangeIds($mxMapInfos) { $mysqli = $this->maniaControl->database->mysqli; // Save map data $saveMapQuery = "UPDATE `" . MapManager::TABLE_MAPS . "` @@ -132,14 +132,14 @@ class ManiaExchangeInfoSearcher { //TODO rename to ManiaExchangeManager //if($id % self::MAPS_PER_MX_FETCH == 0) { if($id % 6 == 0) { //TODO 6 is temporary $maps = $this->getMaplistByMixedUidIdString($mapIdString); - $this->updateMapObjectWithManiaExchangeIds($maps); + $this->updateMapObjectsWithManiaExchangeIds($maps); $mapIdString = ''; } } if($mapIdString != '') { $maps = $this->getMaplistByMixedUidIdString($mapIdString); - $this->updateMapObjectWithManiaExchangeIds($maps); + $this->updateMapObjectsWithManiaExchangeIds($maps); } $fetchMapStatement->close(); diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index af340d11..43655aef 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -340,19 +340,16 @@ class MapManager implements CallbackListener { $title = strtolower(substr($serverInfo['TitleId'], 0, 2)); // Check if map exists - $url = "http://api.mania-exchange.com/{$title}/maps/{$mapId}?format=json"; + $mxMapInfos = $this->maniaControl->mapManager->mxInfoSearcher->getMaplistByMixedUidIdString($mapId); + $mapInfo = $mxMapInfos[0]; + /** @var MXMapInfo $mapInfo */ - $mapInfo = FileUtil::loadFile($url, "application/json"); - - if(!$mapInfo || strlen($mapInfo) <= 0) { + if(!$mapInfo || !isset($mapInfo->uploaded)) { // Invalid id $this->maniaControl->chat->sendError('Invalid MX-Id!', $login); return; } - $mapInfo = json_decode($mapInfo, true); - $mapInfo = $mapInfo[0]; - $url = "http://{$title}.mania-exchange.com/tracks/download/{$mapId}"; $file = FileUtil::loadFile($url); if(!$file) { @@ -361,7 +358,7 @@ class MapManager implements CallbackListener { return; } // Save map - $fileName = $mapId . '_' . $mapInfo['Name'] . '.Map.Gbx'; + $fileName = $mapId . '_' . $mapInfo->name . '.Map.Gbx'; $fileName = FileUtil::getClearedFileName($fileName); if(!file_put_contents($mapDir . $fileName, $file)) { // Save error @@ -387,12 +384,15 @@ class MapManager implements CallbackListener { $this->maniaControl->chat->sendError("Couldn't add map to match settings!", $login); return; } - $this->maniaControl->chat->sendSuccess('Map $<' . $mapInfo['Name'] . '$> added!'); + $this->maniaControl->chat->sendSuccess('Map $<' . $mapInfo->name . '$> added!'); $this->updateFullMapList(); + //Update Mx MapInfo + $this->maniaControl->mapManager->mxInfoSearcher->updateMapObjectsWithManiaExchangeIds($mxMapInfos); + // Queue requested Map - $this->maniaControl->mapManager->mapQueue->addMapToMapQueue($login, $mapInfo['MapUID']); + $this->maniaControl->mapManager->mapQueue->addMapToMapQueue($login, $mapInfo->uid); } // TODO: add local map by filename } diff --git a/application/plugins/CustomVotes.php b/application/plugins/CustomVotes.php index d9ac4b2e..73b5c319 100644 --- a/application/plugins/CustomVotes.php +++ b/application/plugins/CustomVotes.php @@ -486,7 +486,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP $quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig); $quad->setSize(5, 5); $quad->setAction(self::ACTION_NEGATIVE_VOTE); - $quad->setActionKey($quad::ACTIONKEY_F5); + $quad->setActionKey($quad::ACTIONKEY_F7); $label = new Label_Button(); $frame->add($label); @@ -497,19 +497,19 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP $label->setTextSize(1); $label->setSize(3, 3); $label->setTextColor("F00"); - $label->setText("F5"); + $label->setText("F7"); $quad = clone $quad; $frame->add($quad); $quad->setX($width / 2 - 4); $quad->setAction(self::ACTION_POSITIVE_VOTE); - $quad->setActionKey($quad::ACTIONKEY_F6); + $quad->setActionKey($quad::ACTIONKEY_F8); $label = clone $label; $frame->add($label); $label->setX($width / 2 - 4); $label->setTextColor("0F0"); - $label->setText("F6"); + $label->setText("F8"); // Send manialink $manialinkText = $maniaLink->render()->saveXML();