callback refactor

This commit is contained in:
kremsy 2017-04-14 16:30:33 +02:00
parent da408a9bee
commit 486263826d
7 changed files with 207 additions and 178 deletions

View 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;
}
}

View File

@ -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;
}
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 <mail@maniacontrol.com>
* @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 {
}

View File

@ -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;
}
}