Added buffer of recently played maps in mapqueue

This commit is contained in:
Max Klaversma 2014-04-28 15:26:08 +02:00 committed by Steffen Schröder
parent 75b1e2155a
commit cac3550856
2 changed files with 80 additions and 5 deletions

View File

@ -112,6 +112,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
$this->mapListShown[$player->login] = true;
$queueBuffer = $this->maniaControl->mapManager->mapQueue->getQueueBuffer();
// Get Maps
if (is_null($maps) && $maps != 'redirect') {
@ -331,12 +332,21 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$queueLabel->setX($width / 2 - 15);
$queueLabel->setZ(0.2);
$queueLabel->setSize(3, 3);
$queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid);
$queueLabel->setText('+');
$queueLabel->setTextColor('09f');
$description = 'Add $<' . $map->name . '$> to the Map Queue';
$queueLabel->addTooltipLabelFeature($descriptionLabel, $description);
if(in_array($map->uid, $queueBuffer)) {
if ($this->maniaControl->authenticationManager->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
$queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid);
}
$queueLabel->setTextColor('f00');
$description = '$<' . $map->name . '$> has recently been played!';
$queueLabel->addTooltipLabelFeature($descriptionLabel, $description);
} else {
$queueLabel->setTextColor('09f');
$queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid);
$description = 'Add $<' . $map->name . '$> to the Map Queue';
$queueLabel->addTooltipLabelFeature($descriptionLabel, $description);
}
}
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) {

View File

@ -4,6 +4,7 @@ namespace ManiaControl\Maps;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
@ -26,7 +27,9 @@ class MapQueue implements CallbackListener, CommandListener {
const SETTING_SKIP_MAPQUEUE_ADMIN = 'Skip Map when admin leaves';
const SETTING_MAPLIMIT_PLAYER = 'Maximum maps per player in the Map-Queue (-1 = unlimited)';
const SETTING_MAPLIMIT_ADMIN = 'Maximum maps per admin (Admin+) in the Map-Queue (-1 = unlimited)';
const SETTING_BUFFERSIZE = 'Size of the Map-Queue buffer (recently played maps)';
const SETTING_PERMISSION_CLEAR_MAPQUEUE = 'Clear Mapqueue';
const SETTING_PERMISSION_QUEUE_BUFFER = 'Queue maps in buffer';
const ADMIN_COMMAND_CLEAR_MAPQUEUE = 'clearmapqueue';
const ADMIN_COMMAND_CLEAR_JUKEBOX = 'clearjukebox';
@ -37,6 +40,7 @@ class MapQueue implements CallbackListener, CommandListener {
private $maniaControl = null;
private $queuedMaps = array();
private $nextMap = null;
private $buffer = array();
/**
* Create a new server MapQueue
@ -47,14 +51,18 @@ class MapQueue implements CallbackListener, CommandListener {
$this->maniaControl = $maniaControl;
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'endMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'beginMap');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
// Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE, true);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN, false);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAPLIMIT_PLAYER, 1);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAPLIMIT_ADMIN, -1);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_BUFFERSIZE, 10);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CLEAR_MAPQUEUE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_QUEUE_BUFFER, AuthenticationManager::AUTH_LEVEL_ADMIN);
//Register Admin Commands
$this->maniaControl->commandManager->registerCommandListener(self::ADMIN_COMMAND_CLEAR_JUKEBOX, $this, 'command_ClearMapQueue', true);
@ -62,6 +70,14 @@ class MapQueue implements CallbackListener, CommandListener {
$this->maniaControl->commandManager->registerCommandListener(array('jb', 'jukebox', 'mapqueue'), $this, 'command_MapQueue');
}
/**
* Adds current map to buffer on startup
*/
public function handleAfterInit() {
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
$this->buffer[] = $currentMap->uid;
}
/**
* Clears the map-queue via admin command clearmap queue
*
@ -73,6 +89,12 @@ class MapQueue implements CallbackListener, CommandListener {
$this->clearMapQueue($admin);
}
/**
* Handles the mapqueue/jukebox command
*
* @param array $chat
* @param Player $player
*/
public function command_MapQueue(array $chat, Player $player) {
$chatCommands = explode(' ', $chat[1][2]);
@ -89,6 +111,11 @@ class MapQueue implements CallbackListener, CommandListener {
}
}
/**
* Shows current mapqueue in the chat
*
* @param $player
*/
public function showMapQueue($player) {
if(count($this->queuedMaps) == 0) {
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
@ -105,6 +132,11 @@ class MapQueue implements CallbackListener, CommandListener {
$this->maniaControl->chat->sendInformation($message, $player->login);
}
/**
* Shows current mapqueue in a manialink
*
* @param $player
*/
public function showMapQueueManialink($player) {
if(count($this->queuedMaps) == 0) {
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
@ -119,6 +151,15 @@ class MapQueue implements CallbackListener, CommandListener {
$this->maniaControl->mapManager->mapList->showMapList($player, $maps);
}
/**
* Returns the current queue buffer
*
* @return array
*/
public function getQueueBuffer() {
return $this->buffer;
}
/**
* Clears the Map Queue
*
@ -209,6 +250,13 @@ class MapQueue implements CallbackListener, CommandListener {
}
//TODO recently maps not able to add to queue-amps setting, and management
// Check if map is in the buffer
if(in_array($uid, $this->buffer)) {
$this->maniaControl->chat->sendError('That map has recently been played!', $login);
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
return;
}
}
$map = $this->maniaControl->mapManager->getMapByUid($uid);
@ -288,6 +336,23 @@ class MapQueue implements CallbackListener, CommandListener {
$this->maniaControl->client->chooseNextMap($map->fileName);
}
/**
* Called on begin map
*
* @param Map $map
*/
public function beginMap(Map $map) {
if(in_array($map->uid, $this->buffer)) {
return;
}
if(count($this->buffer) >= $this->maniaControl->settingManager->getSetting($this, self::SETTING_BUFFERSIZE)) {
array_shift($this->buffer);
}
$this->buffer[] = $map->uid;
}
/**
* Returns the next Map if the next map is a queuedmap or null if it's not
*