code refactoring
- variable names - unused parameters
This commit is contained in:
@ -433,7 +433,9 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
||||
}
|
||||
}
|
||||
|
||||
usort($mapList, array($this, 'sortByKarma'));
|
||||
usort($mapList, function (Map $mapA, Map $mapB) {
|
||||
return ($mapA->karma - $mapB->karma);
|
||||
});
|
||||
if ($best) {
|
||||
$mapList = array_reverse($mapList);
|
||||
}
|
||||
@ -453,10 +455,9 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
||||
private function showMapListDate($newest, Player $player) {
|
||||
$maps = $this->maniaControl->mapManager->getMaps();
|
||||
|
||||
usort($maps, function ($a, $b) {
|
||||
return ($a->index - $b->index);
|
||||
usort($maps, function (Map $mapA, Map $mapB) {
|
||||
return ($mapA->index - $mapB->index);
|
||||
});
|
||||
|
||||
if ($newest) {
|
||||
$maps = array_reverse($maps);
|
||||
}
|
||||
@ -473,15 +474,4 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
||||
public function command_xList(array $chatCallback, Player $player) {
|
||||
$this->maniaControl->mapManager->mxList->showList($chatCallback, $player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper Function to sort Maps by Karma
|
||||
*
|
||||
* @param Map $a
|
||||
* @param Map $b
|
||||
* @return mixed
|
||||
*/
|
||||
private function sortByKarma(Map $a, Map $b) {
|
||||
return ($a->karma - $b->karma);
|
||||
}
|
||||
}
|
||||
|
@ -198,8 +198,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$headFrame = new Frame();
|
||||
$frame->add($headFrame);
|
||||
$headFrame->setY($height / 2 - 5);
|
||||
$x = -$width / 2;
|
||||
$array = array('Id' => $x + 5, 'Mx Id' => $x + 10, 'Map Name' => $x + 20, 'Author' => $x + 68, 'Karma' => $x + 115, 'Actions' => $width / 2 - 16);
|
||||
$posX = -$width / 2;
|
||||
$array = array('Id' => $posX + 5, 'Mx Id' => $posX + 10, 'Map Name' => $posX + 20, 'Author' => $posX + 68, 'Karma' => $posX + 115, 'Actions' => $width / 2 - 16);
|
||||
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
|
||||
|
||||
// Predefine description Label
|
||||
@ -214,11 +214,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$paging->setStartPageNumber($pageIndex + 1);
|
||||
|
||||
$index = 0;
|
||||
$id = 1 + $mapsBeginIndex;
|
||||
$y = $height / 2 - 10;
|
||||
$mapListId = 1 + $mapsBeginIndex;
|
||||
$posY = $height / 2 - 10;
|
||||
$pageFrame = null;
|
||||
|
||||
/** @var Map $map */
|
||||
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
|
||||
$mxIcon = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON);
|
||||
$mxIconHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER);
|
||||
@ -226,10 +225,11 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$mxIconGreenHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN_MOVER);
|
||||
|
||||
foreach ($mapList as $map) {
|
||||
/** @var Map $map */
|
||||
if ($index % self::MAX_MAPS_PER_PAGE === 0) {
|
||||
$pageFrame = new Frame();
|
||||
$frame->add($pageFrame);
|
||||
$y = $height / 2 - 10;
|
||||
$posY = $height / 2 - 10;
|
||||
$paging->addPage($pageFrame, $pageNumber);
|
||||
$pageNumber++;
|
||||
}
|
||||
@ -237,10 +237,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
// Map Frame
|
||||
$mapFrame = new Frame();
|
||||
$pageFrame->add($mapFrame);
|
||||
$mapFrame->setY($posY);
|
||||
$mapFrame->setZ(0.1);
|
||||
$mapFrame->setY($y);
|
||||
|
||||
if ($id % 2 !== 0) {
|
||||
if ($mapListId % 2 !== 0) {
|
||||
$lineQuad = new Quad_BgsPlayerCard();
|
||||
$mapFrame->add($lineQuad);
|
||||
$lineQuad->setSize($width, 4);
|
||||
@ -251,7 +251,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
if ($currentMap === $map) {
|
||||
$currentQuad = new Quad_Icons64x64_1();
|
||||
$mapFrame->add($currentQuad);
|
||||
$currentQuad->setX($x + 3.5);
|
||||
$currentQuad->setX($posX + 3.5);
|
||||
$currentQuad->setZ(0.2);
|
||||
$currentQuad->setSize(4, 4);
|
||||
$currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue);
|
||||
@ -266,7 +266,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$mxQuad->setSize(3, 3);
|
||||
$mxQuad->setImage($mxIcon);
|
||||
$mxQuad->setImageFocus($mxIconHover);
|
||||
$mxQuad->setX($x + 65);
|
||||
$mxQuad->setX($posX + 65);
|
||||
$mxQuad->setUrl($map->mx->pageurl);
|
||||
$mxQuad->setZ(0.01);
|
||||
$description = 'View $<' . $map->name . '$> on Mania-Exchange';
|
||||
@ -278,7 +278,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$mxQuad->setSize(3, 3);
|
||||
$mxQuad->setImage($mxIconGreen);
|
||||
$mxQuad->setImageFocus($mxIconGreenHover);
|
||||
$mxQuad->setX($x + 62);
|
||||
$mxQuad->setX($posX + 62);
|
||||
$mxQuad->setUrl($map->mx->pageurl);
|
||||
$mxQuad->setZ(0.01);
|
||||
$description = 'Update for $<' . $map->name . '$> available on Mania-Exchange!';
|
||||
@ -292,7 +292,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
}
|
||||
|
||||
// Display Maps
|
||||
$array = array($id => $x + 5, $mxId => $x + 10, Formatter::stripDirtyCodes($map->name) => $x + 20, $map->authorNick => $x + 68);
|
||||
$array = array($mapListId => $posX + 5, $mxId => $posX + 10, Formatter::stripDirtyCodes($map->name) => $posX + 20, $map->authorNick => $posX + 68);
|
||||
$labels = $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
|
||||
if (isset($labels[3])) {
|
||||
/** @var Label $label */
|
||||
@ -359,7 +359,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$eraseLabel->setText('x');
|
||||
$eraseLabel->setTextColor('a00');
|
||||
|
||||
$confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $map->uid, true);
|
||||
$confirmFrame = $this->buildConfirmFrame($maniaLink, $posY, $map->uid, true);
|
||||
$eraseLabel->addToggleFeature($confirmFrame);
|
||||
$description = 'Remove Map: $<' . $map->name . '$>';
|
||||
$eraseLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
@ -376,7 +376,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$switchLabel->setText('»');
|
||||
$switchLabel->setTextColor('0f0');
|
||||
|
||||
$confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $map->uid);
|
||||
$confirmFrame = $this->buildConfirmFrame($maniaLink, $posY, $map->uid);
|
||||
$switchLabel->addToggleFeature($confirmFrame);
|
||||
|
||||
$description = 'Switch Directly to Map: $<' . $map->name . '$>';
|
||||
@ -438,7 +438,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$karmaGauge = new Gauge();
|
||||
$mapFrame->add($karmaGauge);
|
||||
$karmaGauge->setZ(2);
|
||||
$karmaGauge->setX($x + 120);
|
||||
$karmaGauge->setX($posX + 120);
|
||||
$karmaGauge->setSize(20, 9);
|
||||
$karmaGauge->setDrawBg(false);
|
||||
$karma = floatval($karma);
|
||||
@ -449,7 +449,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$karmaLabel = new Label();
|
||||
$mapFrame->add($karmaLabel);
|
||||
$karmaLabel->setZ(2);
|
||||
$karmaLabel->setX($x + 120);
|
||||
$karmaLabel->setX($posX + 120);
|
||||
$karmaLabel->setSize(20 * 0.9, 5);
|
||||
$karmaLabel->setTextSize(0.9);
|
||||
$karmaLabel->setTextColor('000');
|
||||
@ -457,8 +457,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
}
|
||||
}
|
||||
|
||||
$y -= 4;
|
||||
$id++;
|
||||
$posY -= 4;
|
||||
$mapListId++;
|
||||
$index++;
|
||||
}
|
||||
|
||||
@ -494,12 +494,12 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
* Builds the confirmation frame
|
||||
*
|
||||
* @param ManiaLink $maniaLink
|
||||
* @param float $y
|
||||
* @param float $posY
|
||||
* @param bool $mapUid
|
||||
* @param bool $erase
|
||||
* @return Frame
|
||||
*/
|
||||
public function buildConfirmFrame(Manialink $maniaLink, $y, $mapUid, $erase = false) {
|
||||
public function buildConfirmFrame(Manialink $maniaLink, $posY, $mapUid, $erase = false) {
|
||||
// TODO: get rid of the confirm frame to decrease xml size & network usage
|
||||
|
||||
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
||||
@ -508,7 +508,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
|
||||
$confirmFrame = new Frame();
|
||||
$maniaLink->add($confirmFrame);
|
||||
$confirmFrame->setPosition($width / 2 + 6, $y);
|
||||
$confirmFrame->setPosition($width / 2 + 6, $posY);
|
||||
$confirmFrame->setVisible(false);
|
||||
|
||||
$quad = new Quad();
|
||||
|
@ -244,22 +244,21 @@ class MapManager implements CallbackListener {
|
||||
public function addMapFromMx($mapId, $login, $update = false) {
|
||||
if (is_numeric($mapId)) {
|
||||
// Check if map exists
|
||||
$self = $this;
|
||||
$this->maniaControl->mapManager->mxManager->getMapInfo($mapId, function (MXMapInfo $mapInfo) use (&$self, &$login, &$update) {
|
||||
$this->maniaControl->mapManager->mxManager->getMapInfo($mapId, function (MXMapInfo $mapInfo) use (&$login, &$update) {
|
||||
if (!$mapInfo || !isset($mapInfo->uploaded)) {
|
||||
// Invalid id
|
||||
$self->maniaControl->chat->sendError('Invalid MX-Id!', $login);
|
||||
$this->maniaControl->chat->sendError('Invalid MX-Id!', $login);
|
||||
return;
|
||||
}
|
||||
|
||||
// Download the file
|
||||
$self->maniaControl->fileReader->loadFile($mapInfo->downloadurl, function ($file, $error) use (&$self, &$login, &$mapInfo, &$update) {
|
||||
$this->maniaControl->fileReader->loadFile($mapInfo->downloadurl, function ($file, $error) use (&$login, &$mapInfo, &$update) {
|
||||
if (!$file || $error) {
|
||||
// Download error
|
||||
$self->maniaControl->chat->sendError("Download failed: '{$error}'!", $login);
|
||||
$this->maniaControl->chat->sendError("Download failed: '{$error}'!", $login);
|
||||
return;
|
||||
}
|
||||
$self->processMapFile($file, $mapInfo, $login, $update);
|
||||
$this->processMapFile($file, $mapInfo, $login, $update);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -379,9 +378,9 @@ class MapManager implements CallbackListener {
|
||||
$tempList = array();
|
||||
|
||||
try {
|
||||
$i = 0;
|
||||
while (true) {
|
||||
$maps = $this->maniaControl->client->getMapList(150, $i);
|
||||
$offset = 0;
|
||||
while ($this->maniaControl->client) {
|
||||
$maps = $this->maniaControl->client->getMapList(150, $offset);
|
||||
|
||||
foreach ($maps as $rpcMap) {
|
||||
if (array_key_exists($rpcMap->uId, $this->maps)) {
|
||||
@ -394,7 +393,7 @@ class MapManager implements CallbackListener {
|
||||
}
|
||||
}
|
||||
|
||||
$i += 150;
|
||||
$offset += 150;
|
||||
}
|
||||
} catch (IndexOutOfBoundException $e) {
|
||||
}
|
||||
@ -554,14 +553,14 @@ class MapManager implements CallbackListener {
|
||||
$lowerMapArray = array();
|
||||
$higherMapArray = array();
|
||||
|
||||
$i = 0;
|
||||
$index = 0;
|
||||
foreach ($this->maps as $map) {
|
||||
if ($i < $currentIndex) {
|
||||
if ($index < $currentIndex) {
|
||||
$lowerMapArray[] = $map->fileName;
|
||||
} else {
|
||||
$higherMapArray[] = $map->fileName;
|
||||
}
|
||||
$i++;
|
||||
$index++;
|
||||
}
|
||||
|
||||
$mapArray = array_merge($higherMapArray, $lowerMapArray);
|
||||
@ -708,10 +707,8 @@ class MapManager implements CallbackListener {
|
||||
|
||||
/**
|
||||
* Handle Script EndMap Callback
|
||||
*
|
||||
* @param string $mapUid
|
||||
*/
|
||||
public function handleScriptEndMap($mapUid) {
|
||||
public function handleScriptEndMap() {
|
||||
$this->endMap();
|
||||
}
|
||||
|
||||
|
@ -409,12 +409,12 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
* @return array
|
||||
*/
|
||||
public function getQueuedMapsRanking() {
|
||||
$i = 1;
|
||||
$index = 1;
|
||||
$queuedMaps = array();
|
||||
foreach ($this->queuedMaps as $queuedMap) {
|
||||
$map = $queuedMap[1];
|
||||
$queuedMaps[$map->uid] = $i;
|
||||
$i++;
|
||||
$queuedMaps[$map->uid] = $index;
|
||||
$index++;
|
||||
}
|
||||
return $queuedMaps;
|
||||
}
|
||||
|
Reference in New Issue
Block a user