From 56b361fff94b72c63e6d1df5f8397644252d55c2 Mon Sep 17 00:00:00 2001 From: agiorla Date: Tue, 3 Jul 2018 12:12:47 -0400 Subject: [PATCH] set up VReplayChecks for Dedimania records in Laps mode (#187) --- plugins/MCTeam/Dedimania/DedimaniaPlugin.php | 35 +++++++++++++++++-- .../MCTeam/Dedimania/DedimaniaWebHandler.php | 4 +-- plugins/MCTeam/Dedimania/RecordData.php | 4 ++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/plugins/MCTeam/Dedimania/DedimaniaPlugin.php b/plugins/MCTeam/Dedimania/DedimaniaPlugin.php index e1381cd5..d59a204d 100644 --- a/plugins/MCTeam/Dedimania/DedimaniaPlugin.php +++ b/plugins/MCTeam/Dedimania/DedimaniaPlugin.php @@ -66,6 +66,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene private $recordWidget = null; private $checkpoints = array(); + private $allCheckpoints = array(); /** @var \MCTeam\Dedimania\DedimaniaWebHandler $webHandler */ private $webHandler = null; @@ -249,6 +250,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene */ public function handleBeginMap() { $this->checkpoints = null; + $this->allCheckpoints = null; $this->webHandler->getDedimaniaData()->unsetRecords(); $this->webHandler->maniaLinkUpdateNeeded(); $this->webHandler->fetchDedimaniaRecords(true); @@ -278,7 +280,12 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene if (!isset($this->checkpoints[$login])) { $this->checkpoints[$login] = array(); } + if (!isset($this->allCheckpoints[$login])) { + $this->allCheckpoints[$login] = array(); + } + $this->checkpoints[$login][$structure->getCheckPointInLap()] = $structure->getLapTime(); + $this->allCheckpoints[$login][$structure->getCheckPointInRace()] = $structure->getRaceTime(); } /** @@ -304,15 +311,18 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene $player = $structure->getPlayer(); + $this->checkpoints[$player->login][$structure->getCheckPointInLap()] = $structure->getLapTime(); + $this->allCheckpoints[$player->login][$structure->getCheckPointInRace()] = $structure->getRaceTime(); + $oldRecord = $this->getDedimaniaRecord($player->login); if ($oldRecord->nullRecord || $oldRecord && $oldRecord->best > $structure->getLapTime()) { // Save time $newRecord = new RecordData(null); $checkPoints = $this->getCheckpoints($player->login); - $checkPoints = $checkPoints . "," . $structure->getLapTime(); + $allCPs = $this->getAllCheckpoints($player->login); - $newRecord->constructNewRecord($player->login, $player->nickname, $structure->getLapTime(), $checkPoints, true); + $newRecord->constructNewRecord($player->login, $player->nickname, $structure->getLapTime(), $checkPoints, true, $allCPs); if ($this->insertDedimaniaRecord($newRecord, $oldRecord)) { // Get newly saved record @@ -400,6 +410,27 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene return $string; } + /** + * Get total checkpoint string for dedimania record + * + * @param string $login + * @return string + */ + private function getAllCheckpoints($login) { + if (!$login || !isset($this->allCheckpoints[$login])) { + return null; + } + $string = ''; + $count = count($this->allCheckpoints[$login]); + foreach ($this->allCheckpoints[$login] as $index => $check) { + $string .= strval($check); + if ($index < $count - 1) { + $string .= ','; + } + } + return $string; + } + /** * Inserts the given new Dedimania record at the proper position * diff --git a/plugins/MCTeam/Dedimania/DedimaniaWebHandler.php b/plugins/MCTeam/Dedimania/DedimaniaWebHandler.php index c78a1054..d74f60e1 100644 --- a/plugins/MCTeam/Dedimania/DedimaniaWebHandler.php +++ b/plugins/MCTeam/Dedimania/DedimaniaWebHandler.php @@ -183,8 +183,7 @@ class DedimaniaWebHandler implements TimerListener { } if (!isset($replays['VReplayChecks'])) { - $replays['VReplayChecks'] = ''; - // TODO: VReplayChecks + $replays['VReplayChecks'] = $record->allCheckpoints; } if (!isset($replays['Top1GReplay'])) { $replays['Top1GReplay'] = $record->top1GReplay; @@ -192,6 +191,7 @@ class DedimaniaWebHandler implements TimerListener { } xmlrpc_set_type($replays['VReplay'], 'base64'); + xmlrpc_set_type($replays['VReplayChecks'], 'base64'); xmlrpc_set_type($replays['Top1GReplay'], 'base64'); $data = array($this->dedimaniaData->sessionId, $this->getMapInfo(), $gameMode, $times, $replays); diff --git a/plugins/MCTeam/Dedimania/RecordData.php b/plugins/MCTeam/Dedimania/RecordData.php index e7f69db0..361e1682 100644 --- a/plugins/MCTeam/Dedimania/RecordData.php +++ b/plugins/MCTeam/Dedimania/RecordData.php @@ -25,6 +25,7 @@ class RecordData { public $newRecord = false; public $vReplay = ''; public $top1GReplay = ''; + public $allCheckpoints = ''; /** * Construct a Record by a given Record Array @@ -54,12 +55,13 @@ class RecordData { * @param int $checkpoints * @param bool $newRecord */ - public function constructNewRecord($login, $nickname, $best, $checkpoints, $newRecord = false) { + public function constructNewRecord($login, $nickname, $best, $checkpoints, $newRecord = false, $allCPs = '') { $this->nullRecord = false; $this->login = $login; $this->nickname = $nickname; $this->best = $best; $this->checkpoints = $checkpoints; $this->newRecord = $newRecord; + $this->allCheckpoints = $allCPs; } }