maplist optimations
This commit is contained in:
parent
ae80995be6
commit
7fa6a0beda
@ -89,11 +89,20 @@ class ManiaExchangeManager {
|
|||||||
$saveMapStatement->close();
|
$saveMapStatement->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch Map Information from Mania Exchange
|
* Fetch Map Information from Mania Exchange
|
||||||
|
* @param null $map
|
||||||
*/
|
*/
|
||||||
public function fetchManiaExchangeMapInformations() {
|
public function fetchManiaExchangeMapInformations($map = null) {
|
||||||
$maps = $this->maniaControl->mapManager->getMaps();
|
if(!$map){
|
||||||
|
//Fetch Informations for whole Maplist
|
||||||
|
$maps = $this->maniaControl->mapManager->getMaps();
|
||||||
|
}else{
|
||||||
|
//Fetch Information for a single map
|
||||||
|
$maps[] = $map;
|
||||||
|
}
|
||||||
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$mapIdString = '';
|
$mapIdString = '';
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ class MapManager implements CallbackListener {
|
|||||||
*/
|
*/
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
private $maps = array();
|
private $maps = array();
|
||||||
|
/** @var Map $currentMap */
|
||||||
private $currentMap = null;
|
private $currentMap = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,8 +165,9 @@ class MapManager implements CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Remove a Map
|
* Remove a Map
|
||||||
*
|
*
|
||||||
* @param string $uid
|
* @param \ManiaControl\Players\Player $admin
|
||||||
* @param bool $eraseFile
|
* @param string $uid
|
||||||
|
* @param bool $eraseFile
|
||||||
*/
|
*/
|
||||||
public function removeMap(Player $admin, $uid, $eraseFile = false) { //TODO erasefile?
|
public function removeMap(Player $admin, $uid, $eraseFile = false) { //TODO erasefile?
|
||||||
$map = $this->maps[$uid];
|
$map = $this->maps[$uid];
|
||||||
@ -183,17 +185,55 @@ class MapManager implements CallbackListener {
|
|||||||
unset($this->maps[$uid]);
|
unset($this->maps[$uid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restructures the Maplist
|
||||||
|
*/
|
||||||
|
public function restructureMapList() {
|
||||||
|
$currentIndex = $this->getMapIndex($this->currentMap);
|
||||||
|
|
||||||
|
//No RestructureNeeded
|
||||||
|
if($currentIndex < 14) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$lowerMapArray = array();
|
||||||
|
$higherMapArray = array();
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
foreach($this->maps as $map) {
|
||||||
|
/** @var Map $map */
|
||||||
|
if($i < $currentIndex) {
|
||||||
|
$lowerMapArray[] = $map->fileName;
|
||||||
|
} else {
|
||||||
|
$higherMapArray[] = $map->fileName;
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mapArray = array_merge($higherMapArray, $lowerMapArray);
|
||||||
|
|
||||||
|
if(!$this->maniaControl->client->query('ChooseNextMapList', $mapArray)) {
|
||||||
|
trigger_error("Error while restructuring the Maplist. " . $this->maniaControl->getClientErrorText());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shuffles the MapList
|
* Shuffles the MapList
|
||||||
*
|
*
|
||||||
|
* @param Player $admin
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function shuffleMapList($admin = null) {
|
public function shuffleMapList($admin = null) {
|
||||||
shuffle($this->maps);
|
$shuffledMaps = $this->maps;
|
||||||
|
shuffle($shuffledMaps);
|
||||||
|
|
||||||
$mapArray = array();
|
$mapArray = array();
|
||||||
|
|
||||||
foreach($this->maps as $map) {
|
foreach($shuffledMaps as $map) {
|
||||||
/** @var Map $map */
|
/** @var Map $map */
|
||||||
$mapArray[] = $map->fileName;
|
$mapArray[] = $map->fileName;
|
||||||
}
|
}
|
||||||
@ -211,6 +251,8 @@ class MapManager implements CallbackListener {
|
|||||||
$this->maniaControl->log($message, true);
|
$this->maniaControl->log($message, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Restructure if needed
|
||||||
|
$this->restructureMapList();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +340,13 @@ class MapManager implements CallbackListener {
|
|||||||
public function handleOnInit(array $callback) {
|
public function handleOnInit(array $callback) {
|
||||||
$this->updateFullMapList();
|
$this->updateFullMapList();
|
||||||
$this->fetchCurrentMap();
|
$this->fetchCurrentMap();
|
||||||
|
|
||||||
|
//Fetch Mx Infos
|
||||||
$this->mxManager->fetchManiaExchangeMapInformations();
|
$this->mxManager->fetchManiaExchangeMapInformations();
|
||||||
|
|
||||||
|
//Restructure Maplist
|
||||||
|
$this->restructureMapList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -337,8 +385,15 @@ class MapManager implements CallbackListener {
|
|||||||
$this->fetchCurrentMap();
|
$this->fetchCurrentMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Restructure MapList if id is over 15
|
||||||
|
$this->restructureMapList();
|
||||||
|
|
||||||
|
//Update the mx of the map (for update checks, etc.)
|
||||||
|
$this->mxManager->fetchManiaExchangeMapInformations($this->currentMap);
|
||||||
|
|
||||||
// Trigger own BeginMap callback
|
// Trigger own BeginMap callback
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_BEGINMAP, array(self::CB_BEGINMAP, $this->currentMap));
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_BEGINMAP, array(self::CB_BEGINMAP, $this->currentMap));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -358,6 +413,19 @@ class MapManager implements CallbackListener {
|
|||||||
return array_values($this->maps);
|
return array_values($this->maps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the MapIndex of a given map
|
||||||
|
*
|
||||||
|
* @param Map $map
|
||||||
|
* @internal param $uid
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getMapIndex(Map $map) {
|
||||||
|
$maps = $this->getMaps();
|
||||||
|
return array_search($map, $maps);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a Map from Mania Exchange
|
* Adds a Map from Mania Exchange
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user