TrackManiaControl/core/Callbacks/TrackManiaCallbacks.php

118 lines
4.8 KiB
PHP
Raw Normal View History

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;
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;
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>
2017-02-04 11:49:23 +01:00
* @copyright 2014-2017 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 {
/*
* Private properties
2014-05-24 17:45:35 +02:00
*/
/** @var ManiaControl $maniaControl */
2014-05-24 17:45:35 +02:00
private $maniaControl = null;
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;
// Register for script callbacks
$callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks');
2014-05-24 17:45:35 +02:00
}
/**
* Handle Script Callbacks
*
* @param string $name
* @param mixed $data
*/
public function handleScriptCallbacks($name, $data) {
if (!$this->maniaControl->getCallbackManager()->callbackListeningExists($name)) {
2017-03-25 20:19:45 +01:00
//return; //Leave that disabled while testing/implementing Callbacks
}
switch ($name) {
case Callbacks::TM_SCORES:
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnScoresStructure($this->maniaControl, $data));
break;
2017-03-25 20:19:45 +01:00
case Callbacks::TM_ONEVENTDEFAULT:
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnDefaultEventStructure($this->maniaControl, $data));
break;
case Callbacks::TM_ONEVENTSTARTLINE:
2017-04-14 17:02:00 +02:00
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnStartLineEventStructure($this->maniaControl, $data));
break;
case Callbacks::TM_ONCOMMAND:
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnCommandStructure($this->maniaControl, $data));
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));
break;
case Callbacks::TM_ONWAYPOINT:
$this->handleWayPointCallback(new OnWayPointEventStructure($this->maniaControl, $data));
//$this->maniaControl->getCallbackManager()->triggerCallback($name, $wayPointStructure);
break;
case Callbacks::TM_ONRESPAWN:
2017-04-14 17:02:00 +02:00
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnRespawnStructure($this->maniaControl, $data));
break;
case Callbacks::TM_ONSTUNT:
2017-04-14 17:02:00 +02:00
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnStuntEventStructure($this->maniaControl, $data));
break;
case Callbacks::TM_WARMUPSTART:
2017-04-14 17:02:00 +02:00
case Callbacks::TM_WARMUPEND:
$this->maniaControl->getCallbackManager()->triggerCallback($name);
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));
break;
2017-04-14 17:02:00 +02:00
case Callbacks::TM_POINTSREPARTITION:
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnPointsRepartitionStructure($this->maniaControl, $data));
break;
case Callbacks::TM_UIPROPERTIES:
2017-04-14 17:02:00 +02:00
$this->maniaControl->getCallbackManager()->triggerCallback($name, new UIPropertiesBaseStructure($this->maniaControl, $data));
break;
}
}
2014-05-24 17:45:35 +02:00
/**
* Trigger the three different Types of Callbacks
2014-05-24 17:45:35 +02:00
*
* @param \ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure $structure
2014-05-24 17:45:35 +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 {
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONWAYPOINT, $structure);
}
}
2014-05-24 17:45:35 +02:00
}