set up VReplayChecks for Dedimania records in Laps mode (#187)
This commit is contained in:
		| @@ -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 | ||||
| 	 * | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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; | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user