2014-05-24 17:45:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Callbacks;
|
|
|
|
|
2017-04-13 19:14:23 +02:00
|
|
|
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
|
2017-04-14 17:02:00 +02:00
|
|
|
use ManiaControl\Callbacks\Structures\Common\UIPropertiesBaseStructure;
|
2017-04-07 23:03:56 +02:00
|
|
|
use ManiaControl\Callbacks\Structures\TrackMania\OnCommandStructure;
|
2017-03-25 20:19:45 +01:00
|
|
|
use ManiaControl\Callbacks\Structures\TrackMania\OnDefaultEventStructure;
|
2017-04-14 17:02:00 +02:00
|
|
|
use ManiaControl\Callbacks\Structures\TrackMania\OnPointsRepartitionStructure;
|
|
|
|
use ManiaControl\Callbacks\Structures\TrackMania\OnRespawnStructure;
|
2017-04-07 23:03:56 +02:00
|
|
|
use ManiaControl\Callbacks\Structures\TrackMania\OnScoresStructure;
|
2017-04-14 17:02:00 +02:00
|
|
|
use ManiaControl\Callbacks\Structures\TrackMania\OnStartLineEventStructure;
|
|
|
|
use ManiaControl\Callbacks\Structures\TrackMania\OnStuntEventStructure;
|
|
|
|
use ManiaControl\Callbacks\Structures\TrackMania\OnWarmupStartEndRoundStructure;
|
|
|
|
use ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure;
|
2014-05-24 17:45:35 +02:00
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class handling and parsing TrackMania Callbacks
|
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2019-01-05 21:02:24 +01:00
|
|
|
* @copyright 2014-2019 ManiaControl Team
|
2014-05-24 17:45:35 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
|
|
|
*/
|
|
|
|
class TrackManiaCallbacks implements CallbackListener {
|
|
|
|
/*
|
2014-08-02 22:31:46 +02:00
|
|
|
* Private properties
|
2014-05-24 17:45:35 +02:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2014-05-24 17:45:35 +02:00
|
|
|
private $maniaControl = null;
|
|
|
|
|
2017-03-29 13:28:32 +02:00
|
|
|
|
2014-05-24 17:45:35 +02:00
|
|
|
/**
|
|
|
|
* Create a new TrackMania Callbacks Instance
|
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
* @param CallbackManager $callbackManager
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
2017-03-25 13:44:03 +01:00
|
|
|
// Register for script callbacks
|
|
|
|
$callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks');
|
2014-05-24 17:45:35 +02:00
|
|
|
}
|
|
|
|
|
2017-03-25 13:44:03 +01:00
|
|
|
/**
|
|
|
|
* Handle Script Callbacks
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param mixed $data
|
|
|
|
*/
|
|
|
|
public function handleScriptCallbacks($name, $data) {
|
|
|
|
if (!$this->maniaControl->getCallbackManager()->callbackListeningExists($name)) {
|
2017-05-10 11:07:45 +02:00
|
|
|
return; //Leave that disabled while testing/implementing Callbacks
|
2017-03-25 13:44:03 +01:00
|
|
|
}
|
|
|
|
switch ($name) {
|
2017-03-29 13:28:32 +02:00
|
|
|
case Callbacks::TM_SCORES:
|
2017-04-07 23:03:56 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnScoresStructure($this->maniaControl, $data));
|
2017-03-29 13:28:32 +02:00
|
|
|
break;
|
2017-03-25 20:19:45 +01:00
|
|
|
case Callbacks::TM_ONEVENTDEFAULT:
|
2017-04-07 23:03:56 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnDefaultEventStructure($this->maniaControl, $data));
|
2017-03-25 13:44:03 +01:00
|
|
|
break;
|
2017-03-29 13:28:32 +02:00
|
|
|
case Callbacks::TM_ONEVENTSTARTLINE:
|
2017-04-14 17:02:00 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnStartLineEventStructure($this->maniaControl, $data));
|
2017-03-29 13:28:32 +02:00
|
|
|
break;
|
|
|
|
case Callbacks::TM_ONCOMMAND:
|
2017-04-07 23:03:56 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnCommandStructure($this->maniaControl, $data));
|
2017-03-29 13:28:32 +02:00
|
|
|
break;
|
|
|
|
case Callbacks::TM_ONPLAYERADDED:
|
|
|
|
case Callbacks::TM_ONPLAYERREMOVED:
|
2017-04-14 17:02:00 +02:00
|
|
|
case Callbacks::TM_ONGIVEUP:
|
|
|
|
case Callbacks::TM_ONSTARTCOUNTDOWN:
|
2017-04-13 19:14:23 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback($name, new BasePlayerTimeStructure($this->maniaControl, $data));
|
2017-03-29 13:28:32 +02:00
|
|
|
break;
|
|
|
|
case Callbacks::TM_ONWAYPOINT:
|
2017-05-08 19:55:07 +02:00
|
|
|
$this->handleWayPointCallback(new OnWayPointEventStructure($this->maniaControl, $data));
|
|
|
|
|
|
|
|
//$this->maniaControl->getCallbackManager()->triggerCallback($name, $wayPointStructure);
|
2017-03-29 13:28:32 +02:00
|
|
|
break;
|
|
|
|
case Callbacks::TM_ONRESPAWN:
|
2017-04-14 17:02:00 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnRespawnStructure($this->maniaControl, $data));
|
2017-03-29 13:28:32 +02:00
|
|
|
break;
|
|
|
|
case Callbacks::TM_ONSTUNT:
|
2017-04-14 17:02:00 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnStuntEventStructure($this->maniaControl, $data));
|
2017-03-29 13:28:32 +02:00
|
|
|
break;
|
|
|
|
case Callbacks::TM_WARMUPSTART:
|
2017-04-14 17:02:00 +02:00
|
|
|
case Callbacks::TM_WARMUPEND:
|
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback($name);
|
2017-03-29 13:28:32 +02:00
|
|
|
break;
|
|
|
|
case Callbacks::TM_WARMUPSTARTROUND:
|
|
|
|
case Callbacks::TM_WARMUPENDROUND:
|
2017-04-14 17:02:00 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnWarmupStartEndRoundStructure($this->maniaControl, $data));
|
2017-03-29 13:28:32 +02:00
|
|
|
break;
|
2017-04-14 17:02:00 +02:00
|
|
|
case Callbacks::TM_POINTSREPARTITION:
|
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnPointsRepartitionStructure($this->maniaControl, $data));
|
2017-03-29 13:28:32 +02:00
|
|
|
break;
|
2017-04-13 16:12:10 +02:00
|
|
|
case Callbacks::TM_UIPROPERTIES:
|
2017-04-14 17:02:00 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback($name, new UIPropertiesBaseStructure($this->maniaControl, $data));
|
2017-04-13 16:12:10 +02:00
|
|
|
break;
|
2017-03-25 13:44:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-24 17:45:35 +02:00
|
|
|
/**
|
2017-05-08 19:55:07 +02:00
|
|
|
* Trigger the three different Types of Callbacks
|
2014-05-24 17:45:35 +02:00
|
|
|
*
|
2017-05-08 19:55:07 +02:00
|
|
|
* @param \ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure $structure
|
2014-05-24 17:45:35 +02:00
|
|
|
*/
|
2017-05-08 19:55:07 +02:00
|
|
|
private function handleWayPointCallback(OnWayPointEventStructure $structure) {
|
|
|
|
if ($structure->getIsEndRace()) {
|
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONFINISHLINE, $structure);
|
|
|
|
} else if ($structure->getIsEndLap()) {
|
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONLAPFINISH, $structure);
|
2014-05-24 17:45:35 +02:00
|
|
|
} else {
|
2017-05-08 19:55:07 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONWAYPOINT, $structure);
|
2014-05-24 18:32:09 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-24 17:45:35 +02:00
|
|
|
}
|