player cache instead of own data array

This commit is contained in:
Steffen Schröder 2014-05-18 16:27:08 +02:00
parent 32259585bd
commit c088a79041

View File

@ -52,12 +52,13 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
const MAX_PAGES_PER_CHUNK = 2; const MAX_PAGES_PER_CHUNK = 2;
const DEFAULT_KARMA_PLUGIN = 'MCTeam\KarmaPlugin'; const DEFAULT_KARMA_PLUGIN = 'MCTeam\KarmaPlugin';
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin'; const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
const CACHE_CURRENT_PAGE = 'CurrentPage';
const WIDGET_NAME = 'MapList';
/* /*
* Private Properties * Private Properties
*/ */
private $maniaControl = null; private $maniaControl = null;
private $playerCurrentPage = array();
/** /**
* Create a new MapList Instance * Create a new MapList Instance
@ -99,7 +100,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
*/ */
public function checkUpdates(array $chatCallback, Player $player) { public function checkUpdates(array $chatCallback, Player $player) {
// Update Mx Infos // Update Mx Infos
$this->maniaControl->mapManager->mxManager->fetchManiaExchangeMapInformations(); $this->maniaControl->mapManager->mxManager->fetchManiaExchangeMapInformation();
// Reshow the Maplist // Reshow the Maplist
$this->showMapList($player); $this->showMapList($player);
@ -117,14 +118,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight(); $height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
if ($pageIndex < 0) { if ($pageIndex < 0) {
if (isset($this->playerCurrentPage[$player->login])) { $pageIndex = (int)$player->getCache($this, self::CACHE_CURRENT_PAGE);
$pageIndex = $this->playerCurrentPage[$player->login];
} else {
$pageIndex = 0;
}
} }
$this->playerCurrentPage[$player->login] = $pageIndex; $player->setCache($this, self::CACHE_CURRENT_PAGE, $pageIndex);
$queueBuffer = $this->maniaControl->mapManager->mapQueue->getQueueBuffer(); $queueBuffer = $this->maniaControl->mapManager->mapQueue->getQueueBuffer();
$chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex); $chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex);
$mapsBeginIndex = $this->getChunkMapsBeginIndex($chunkIndex); $mapsBeginIndex = $this->getChunkMapsBeginIndex($chunkIndex);
@ -216,7 +213,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK; $pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK;
$paging->setStartPageNumber($pageIndex + 1); $paging->setStartPageNumber($pageIndex + 1);
$index = 0; $index = 0;
$id = 1 + $mapsBeginIndex; $id = 1 + $mapsBeginIndex;
$y = $height / 2 - 10; $y = $height / 2 - 10;
$pageFrame = null; $pageFrame = null;
@ -467,7 +464,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$index++; $index++;
} }
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'MapList'); $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, self::WIDGET_NAME);
} }
/** /**
@ -562,8 +559,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
*/ */
public function handleWidgetOpened(Player $player, $openedWidget) { public function handleWidgetOpened(Player $player, $openedWidget) {
// unset when another main widget got opened // unset when another main widget got opened
if ($openedWidget != 'MapList') { if ($openedWidget !== self::WIDGET_NAME) {
unset($this->playerCurrentPage[$player->login]); $player->destroyCache($this, self::CACHE_CURRENT_PAGE);
} }
} }
@ -574,7 +571,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
*/ */
public function closeWidget(Player $player) { public function closeWidget(Player $player) {
// TODO: resolve duplicate with 'playerCloseWidget' // TODO: resolve duplicate with 'playerCloseWidget'
unset($this->playerCurrentPage[$player->login]); $player->destroyCache($this, self::CACHE_CURRENT_PAGE);
} }
/** /**
@ -668,7 +665,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @param Player $player * @param Player $player
*/ */
public function playerCloseWidget(Player $player) { public function playerCloseWidget(Player $player) {
unset($this->playerCurrentPage[$player->login]); $player->destroyCache($this, self::CACHE_CURRENT_PAGE);
$this->maniaControl->manialinkManager->closeWidget($player); $this->maniaControl->manialinkManager->closeWidget($player);
} }
@ -676,12 +673,12 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* Reopen the widget on Map Begin, MapListChanged, etc. * Reopen the widget on Map Begin, MapListChanged, etc.
*/ */
public function updateWidget() { public function updateWidget() {
foreach ($this->playerCurrentPage as $login => $pageIndex) { $players = $this->maniaControl->playerManager->getPlayers();
$player = $this->maniaControl->playerManager->getPlayer($login); foreach ($players as $player) {
if ($player) { /** @var Player $player */
$this->showMapList($player, null, $pageIndex); $currentPage = $player->getCache($this, self::CACHE_CURRENT_PAGE);
} else { if ($currentPage !== null) {
unset($this->playerCurrentPage[$login]); $this->showMapList($player, null, $currentPage);
} }
} }
} }