Updated LocalRecordsPlugin design and fixed Stats list bug with playtime

This commit is contained in:
Jocy 2017-05-21 20:40:30 +02:00
parent e072024ce5
commit 03621f1fba
2 changed files with 23 additions and 10 deletions

View File

@ -88,7 +88,20 @@ abstract class Formatter implements UsageInformationAble {
* @return string * @return string
*/ */
public static function formatTimeH($seconds) { public static function formatTimeH($seconds) {
return gmdate('H:i:s', $seconds); $hrs = floor($seconds / 3600);
$mins = intval(($seconds / 60) % 60);
$sec = intval($seconds % 60);
$hrs = str_pad($hrs, 2, '0', STR_PAD_LEFT);
$mins = str_pad($mins, 2, '0', STR_PAD_LEFT);
$sec = str_pad($sec, 2, '0', STR_PAD_LEFT);
$str = '';
$str .= $hrs . ':';
$str .= $mins . ':';
$str .= $sec;
return $str;
} }
/** /**

View File

@ -326,8 +326,8 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene
$rankLabel = new Label(); $rankLabel = new Label();
$recordFrame->addChild($rankLabel); $recordFrame->addChild($rankLabel);
$rankLabel->setHorizontalAlign($rankLabel::LEFT); $rankLabel->setHorizontalAlign($rankLabel::LEFT);
$rankLabel->setX($width * -0.47); $rankLabel->setX($width * -0.49);
$rankLabel->setSize($width * 0.06, $lineHeight); $rankLabel->setSize($width * 0.09, $lineHeight);
$rankLabel->setTextSize(1); $rankLabel->setTextSize(1);
$rankLabel->setTextPrefix('$o'); $rankLabel->setTextPrefix('$o');
$rankLabel->setText($record->rank); $rankLabel->setText($record->rank);
@ -336,7 +336,7 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene
$nameLabel = new Label(); $nameLabel = new Label();
$recordFrame->addChild($nameLabel); $recordFrame->addChild($nameLabel);
$nameLabel->setHorizontalAlign($nameLabel::LEFT); $nameLabel->setHorizontalAlign($nameLabel::LEFT);
$nameLabel->setX($width * -0.36); $nameLabel->setX($width * -0.39);
$nameLabel->setSize($width * 0.6, $lineHeight); $nameLabel->setSize($width * 0.6, $lineHeight);
$nameLabel->setTextSize(1); $nameLabel->setTextSize(1);
$nameLabel->setText($record->nickname); $nameLabel->setText($record->nickname);
@ -345,8 +345,8 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene
$timeLabel = new Label(); $timeLabel = new Label();
$recordFrame->addChild($timeLabel); $recordFrame->addChild($timeLabel);
$timeLabel->setHorizontalAlign($timeLabel::RIGHT); $timeLabel->setHorizontalAlign($timeLabel::RIGHT);
$timeLabel->setX($width * 0.47); $timeLabel->setX($width * 0.49);
$timeLabel->setSize($width * 0.25, $lineHeight); $timeLabel->setSize($width * 0.27, $lineHeight);
$timeLabel->setTextSize(1); $timeLabel->setTextSize(1);
$timeLabel->setText(Formatter::formatTime($record->time)); $timeLabel->setText(Formatter::formatTime($record->time));
$timeLabel->setTextEmboss(true); $timeLabel->setTextEmboss(true);
@ -468,7 +468,7 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene
* @param \ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure $structure * @param \ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure $structure
*/ */
public function handleFinishCallback(OnWayPointEventStructure $structure) { public function handleFinishCallback(OnWayPointEventStructure $structure) {
if ($structure->getRaceTime() <= 0) { if ($structure->getLapTime() <= 0) {
// Invalid time // Invalid time
return; return;
} }
@ -487,11 +487,11 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene
// Check old record of the player // Check old record of the player
$oldRecord = $this->getLocalRecord($map, $player); $oldRecord = $this->getLocalRecord($map, $player);
if ($oldRecord) { if ($oldRecord) {
if ($oldRecord->time < $structure->getRaceTime()) { if ($oldRecord->time < $structure->getLapTime()) {
// Not improved // Not improved
return; return;
} }
if ($oldRecord->time == $structure->getRaceTime()) { if ($oldRecord->time == $structure->getLapTime()) {
// Same time // Same time
// TODO: respect notify-settings // TODO: respect notify-settings
$message = '$<$fff' . $player->nickname . '$> equalized the $<$ff0' . $oldRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($oldRecord->time) . '$>!'; $message = '$<$fff' . $player->nickname . '$> equalized the $<$ff0' . $oldRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($oldRecord->time) . '$>!';
@ -510,7 +510,7 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene
) VALUES ( ) VALUES (
{$map->index}, {$map->index},
{$player->index}, {$player->index},
{$structure->getRaceTime()}, {$structure->getLapTime()},
'{$checkpointsString}' '{$checkpointsString}'
) ON DUPLICATE KEY UPDATE ) ON DUPLICATE KEY UPDATE
`time` = VALUES(`time`), `time` = VALUES(`time`),