callback refactor
This commit is contained in:
		
							
								
								
									
										52
									
								
								core/Callbacks/Structures/Common/CommonCommandStructure.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								core/Callbacks/Structures/Common/CommonCommandStructure.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace ManiaControl\Callbacks\Structures\ShootMania; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | use ManiaControl\Callbacks\Structures\Common\BaseStructure; | ||||||
|  | use ManiaControl\Callbacks\Structures\Common\BaseTimeStructure; | ||||||
|  | use ManiaControl\ManiaControl; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Common Structure Class for the OnCommand Structure Callback | ||||||
|  |  * | ||||||
|  |  * @api | ||||||
|  |  * @author    ManiaControl Team <mail@maniacontrol.com> | ||||||
|  |  * @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; | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @@ -0,0 +1,43 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace ManiaControl\Callbacks\Structures\ShootMania; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | use ManiaControl\Callbacks\Structures\Common\BaseStructure; | ||||||
|  | use ManiaControl\Callbacks\Structures\Common\BaseTimeStructure; | ||||||
|  | use ManiaControl\ManiaControl; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Common Structure Class for the Default Event Structure Callback | ||||||
|  |  * | ||||||
|  |  * @api | ||||||
|  |  * @author    ManiaControl Team <mail@maniacontrol.com> | ||||||
|  |  * @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; | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @@ -3,9 +3,6 @@ | |||||||
| namespace ManiaControl\Callbacks\Structures\ShootMania; | namespace ManiaControl\Callbacks\Structures\ShootMania; | ||||||
|  |  | ||||||
|  |  | ||||||
| use ManiaControl\Callbacks\Structures\Common\BaseStructure; |  | ||||||
| use ManiaControl\ManiaControl; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Structure Class for the OnCommand Structure Callback |  * Structure Class for the OnCommand Structure Callback | ||||||
|  * |  * | ||||||
| @@ -14,52 +11,5 @@ use ManiaControl\ManiaControl; | |||||||
|  * @copyright 2014-2017 ManiaControl Team |  * @copyright 2014-2017 ManiaControl Team | ||||||
|  * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3 |  * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3 | ||||||
|  */ |  */ | ||||||
| class OnCommandStructure extends BaseStructure { | class OnCommandStructure extends CommonCommandStructure { | ||||||
| 	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; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
|  |  | ||||||
| } | } | ||||||
| @@ -14,40 +14,5 @@ use ManiaControl\ManiaControl; | |||||||
|  * @copyright 2014-2017 ManiaControl Team |  * @copyright 2014-2017 ManiaControl Team | ||||||
|  * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3 |  * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3 | ||||||
|  */ |  */ | ||||||
| class OnDefaultEventStructure extends BaseStructure { | class OnDefaultEventStructure extends CommonDefaultEventStructure { | ||||||
| 	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; |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| @@ -5,8 +5,8 @@ namespace ManiaControl\Callbacks\Structures\TrackMania; | |||||||
|  |  | ||||||
| use ManiaControl\Callbacks\Structures\Common\BaseStructure; | use ManiaControl\Callbacks\Structures\Common\BaseStructure; | ||||||
| use ManiaControl\Callbacks\Structures\Common\BaseTimeStructure; | use ManiaControl\Callbacks\Structures\Common\BaseTimeStructure; | ||||||
|  | use ManiaControl\Callbacks\Structures\ShootMania\CommonCommandStructure; | ||||||
| use ManiaControl\ManiaControl; | use ManiaControl\ManiaControl; | ||||||
| //TODO make a common structure between shootmania and this and extend it |  | ||||||
| /** | /** | ||||||
|  * Structure Class for the OnCommand Structure Callback |  * Structure Class for the OnCommand Structure Callback | ||||||
|  * |  * | ||||||
| @@ -15,45 +15,5 @@ use ManiaControl\ManiaControl; | |||||||
|  * @copyright 2014-2017 ManiaControl Team |  * @copyright 2014-2017 ManiaControl Team | ||||||
|  * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3 |  * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3 | ||||||
|  */ |  */ | ||||||
| class OnCommandStructure extends BaseTimeStructure { | class OnCommandStructure extends CommonCommandStructure { | ||||||
| 	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; |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| @@ -5,38 +5,16 @@ namespace ManiaControl\Callbacks\Structures\TrackMania; | |||||||
|  |  | ||||||
| use ManiaControl\Callbacks\Structures\Common\BaseStructure; | use ManiaControl\Callbacks\Structures\Common\BaseStructure; | ||||||
| use ManiaControl\Callbacks\Structures\Common\BaseTimeStructure; | use ManiaControl\Callbacks\Structures\Common\BaseTimeStructure; | ||||||
|  | use ManiaControl\Callbacks\Structures\ShootMania\CommonDefaultEventStructure; | ||||||
| use ManiaControl\ManiaControl; | use ManiaControl\ManiaControl; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Structure Class for the Default Event Structure Callback |  * Structure Class for the Default Event Structure Callback | ||||||
|  * |  * | ||||||
|  |  * @api | ||||||
|  * @author    ManiaControl Team <mail@maniacontrol.com> |  * @author    ManiaControl Team <mail@maniacontrol.com> | ||||||
|  * @copyright 2014-2017 ManiaControl Team |  * @copyright 2014-2017 ManiaControl Team | ||||||
|  * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3 |  * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3 | ||||||
|  */ |  */ | ||||||
| class OnDefaultEventStructure extends BaseTimeStructure { | class OnDefaultEventStructure extends CommonDefaultEventStructure { | ||||||
| 	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; |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| @@ -17,14 +17,14 @@ use ManiaControl\Utils\Formatter; | |||||||
|  * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3 |  * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3 | ||||||
|  */ |  */ | ||||||
| class OnEventWayPointStructure extends BasePlayerTimeStructure { | class OnEventWayPointStructure extends BasePlayerTimeStructure { | ||||||
| 	private $racetime; | 	private $raceTime; | ||||||
| 	private $laptime; | 	private $lapTime; | ||||||
| 	private $stuntsscore; | 	private $stuntsScore; | ||||||
| 	private $checkpointinrace; | 	private $checkPointInRace; | ||||||
| 	private $checkpointinlap; | 	private $checkPointInLap; | ||||||
| 	private $isendrace; | 	private $isEndRace; | ||||||
| 	private $isendlap; | 	private $isEndLap; | ||||||
| 	private $blockid; | 	private $blockId; | ||||||
| 	private $speed; | 	private $speed; | ||||||
| 	private $distance; | 	private $distance; | ||||||
|  |  | ||||||
| @@ -37,29 +37,29 @@ class OnEventWayPointStructure extends BasePlayerTimeStructure { | |||||||
| 	public function __construct(ManiaControl $maniaControl, $data) { | 	public function __construct(ManiaControl $maniaControl, $data) { | ||||||
| 		parent::__construct($maniaControl, $data); | 		parent::__construct($maniaControl, $data); | ||||||
|  |  | ||||||
| 		$this->racetime         = (int) $this->getPlainJsonObject()->racetime; | 		$this->raceTime         = (int) $this->getPlainJsonObject()->racetime; | ||||||
| 		$this->laptime          = (int) $this->getPlainJsonObject()->laptime; | 		$this->lapTime          = (int) $this->getPlainJsonObject()->laptime; | ||||||
| 		$this->stuntsscore      = $this->getPlainJsonObject()->stuntsscore; | 		$this->stuntsScore      = $this->getPlainJsonObject()->stuntsscore; | ||||||
| 		$this->checkpointinrace = (int) $this->getPlainJsonObject()->checkpointinrace; | 		$this->checkPointInRace = (int) $this->getPlainJsonObject()->checkpointinrace; | ||||||
| 		$this->checkpointinlap  = (int) $this->getPlainJsonObject()->checkpointinlap; | 		$this->checkPointInLap  = (int) $this->getPlainJsonObject()->checkpointinlap; | ||||||
| 		$this->isendrace        = $this->getPlainJsonObject()->isendrace; | 		$this->isEndRace        = $this->getPlainJsonObject()->isendrace; | ||||||
| 		$this->isendlap         = $this->getPlainJsonObject()->isendlap; | 		$this->isEndLap         = $this->getPlainJsonObject()->isendlap; | ||||||
| 		$this->blockid          = $this->getPlainJsonObject()->blockid; | 		$this->blockId          = $this->getPlainJsonObject()->blockid; | ||||||
| 		$this->speed            = $this->getPlainJsonObject()->speed; | 		$this->speed            = $this->getPlainJsonObject()->speed; | ||||||
| 		$this->distance         = $this->getPlainJsonObject()->distance; | 		$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              = new RecordCallback(); | ||||||
| 		$wayPointCallback->rawCallback = $data; | 		$wayPointCallback->rawCallback = $data; | ||||||
| 		$wayPointCallback->setPlayer($this->getPlayer()); | 		$wayPointCallback->setPlayer($this->getPlayer()); | ||||||
| 		$wayPointCallback->blockId       = $this->blockid; | 		$wayPointCallback->blockId       = $this->blockId; | ||||||
| 		$wayPointCallback->time          = $this->racetime; | 		$wayPointCallback->time          = $this->raceTime; | ||||||
| 		$wayPointCallback->checkpoint    = $this->checkpointinrace; | 		$wayPointCallback->checkpoint    = $this->checkPointInRace; | ||||||
| 		$wayPointCallback->isEndRace     = Formatter::parseBoolean($this->isendrace); | 		$wayPointCallback->isEndRace     = Formatter::parseBoolean($this->isEndRace); | ||||||
| 		$wayPointCallback->lapTime       = $this->laptime; | 		$wayPointCallback->lapTime       = $this->lapTime; | ||||||
| 		$wayPointCallback->lapCheckpoint = $this->checkpointinlap; | 		$wayPointCallback->lapCheckpoint = $this->checkPointInLap; | ||||||
| 		$wayPointCallback->lap           = 0; | 		$wayPointCallback->lap           = 0; | ||||||
| 		$wayPointCallback->isEndLap      = Formatter::parseBoolean($this->isendlap); | 		$wayPointCallback->isEndLap      = Formatter::parseBoolean($this->isEndLap); | ||||||
| 		if ($wayPointCallback->checkpoint > 0) { | 		if ($wayPointCallback->checkpoint > 0) { | ||||||
| 			$currentMap            = $this->maniaControl->getMapManager()->getCurrentMap(); | 			$currentMap            = $this->maniaControl->getMapManager()->getCurrentMap(); | ||||||
| 			$wayPointCallback->lap += $wayPointCallback->checkpoint / $currentMap->nbCheckpoints; | 			$wayPointCallback->lap += $wayPointCallback->checkpoint / $currentMap->nbCheckpoints; | ||||||
| @@ -73,4 +73,85 @@ class OnEventWayPointStructure extends BasePlayerTimeStructure { | |||||||
| 		} | 		} | ||||||
| 		$this->maniaControl->getCallbackManager()->triggerCallback($wayPointCallback); | 		$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; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user