TrackManiaControl/core/Callbacks/Structures/TrackMania/OnScoresStructure.php

66 lines
2.4 KiB
PHP
Raw Normal View History

<?php
namespace ManiaControl\Callbacks\Structures\TrackMania;
2017-03-30 19:39:23 +02:00
use ManiaControl\Callbacks\Structures\Common\CommonScoresStructure;
use ManiaControl\Callbacks\Structures\TrackMania\Models\PlayerScore;
use ManiaControl\ManiaControl;
/**
2017-03-30 19:39:23 +02:00
* Structure Class for the Trackmania OnScores Structure Callback
*
2017-04-13 19:14:23 +02:00
* @api
* @author ManiaControl Team <mail@maniacontrol.com>
2020-01-22 10:39:35 +01:00
* @copyright 2014-2020 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
2017-03-30 19:39:23 +02:00
class OnScoresStructure extends CommonScoresStructure {
2017-04-07 23:26:35 +02:00
/**
* OnScoresStructure constructor.
*
* @param \ManiaControl\ManiaControl $maniaControl
* @param $data
*/
public function __construct(ManiaControl $maniaControl, $data) {
parent::__construct($maniaControl, $data);
$jsonObj = $this->getPlainJsonObject();
foreach ($jsonObj->players as $jsonPlayer) {
2017-05-09 19:11:19 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($jsonPlayer->login);
if ($player) {
$playerScore = new PlayerScore();
$playerScore->setPlayer($this->maniaControl->getPlayerManager()->getPlayer($jsonPlayer->login));
$playerScore->setRank($jsonPlayer->rank);
$playerScore->setMapPoints($jsonPlayer->mappoints);
$playerScore->setMatchPoints($jsonPlayer->matchpoints);
$playerScore->setRoundPoints($jsonPlayer->roundpoints);
2017-05-09 19:11:19 +02:00
$playerScore->setBestRaceTime($jsonPlayer->bestracetime);
$playerScore->setBestLapTime($jsonPlayer->bestlaptime);
$playerScore->setStuntScore($jsonPlayer->stuntsscore);
$playerScore->setBestRaceRespawns($jsonPlayer->bestracerespawns);
$playerScore->setBestRaceCheckpoints($jsonPlayer->bestracecheckpoints);
$playerScore->setBestLapRespawns($jsonPlayer->bestlaprespawns);
$playerScore->setBestLapCheckpoints($jsonPlayer->bestlapcheckpoints);
//New attributes in 2.5.0
if (property_exists($jsonPlayer, 'prevracetime')) {
$playerScore->setPrevRaceTime($jsonPlayer->prevracetime);
}
if (property_exists($jsonPlayer, 'prevracerespawns')) {
$playerScore->setPrevRaceRespawns($jsonPlayer->prevracerespawns);
}
if (property_exists($jsonPlayer, 'prevracecheckpoints')) {
$playerScore->setPrevRaceCheckpoints($jsonPlayer->prevracecheckpoints);
}
if (property_exists($jsonPlayer, 'prevstuntsscore')) {
$playerScore->setPrevStuntsScore($jsonPlayer->prevstuntsscore);
}
2017-05-09 19:11:19 +02:00
$this->playerScores[$jsonPlayer->login] = $playerScore;
}
}
}
}