Made some changes to support external Karma viewing

This commit is contained in:
Max Klaversma 2014-04-19 15:41:54 +02:00 committed by Steffen Schröder
parent 51f8fd8e22
commit 6f17ebd50e

View File

@ -31,7 +31,9 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
const VERSION = 0.1; const VERSION = 0.1;
const MLID_KARMA = 'KarmaPlugin.MLID'; const MLID_KARMA = 'KarmaPlugin.MLID';
const TABLE_KARMA = 'mc_karma'; const TABLE_KARMA = 'mc_karma';
const CB_KARMA_CHANGED = 'KarmaPlugin.Changed';
const SETTING_AVAILABLE_VOTES = 'Available Votes (X-Y: Comma separated)'; const SETTING_AVAILABLE_VOTES = 'Available Votes (X-Y: Comma separated)';
const SETTING_WIDGET_ENABLE = 'Enable Karma Widget';
const SETTING_WIDGET_TITLE = 'Widget-Title'; const SETTING_WIDGET_TITLE = 'Widget-Title';
const SETTING_WIDGET_POSX = 'Widget-Position: X'; const SETTING_WIDGET_POSX = 'Widget-Position: X';
const SETTING_WIDGET_POSY = 'Widget-Position: Y'; const SETTING_WIDGET_POSY = 'Widget-Position: Y';
@ -93,6 +95,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
// Init settings // Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_AVAILABLE_VOTES, '-2,2'); $this->maniaControl->settingManager->initSetting($this, self::SETTING_AVAILABLE_VOTES, '-2,2');
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_TITLE, 'Map-Karma'); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_TITLE, 'Map-Karma');
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSX, 160 - 27.5); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSX, 160 - 27.5);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 90 - 10 - 6); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 90 - 10 - 6);
@ -200,36 +203,38 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$voteCount = $votes['count']; $voteCount = $votes['count'];
} }
// Build karma manialink if($this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_ENABLE)) {
$this->buildManialink(); // Build karma manialink
$this->buildManialink();
// Update karma gauge & label // Update karma gauge & label
$karmaGauge = $this->manialink->karmaGauge; $karmaGauge = $this->manialink->karmaGauge;
$karmaLabel = $this->manialink->karmaLabel; $karmaLabel = $this->manialink->karmaLabel;
if (is_numeric($karma) && $voteCount > 0) { if (is_numeric($karma) && $voteCount > 0) {
$karma = floatval($karma); $karma = floatval($karma);
$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15); $karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
$karmaColor = ColorUtil::floatToStatusColor($karma); $karmaColor = ColorUtil::floatToStatusColor($karma);
$karmaGauge->setColor($karmaColor . '7'); $karmaGauge->setColor($karmaColor . '7');
$karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $voteCount . ')'); $karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $voteCount . ')');
} else { } else {
$karma = 0.; $karma = 0.;
$karmaGauge->setRatio(0.); $karmaGauge->setRatio(0.);
$karmaGauge->setColor('00fb'); $karmaGauge->setColor('00fb');
$karmaLabel->setText('-'); $karmaLabel->setText('-');
} }
// Loop players // Loop players
foreach($players as $login => $player) { foreach($players as $login => $player) {
// Get player vote // Get player vote
//$vote = $this->getPlayerVote($player, $map); //TODO what is this for, vote nowhere used? //$vote = $this->getPlayerVote($player, $map); //TODO what is this for, vote nowhere used?
// Adjust manialink for player's vote // Adjust manialink for player's vote
$votesFrame = $this->manialink->votesFrame; $votesFrame = $this->manialink->votesFrame;
$votesFrame->removeChildren(); $votesFrame->removeChildren();
// Send manialink // Send manialink
$this->maniaControl->manialinkManager->sendManialink($this->manialink, $login); $this->maniaControl->manialinkManager->sendManialink($this->manialink, $login);
}
} }
} }
@ -362,6 +367,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if (!$success) { if (!$success) {
return false; return false;
} }
$this->maniaControl->callbackManager->triggerCallback(self::CB_KARMA_CHANGED);
$this->updateManialink = true; $this->updateManialink = true;
return true; return true;
} }
@ -454,7 +460,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* @param Map $map * @param Map $map
* @return int * @return int
*/ */
private function getPlayerVote(Player $player, Map $map) { public function getPlayerVote(Player $player, Map $map) {
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$query = "SELECT * FROM `" . self::TABLE_KARMA . "` $query = "SELECT * FROM `" . self::TABLE_KARMA . "`
WHERE `playerIndex` = {$player->index} WHERE `playerIndex` = {$player->index}
@ -611,6 +617,16 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if ($settingName == '$l[http://karma.mania-exchange.com/auth/getapikey?server=' . $serverLogin . ']MX Karma Code for ' . $serverLogin . '$l') { if ($settingName == '$l[http://karma.mania-exchange.com/auth/getapikey?server=' . $serverLogin . ']MX Karma Code for ' . $serverLogin . '$l') {
$this->mxKarmaOpenSession(); $this->mxKarmaOpenSession();
} }
if ($settingName == 'Enable Karma Widget' && $value == true) {
$this->updateManialink = true;
$this->handle1Second(time());
} elseif ($settingName == 'Enable Karma Widget' && $value == false) {
$this->updateManialink = false;
$ml = new ManiaLink(self::MLID_KARMA);
$mltext = $ml->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($mltext);
}
} }
/** /**