Added buffer of recently played maps in mapqueue
This commit is contained in:
parent
75b1e2155a
commit
cac3550856
@ -112,6 +112,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
||||||
|
|
||||||
$this->mapListShown[$player->login] = true;
|
$this->mapListShown[$player->login] = true;
|
||||||
|
$queueBuffer = $this->maniaControl->mapManager->mapQueue->getQueueBuffer();
|
||||||
|
|
||||||
// Get Maps
|
// Get Maps
|
||||||
if (is_null($maps) && $maps != 'redirect') {
|
if (is_null($maps) && $maps != 'redirect') {
|
||||||
@ -331,12 +332,21 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$queueLabel->setX($width / 2 - 15);
|
$queueLabel->setX($width / 2 - 15);
|
||||||
$queueLabel->setZ(0.2);
|
$queueLabel->setZ(0.2);
|
||||||
$queueLabel->setSize(3, 3);
|
$queueLabel->setSize(3, 3);
|
||||||
$queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid);
|
|
||||||
$queueLabel->setText('+');
|
$queueLabel->setText('+');
|
||||||
$queueLabel->setTextColor('09f');
|
|
||||||
|
if(in_array($map->uid, $queueBuffer)) {
|
||||||
$description = 'Add $<' . $map->name . '$> to the Map Queue';
|
if ($this->maniaControl->authenticationManager->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
||||||
$queueLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
$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)) {
|
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) {
|
||||||
|
@ -4,6 +4,7 @@ namespace ManiaControl\Maps;
|
|||||||
|
|
||||||
use ManiaControl\Admin\AuthenticationManager;
|
use ManiaControl\Admin\AuthenticationManager;
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
use ManiaControl\Commands\CommandListener;
|
use ManiaControl\Commands\CommandListener;
|
||||||
use ManiaControl\Formatter;
|
use ManiaControl\Formatter;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
@ -26,7 +27,9 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
const SETTING_SKIP_MAPQUEUE_ADMIN = 'Skip Map when admin leaves';
|
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_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_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_CLEAR_MAPQUEUE = 'Clear Mapqueue';
|
||||||
|
const SETTING_PERMISSION_QUEUE_BUFFER = 'Queue maps in buffer';
|
||||||
|
|
||||||
const ADMIN_COMMAND_CLEAR_MAPQUEUE = 'clearmapqueue';
|
const ADMIN_COMMAND_CLEAR_MAPQUEUE = 'clearmapqueue';
|
||||||
const ADMIN_COMMAND_CLEAR_JUKEBOX = 'clearjukebox';
|
const ADMIN_COMMAND_CLEAR_JUKEBOX = 'clearjukebox';
|
||||||
@ -37,6 +40,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
private $queuedMaps = array();
|
private $queuedMaps = array();
|
||||||
private $nextMap = null;
|
private $nextMap = null;
|
||||||
|
private $buffer = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new server MapQueue
|
* Create a new server MapQueue
|
||||||
@ -47,14 +51,18 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
|
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'endMap');
|
$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
|
// Init settings
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE, true);
|
$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_SKIP_MAPQUEUE_ADMIN, false);
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAPLIMIT_PLAYER, 1);
|
$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_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_CLEAR_MAPQUEUE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||||
|
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_QUEUE_BUFFER, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||||
|
|
||||||
//Register Admin Commands
|
//Register Admin Commands
|
||||||
$this->maniaControl->commandManager->registerCommandListener(self::ADMIN_COMMAND_CLEAR_JUKEBOX, $this, 'command_ClearMapQueue', true);
|
$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');
|
$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
|
* Clears the map-queue via admin command clearmap queue
|
||||||
*
|
*
|
||||||
@ -73,6 +89,12 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
$this->clearMapQueue($admin);
|
$this->clearMapQueue($admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the mapqueue/jukebox command
|
||||||
|
*
|
||||||
|
* @param array $chat
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
public function command_MapQueue(array $chat, Player $player) {
|
public function command_MapQueue(array $chat, Player $player) {
|
||||||
$chatCommands = explode(' ', $chat[1][2]);
|
$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) {
|
public function showMapQueue($player) {
|
||||||
if(count($this->queuedMaps) == 0) {
|
if(count($this->queuedMaps) == 0) {
|
||||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
|
$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);
|
$this->maniaControl->chat->sendInformation($message, $player->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows current mapqueue in a manialink
|
||||||
|
*
|
||||||
|
* @param $player
|
||||||
|
*/
|
||||||
public function showMapQueueManialink($player) {
|
public function showMapQueueManialink($player) {
|
||||||
if(count($this->queuedMaps) == 0) {
|
if(count($this->queuedMaps) == 0) {
|
||||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
|
$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);
|
$this->maniaControl->mapManager->mapList->showMapList($player, $maps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current queue buffer
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getQueueBuffer() {
|
||||||
|
return $this->buffer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the Map Queue
|
* 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
|
//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);
|
$map = $this->maniaControl->mapManager->getMapByUid($uid);
|
||||||
|
|
||||||
@ -288,6 +336,23 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
$this->maniaControl->client->chooseNextMap($map->fileName);
|
$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
|
* Returns the next Map if the next map is a queuedmap or null if it's not
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user