Possibility added to switch between old RASP-karma and new percentage

This commit is contained in:
Max Klaversma 2014-04-30 14:45:56 +02:00 committed by Steffen Schröder
parent 904f000481
commit 919c5b4270
3 changed files with 35 additions and 22 deletions

View File

@ -343,21 +343,26 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$mapList = array(); $mapList = array();
foreach($maps as $map) { foreach($maps as $map) {
if($map instanceof Map) { if($map instanceof Map) {
$votes = $karmaPlugin->getMapVotes($map); if($this->maniaControl->settingManager->getSetting($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA) === true) {
$min = 0; $karma = $karmaPlugin->getMapKarma($map);
$plus = 0; $map->karma = round($karma * 100.);
foreach($votes as $vote) { } else {
if(isset($vote->vote)) { $votes = $karmaPlugin->getMapVotes($map);
if($vote->vote != 0.5) { $min = 0;
if($vote->vote < 0.5) { $plus = 0;
$min = $min+$vote->count; foreach($votes as $vote) {
} else { if(isset($vote->vote)) {
$plus = $plus+$vote->count; if($vote->vote != 0.5) {
if($vote->vote < 0.5) {
$min = $min+$vote->count;
} else {
$plus = $plus+$vote->count;
}
} }
} }
} }
$map->karma = $plus-$min;
} }
$map->karma = $plus-$min;
$mapList[] = $map; $mapList[] = $map;
} }
} }

View File

@ -425,20 +425,26 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$karma = $karmaPlugin->getMapKarma($map); $karma = $karmaPlugin->getMapKarma($map);
$votes = $karmaPlugin->getMapVotes($map); $votes = $karmaPlugin->getMapVotes($map);
if (is_numeric($karma)) { if (is_numeric($karma)) {
$min = 0; if($this->maniaControl->settingManager->getSetting($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA) === true) {
$plus = 0; $endKarma = $karma;
foreach($votes as $vote) { $karmaText = ' ' . round($karma * 100.) . ' (' . $votes['count'] . ')';
if(isset($vote->vote)) { } else {
if($vote->vote != 0.5) { $min = 0;
if($vote->vote < 0.5) { $plus = 0;
$min = $min+$vote->count; foreach($votes as $vote) {
} else { if(isset($vote->vote)) {
$plus = $plus+$vote->count; if($vote->vote != 0.5) {
if($vote->vote < 0.5) {
$min = $min+$vote->count;
} else {
$plus = $plus+$vote->count;
}
} }
} }
} }
$endKarma = $plus-$min;
$karmaText = ' ' . $endKarma . ' (' . $votes['count'] . 'x / ' . round($karma * 100.) . '%)';
} }
$endKarma = $plus-$min;
$karmaGauge = new Gauge(); $karmaGauge = new Gauge();
$mapFrame->add($karmaGauge); $mapFrame->add($karmaGauge);
@ -459,7 +465,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$karmaLabel->setTextSize(0.9); $karmaLabel->setTextSize(0.9);
$karmaLabel->setTextColor('000'); $karmaLabel->setTextColor('000');
$karmaLabel->setAlign(Control::CENTER, Control::CENTER); $karmaLabel->setAlign(Control::CENTER, Control::CENTER);
$karmaLabel->setText(' ' . $endKarma . ' (' . $votes['count'] . 'x / ' . round($karma * 100.) . '%)'); $karmaLabel->setText($karmaText);
} }
} }

View File

@ -43,6 +43,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
const SETTING_WIDGET_POSY = 'Widget-Position: Y'; const SETTING_WIDGET_POSY = 'Widget-Position: Y';
const SETTING_WIDGET_WIDTH = 'Widget-Size: Width'; const SETTING_WIDGET_WIDTH = 'Widget-Size: Width';
const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height'; const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height';
const SETTING_NEWKARMA = 'Enable "new karma" (percentage), disable = RASP karma';
const STAT_PLAYER_MAPVOTES = 'Voted Maps'; const STAT_PLAYER_MAPVOTES = 'Voted Maps';
/* /*
@ -102,6 +103,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 90 - 10 - 6); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 90 - 10 - 6);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_WIDTH, 25.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_WIDTH, 25.);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_HEIGHT, 12.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_HEIGHT, 12.);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NEWKARMA, true);
// Register for callbacks // Register for callbacks
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000); $this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);