TrackManiaControl/libs/FML/Script/ScriptLabel.php

109 lines
2.3 KiB
PHP
Raw Normal View History

2014-04-27 14:44:40 +02:00
<?php
namespace FML\Script;
/**
2014-06-21 03:18:21 +02:00
* Class representing a part of the ManiaLink Script
2014-04-27 14:44:40 +02:00
*
2014-05-20 15:44:45 +02:00
* @author steeffeen <mail@steeffeen.com>
2014-04-27 14:44:40 +02:00
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
2014-05-14 23:24:00 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2014-04-27 14:44:40 +02:00
*/
class ScriptLabel {
/*
* Constants
*/
2014-05-14 23:24:00 +02:00
const ONINIT = 'FML_OnInit';
const LOOP = 'FML_Loop';
const TICK = 'FML_Tick';
2014-04-27 14:44:40 +02:00
const ENTRYSUBMIT = 'FML_EntrySubmit';
2014-05-14 23:24:00 +02:00
const KEYPRESS = 'FML_KeyPress';
const MOUSECLICK = 'FML_MouseClick';
const MOUSEOUT = 'FML_MouseOut';
const MOUSEOVER = 'FML_MouseOver';
2014-04-27 14:44:40 +02:00
/*
2014-06-21 03:18:21 +02:00
* Protected properties
2014-04-27 14:44:40 +02:00
*/
protected $name = null;
protected $text = null;
protected $isolated = null;
/**
* Construct a new ScriptLabel
*
2014-06-21 03:18:21 +02:00
* @param string $name (optional) Label name
* @param string $text (optional) Script text
2014-05-14 23:24:00 +02:00
* @param bool $isolated (optional) Isolate the Label Script
2014-04-27 14:44:40 +02:00
*/
2014-06-21 03:18:21 +02:00
public function __construct($name = self::LOOP, $text = null, $isolated = false) {
2014-04-27 14:44:40 +02:00
$this->setName($name);
$this->setText($text);
$this->setIsolated($isolated);
}
/**
2014-06-21 03:18:21 +02:00
* Set the name
2014-04-27 14:44:40 +02:00
*
2014-06-21 03:18:21 +02:00
* @param string $name Label name
2014-07-03 22:34:47 +02:00
* @return static
2014-04-27 14:44:40 +02:00
*/
public function setName($name) {
2014-05-14 23:24:00 +02:00
$this->name = (string)$name;
2014-04-27 14:44:40 +02:00
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set the text
2014-04-27 14:44:40 +02:00
*
2014-06-21 03:18:21 +02:00
* @param string $text Script text
2014-07-03 22:34:47 +02:00
* @return static
2014-04-27 14:44:40 +02:00
*/
public function setText($text) {
2014-05-14 23:24:00 +02:00
$this->text = (string)$text;
2014-04-27 14:44:40 +02:00
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set isolation
2014-04-27 14:44:40 +02:00
*
2014-06-21 03:18:21 +02:00
* @param bool $isolated Whether the code should be isolated in an own block
2014-07-03 22:34:47 +02:00
* @return static
2014-04-27 14:44:40 +02:00
*/
public function setIsolated($isolated) {
2014-05-14 23:24:00 +02:00
$this->isolated = (bool)$isolated;
2014-04-27 14:44:40 +02:00
return $this;
}
2014-05-16 22:44:22 +02:00
/**
2014-06-21 03:18:21 +02:00
* Check if the given label is an event label
2014-05-16 22:44:22 +02:00
*
2014-06-21 03:18:21 +02:00
* @param string $label Label name
2014-05-16 22:44:22 +02:00
* @return bool
*/
public static function isEventLabel($label) {
2014-06-21 03:18:21 +02:00
if (in_array($label, static::getEventLabels())) {
2014-05-16 22:44:22 +02:00
return true;
}
return false;
}
/**
2014-06-21 03:18:21 +02:00
* Get the possible event label names
2014-05-16 22:44:22 +02:00
*
2014-06-21 03:18:21 +02:00
* @return string[]
2014-05-16 22:44:22 +02:00
*/
public static function getEventLabels() {
return array(self::ENTRYSUBMIT, self::KEYPRESS, self::MOUSECLICK, self::MOUSEOUT, self::MOUSEOVER);
}
2014-04-27 14:44:40 +02:00
/**
2014-06-21 03:18:21 +02:00
* Build the full Script Label text
2014-04-27 14:44:40 +02:00
*
* @return string
*/
public function __toString() {
2014-06-21 03:18:21 +02:00
return Builder::getLabelImplementationBlock($this->name, $this->text, $this->isolated);
2014-04-27 14:44:40 +02:00
}
}