From 486263826dd26066bb2ca643a2015571ed24330a Mon Sep 17 00:00:00 2001 From: kremsy Date: Fri, 14 Apr 2017 16:30:33 +0200 Subject: [PATCH] callback refactor --- .../Common/CommonCommandStructure.php | 52 +++++++ .../Common/CommonDefaultEventStructure.php | 43 ++++++ .../ShootMania/OnCommandStructure.php | 52 +------ .../ShootMania/OnDefaultEventStructure.php | 37 +---- .../TrackMania/OnCommandStructure.php | 44 +----- .../TrackMania/OnDefaultEventStructure.php | 28 +--- .../TrackMania/OnEventWayPointStructure.php | 129 ++++++++++++++---- 7 files changed, 207 insertions(+), 178 deletions(-) create mode 100644 core/Callbacks/Structures/Common/CommonCommandStructure.php create mode 100644 core/Callbacks/Structures/Common/CommonDefaultEventStructure.php diff --git a/core/Callbacks/Structures/Common/CommonCommandStructure.php b/core/Callbacks/Structures/Common/CommonCommandStructure.php new file mode 100644 index 00000000..919266aa --- /dev/null +++ b/core/Callbacks/Structures/Common/CommonCommandStructure.php @@ -0,0 +1,52 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class CommonCommandStructure extends BaseTimeStructure { + private $name; + private $value; + + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $this->name = $this->getPlainJsonObject()->name; + $this->value = $this->getPlainJsonObject()->value; + } + + /** + * < Name of the command + * + * @api + * @return string + */ + public function getName() { + return $this->name; + } + + /** + * < The value passed by the command + * "boolean": true, + * "integer": 123, + * "real": 123.456, + * "text": "an example value" + * + * @api + * @return mixed + */ + public function getValue() { + return $this->value; + } +} \ No newline at end of file diff --git a/core/Callbacks/Structures/Common/CommonDefaultEventStructure.php b/core/Callbacks/Structures/Common/CommonDefaultEventStructure.php new file mode 100644 index 00000000..95ca5948 --- /dev/null +++ b/core/Callbacks/Structures/Common/CommonDefaultEventStructure.php @@ -0,0 +1,43 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class CommonDefaultEventStructure extends BaseTimeStructure { + private $type; + + /** + * OnDefaultEventStructure constructor. + * + * @param \ManiaControl\ManiaControl $maniaControl + * @param $data + */ + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $this->type = $this->getPlainJsonObject()->type; + } + + + /** + * Returns the type of event + * + * @api + * @return string + */ + public function getType() { + return $this->type; + } +} \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnCommandStructure.php b/core/Callbacks/Structures/ShootMania/OnCommandStructure.php index 286f5128..b1b2c1d0 100644 --- a/core/Callbacks/Structures/ShootMania/OnCommandStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnCommandStructure.php @@ -3,9 +3,6 @@ namespace ManiaControl\Callbacks\Structures\ShootMania; -use ManiaControl\Callbacks\Structures\Common\BaseStructure; -use ManiaControl\ManiaControl; - /** * Structure Class for the OnCommand Structure Callback * @@ -14,52 +11,5 @@ use ManiaControl\ManiaControl; * @copyright 2014-2017 ManiaControl Team * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ -class OnCommandStructure extends BaseStructure { - private $time; - private $name; - private $value; - - public function __construct(ManiaControl $maniaControl, $data) { - parent::__construct($maniaControl, $data); - - $this->time = $this->getPlainJsonObject()->time; - $this->name = $this->getPlainJsonObject()->name; - $this->value = $this->getPlainJsonObject()->value; - } - - /** - * < Server time when the event occured - * - * @api - * @return int - */ - public function getTime() { - return $this->time; - } - - /** - * < Name of the command - * - * @api - * @return string - */ - public function getName() { - return $this->name; - } - - /** - * < The value passed by the command - * "boolean": true, - * "integer": 123, - * "real": 123.456, - * "text": "an example value" - * - * @api - * @return mixed - */ - public function getValue() { - return $this->value; - } - - +class OnCommandStructure extends CommonCommandStructure { } \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnDefaultEventStructure.php b/core/Callbacks/Structures/ShootMania/OnDefaultEventStructure.php index 4aad302b..b5148d24 100644 --- a/core/Callbacks/Structures/ShootMania/OnDefaultEventStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnDefaultEventStructure.php @@ -14,40 +14,5 @@ use ManiaControl\ManiaControl; * @copyright 2014-2017 ManiaControl Team * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ -class OnDefaultEventStructure extends BaseStructure { - private $time; - private $type; - - /** - * OnDefaultEventStructure constructor. - * - * @param \ManiaControl\ManiaControl $maniaControl - * @param $data - */ - public function __construct(ManiaControl $maniaControl, $data) { - parent::__construct($maniaControl, $data); - - $this->time = $this->getPlainJsonObject()->time; - $this->type = $this->getPlainJsonObject()->type; - } - - /** - * Returns Server time when the event occured - * - * @api - * @return int - */ - public function getTime() { - return $this->time; - } - - /** - * Returns the type of event - * - * @api - * @return string - */ - public function getType() { - return $this->type; - } +class OnDefaultEventStructure extends CommonDefaultEventStructure { } \ No newline at end of file diff --git a/core/Callbacks/Structures/TrackMania/OnCommandStructure.php b/core/Callbacks/Structures/TrackMania/OnCommandStructure.php index 046f22f6..a9325d39 100644 --- a/core/Callbacks/Structures/TrackMania/OnCommandStructure.php +++ b/core/Callbacks/Structures/TrackMania/OnCommandStructure.php @@ -5,8 +5,8 @@ namespace ManiaControl\Callbacks\Structures\TrackMania; use ManiaControl\Callbacks\Structures\Common\BaseStructure; use ManiaControl\Callbacks\Structures\Common\BaseTimeStructure; +use ManiaControl\Callbacks\Structures\ShootMania\CommonCommandStructure; use ManiaControl\ManiaControl; -//TODO make a common structure between shootmania and this and extend it /** * Structure Class for the OnCommand Structure Callback * @@ -15,45 +15,5 @@ use ManiaControl\ManiaControl; * @copyright 2014-2017 ManiaControl Team * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ -class OnCommandStructure extends BaseTimeStructure { - private $name; - private $value; - - /** - * OnCommandStructure constructor. - * - * @param \ManiaControl\ManiaControl $maniaControl - * @param $data - */ - public function __construct(ManiaControl $maniaControl, $data) { - parent::__construct($maniaControl, $data); - - $this->name = $this->getPlainJsonObject()->name; - $this->value = $this->getPlainJsonObject()->value; - } - - - /** - * < Name of the command - * - * @api - * @return string - */ - public function getName() { - return $this->name; - } - - /** - * < The value passed by the command - * "boolean": true, - * "integer": 123, - * "real": 123.456, - * "text": "an example value" - * - * @api - * @return mixed - */ - public function getValue() { - return $this->value; - } +class OnCommandStructure extends CommonCommandStructure { } \ No newline at end of file diff --git a/core/Callbacks/Structures/TrackMania/OnDefaultEventStructure.php b/core/Callbacks/Structures/TrackMania/OnDefaultEventStructure.php index 2e9d4348..a5e55d5c 100644 --- a/core/Callbacks/Structures/TrackMania/OnDefaultEventStructure.php +++ b/core/Callbacks/Structures/TrackMania/OnDefaultEventStructure.php @@ -5,38 +5,16 @@ namespace ManiaControl\Callbacks\Structures\TrackMania; use ManiaControl\Callbacks\Structures\Common\BaseStructure; use ManiaControl\Callbacks\Structures\Common\BaseTimeStructure; +use ManiaControl\Callbacks\Structures\ShootMania\CommonDefaultEventStructure; use ManiaControl\ManiaControl; /** * Structure Class for the Default Event Structure Callback * + * @api * @author ManiaControl Team * @copyright 2014-2017 ManiaControl Team * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ -class OnDefaultEventStructure extends BaseTimeStructure { - private $type; - - /** - * OnDefaultEventStructure constructor. - * - * @param \ManiaControl\ManiaControl $maniaControl - * @param $data - */ - public function __construct(ManiaControl $maniaControl, $data) { - parent::__construct($maniaControl, $data); - - $this->type = $this->getPlainJsonObject()->type; - } - - - /** - * Returns the type of event - * - * @api - * @return string - */ - public function getType() { - return $this->type; - } +class OnDefaultEventStructure extends CommonDefaultEventStructure { } \ No newline at end of file diff --git a/core/Callbacks/Structures/TrackMania/OnEventWayPointStructure.php b/core/Callbacks/Structures/TrackMania/OnEventWayPointStructure.php index 127c275e..43a036d6 100644 --- a/core/Callbacks/Structures/TrackMania/OnEventWayPointStructure.php +++ b/core/Callbacks/Structures/TrackMania/OnEventWayPointStructure.php @@ -17,14 +17,14 @@ use ManiaControl\Utils\Formatter; * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ class OnEventWayPointStructure extends BasePlayerTimeStructure { - private $racetime; - private $laptime; - private $stuntsscore; - private $checkpointinrace; - private $checkpointinlap; - private $isendrace; - private $isendlap; - private $blockid; + private $raceTime; + private $lapTime; + private $stuntsScore; + private $checkPointInRace; + private $checkPointInLap; + private $isEndRace; + private $isEndLap; + private $blockId; private $speed; private $distance; @@ -37,29 +37,29 @@ class OnEventWayPointStructure extends BasePlayerTimeStructure { public function __construct(ManiaControl $maniaControl, $data) { parent::__construct($maniaControl, $data); - $this->racetime = (int) $this->getPlainJsonObject()->racetime; - $this->laptime = (int) $this->getPlainJsonObject()->laptime; - $this->stuntsscore = $this->getPlainJsonObject()->stuntsscore; - $this->checkpointinrace = (int) $this->getPlainJsonObject()->checkpointinrace; - $this->checkpointinlap = (int) $this->getPlainJsonObject()->checkpointinlap; - $this->isendrace = $this->getPlainJsonObject()->isendrace; - $this->isendlap = $this->getPlainJsonObject()->isendlap; - $this->blockid = $this->getPlainJsonObject()->blockid; + $this->raceTime = (int) $this->getPlainJsonObject()->racetime; + $this->lapTime = (int) $this->getPlainJsonObject()->laptime; + $this->stuntsScore = $this->getPlainJsonObject()->stuntsscore; + $this->checkPointInRace = (int) $this->getPlainJsonObject()->checkpointinrace; + $this->checkPointInLap = (int) $this->getPlainJsonObject()->checkpointinlap; + $this->isEndRace = $this->getPlainJsonObject()->isendrace; + $this->isEndLap = $this->getPlainJsonObject()->isendlap; + $this->blockId = $this->getPlainJsonObject()->blockid; $this->speed = $this->getPlainJsonObject()->speed; $this->distance = $this->getPlainJsonObject()->distance; - // Build callback + // Build callback //TODO remove the old lagacy stuff and update the uses to the new Structure $wayPointCallback = new RecordCallback(); $wayPointCallback->rawCallback = $data; $wayPointCallback->setPlayer($this->getPlayer()); - $wayPointCallback->blockId = $this->blockid; - $wayPointCallback->time = $this->racetime; - $wayPointCallback->checkpoint = $this->checkpointinrace; - $wayPointCallback->isEndRace = Formatter::parseBoolean($this->isendrace); - $wayPointCallback->lapTime = $this->laptime; - $wayPointCallback->lapCheckpoint = $this->checkpointinlap; + $wayPointCallback->blockId = $this->blockId; + $wayPointCallback->time = $this->raceTime; + $wayPointCallback->checkpoint = $this->checkPointInRace; + $wayPointCallback->isEndRace = Formatter::parseBoolean($this->isEndRace); + $wayPointCallback->lapTime = $this->lapTime; + $wayPointCallback->lapCheckpoint = $this->checkPointInLap; $wayPointCallback->lap = 0; - $wayPointCallback->isEndLap = Formatter::parseBoolean($this->isendlap); + $wayPointCallback->isEndLap = Formatter::parseBoolean($this->isEndLap); if ($wayPointCallback->checkpoint > 0) { $currentMap = $this->maniaControl->getMapManager()->getCurrentMap(); $wayPointCallback->lap += $wayPointCallback->checkpoint / $currentMap->nbCheckpoints; @@ -73,4 +73,85 @@ class OnEventWayPointStructure extends BasePlayerTimeStructure { } $this->maniaControl->getCallbackManager()->triggerCallback($wayPointCallback); } + + /** + * @api + * @return int + */ + public function getRaceTime() { + return $this->raceTime; + } + + /** + * @api + * @return int + */ + public function getLapTime() { + return $this->lapTime; + } + + /** + * @api + * @return mixed + */ + public function getStuntsScore() { + return $this->stuntsScore; + } + + /** + * @api + * @return int + */ + public function getCheckPointInRace() { + return $this->checkPointInRace; + } + + /** + * @api + * @return int + */ + public function getCheckPointInLap() { + return $this->checkPointInLap; + } + + /** + * @api + * @return mixed + */ + public function getIsEndRace() { + return $this->isEndRace; + } + + /** + * @api + * @return mixed + */ + public function getIsEndLap() { + return $this->isEndLap; + } + + /** + * @api + * @return mixed + */ + public function getBlockId() { + return $this->blockId; + } + + /** + * @api + * @return mixed + */ + public function getSpeed() { + return $this->speed; + } + + /** + * @api + * @return mixed + */ + public function getDistance() { + return $this->distance; + } + } \ No newline at end of file