removed 'application' folder to have everything in the root directory

This commit is contained in:
Steffen Schröder
2014-09-29 18:20:09 +02:00
parent 1569fd5488
commit 9642433363
284 changed files with 4 additions and 50 deletions

150
libs/FML/Script/Builder.php Normal file
View File

@ -0,0 +1,150 @@
<?php
namespace FML\Script;
/**
* ManiaScript Builder class
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
abstract class Builder {
/*
* Constants
*/
const EMPTY_STRING = '""';
/**
* Build a label implementation block
*
* @param string $labelName Name of the label
* @param string $implementationCode Label implementation coding (without declaration)
* @param bool $isolate Whether the code should be isolated in an own block
* @return string
*/
public static function getLabelImplementationBlock($labelName, $implementationCode, $isolate = true) {
if ($isolate) {
$implementationCode = 'if(True){' . $implementationCode . '}';
}
$labelText = PHP_EOL . "***{$labelName}***" . PHP_EOL . "***{$implementationCode}***" . PHP_EOL;
return $labelText;
}
/**
* Escape dangerous characters in the given text
*
* @param string $text Text to escape
* @param bool $addApostrophes (optional) Whether to add apostrophes before and after the text
* @return string
*/
public static function escapeText($text, $addApostrophes = false) {
$dangers = array('\\', '"', "\n");
$replacements = array('\\\\', '\\"', '\\n');
$escapedText = str_ireplace($dangers, $replacements, $text);
if ($addApostrophes) {
$escapedText = '"' . $escapedText . '"';
}
return $escapedText;
}
/**
* Get the 'Real' string representation of the given value
*
* @param float $value Float value to convert to a ManiaScript 'Real'
* @return string
*/
public static function getReal($value) {
$value = (float)$value;
$stringVal = (string)$value;
if (!fmod($value, 1)) {
$stringVal .= '.';
}
return $stringVal;
}
/**
* Get the 'Boolean' string representation of the given value
*
* @param bool $value Value to convert to a ManiaScript 'Boolean'
* @return string
*/
public static function getBoolean($value) {
$bool = (bool)$value;
if ($bool) {
return 'True';
}
return 'False';
}
/**
* Get the string representation of the given array
*
* @param array $array Array to convert to a ManiaScript array
* @param bool $associative (optional) Whether the array should be associative
* @return string
*/
public static function getArray(array $array, $associative = false) {
$arrayText = '[';
$index = 0;
$count = count($array);
foreach ($array as $key => $value) {
if ($associative) {
if (is_string($key)) {
$arrayText .= '"' . static::escapeText($key) . '"';
} else {
$arrayText .= $key;
}
$arrayText .= ' => ';
}
if (is_string($value)) {
$arrayText .= '"' . static::escapeText($value) . '"';
} else {
$arrayText .= $value;
}
if ($index < $count - 1) {
$arrayText .= ', ';
$index++;
}
}
$arrayText .= ']';
return $arrayText;
}
/**
* Get the include command for the given file and namespace
*
* @param string $file Include file
* @param string $namespace (optional) Include namespace
* @return string
*/
public static function getInclude($file, $namespace = null) {
if (!$namespace && stripos($file, '.') === false) {
$namespace = $file;
}
$file = static::escapeText($file, true);
$includeText = "#Include {$file}";
if ($namespace) {
$includeText .= " as {$namespace}";
}
$includeText .= PHP_EOL;
return $includeText;
}
/**
* Get the constant command for the given name and value
*
* @param string $name Constant name
* @param string $value Constant value
* @return string
*/
public static function getConstant($name, $value) {
if (is_string($value)) {
$value = static::escapeText($value, true);
} else if (is_bool($value)) {
$value = static::getBoolean($value);
}
$constantText = "#Const {$name} {$value}" . PHP_EOL;
return $constantText;
}
}

View File

@ -0,0 +1,112 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for triggering a manialink page action
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ActionTrigger extends ScriptFeature {
/*
* Protected properties
*/
protected $actionName = null;
/** @var Control $control */
protected $control = null;
protected $labelName = null;
/**
* Construct a new Action Trigger Feature
*
* @param string $actionName (optional) Triggered action
* @param Control $control (optional) Action Control
* @param string $labelName (optional) Script Label name
*/
public function __construct($actionName = null, Control $control = null, $labelName = ScriptLabel::MOUSECLICK) {
if ($actionName !== null) {
$this->setActionName($actionName);
}
if ($control !== null) {
$this->setControl($control);
}
if ($labelName !== null) {
$this->setLabelName($labelName);
}
}
/**
* Set the action to trigger
*
* @param string $actionName
* @return static
*/
public function setActionName($actionName) {
$this->actionName = (string)$actionName;
return $this;
}
/**
* Set the Control
*
* @param Control $control Action Control
* @return static
*/
public function setControl(Control $control) {
$control->checkId();
if ($control instanceof Scriptable) {
$control->setScriptEvents(true);
}
$this->control = $control;
return $this;
}
/**
* Set the label name
*
* @param string $labelName Script Label name
* @return static
*/
public function setLabelName($labelName) {
$this->labelName = (string)$labelName;
return $this;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
return $this;
}
/**
* Get the script text
*
* @return string
*/
protected function getScriptText() {
$actionName = Builder::escapeText($this->actionName, true);
if ($this->control) {
// Control event
$controlId = Builder::escapeText($this->control->getId(), true);
$scriptText = "
if (Event.Control.ControlId == {$controlId}) {
TriggerPageAction({$actionName});
}";
} else {
// Other
$scriptText = "
TriggerPageAction({$actionName});";
}
return $scriptText;
}
}

View File

@ -0,0 +1,221 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Entry;
use FML\Controls\Quad;
use FML\Models\CheckBoxDesign;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptInclude;
use FML\Script\ScriptLabel;
/**
* Script Feature for creating a CheckBox behavior
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class CheckBoxFeature extends ScriptFeature {
/*
* Constants
*/
const FUNCTION_UPDATE_QUAD_DESIGN = 'FML_UpdateQuadDesign';
const VAR_CHECKBOX_ENABLED = 'FML_CheckBox_Enabled';
const VAR_CHECKBOX_DESIGNS = 'FML_CheckBox_Designs';
const VAR_CHECKBOX_ENTRY_ID = 'FML_CheckBox_EntryId';
/*
* Protected properties
*/
/** @var Quad $quad */
protected $quad = null;
/** @var Entry $entry */
protected $entry = null;
protected $default = null;
/** @var CheckBoxDesign $enabledDesign */
protected $enabledDesign = null;
/** @var CheckBoxDesign $disabledDesign */
protected $disabledDesign = null;
/**
* Construct a new CheckBox Feature
*
* @param Quad $quad (optional) CheckBox Quad
* @param Entry $entry (optional) Hidden Entry
* @param bool $default (optional) Default value
*/
public function __construct(Quad $quad = null, Entry $entry = null, $default = null) {
if ($quad !== null) {
$this->setQuad($quad);
}
if ($entry !== null) {
$this->setEntry($entry);
}
if ($default !== null) {
$this->setDefault($default);
}
$this->setEnabledDesign(CheckBoxDesign::defaultEnabledDesign());
$this->setDisabledDesign(CheckBoxDesign::defaultDisabledDesign());
}
/**
* Set the CheckBox Quad
*
* @param Quad $quad CheckBox Quad
* @return static
*/
public function setQuad(Quad $quad) {
$this->quad = $quad->checkId()->setScriptEvents(true);
return $this;
}
/**
* Get the CheckBox Quad
*
* @return \FML\Controls\Quad
*/
public function getQuad() {
return $this->quad;
}
/**
* Set the CheckBox Entry
*
* @param Entry $entry CheckBox Entry
* @return static
*/
public function setEntry(Entry $entry) {
$this->entry = $entry->checkId();
return $this;
}
/**
* Get the managed Entry
*
* @return \FML\Controls\Entry
*/
public function getEntry() {
return $this->entry;
}
/**
* Set the default value
*
* @param bool $default Default value
* @return static
*/
public function setDefault($default) {
$this->default = (bool)$default;
return $this;
}
/**
* Set the enabled Design
*
* @param CheckBoxDesign $checkBoxDesign Enabled CheckBox Design
* @return static
*/
public function setEnabledDesign(CheckBoxDesign $checkBoxDesign) {
$this->enabledDesign = $checkBoxDesign;
return $this;
}
/**
* Set the disabled Design
*
* @param CheckBoxDesign $checkBoxDesign Disabled CheckBox Design
* @return static
*/
public function setDisabledDesign(CheckBoxDesign $checkBoxDesign) {
$this->disabledDesign = $checkBoxDesign;
return $this;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
if ($this->getQuad()) {
$script->setScriptInclude(ScriptInclude::TEXTLIB);
$script->addScriptFunction(self::FUNCTION_UPDATE_QUAD_DESIGN, $this->buildUpdateQuadDesignFunction());
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->buildInitScriptText(), true);
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $this->buildClickScriptText());
}
return $this;
}
/**
* Build the function text
*
* @return string
*/
protected function buildUpdateQuadDesignFunction() {
return "
Void " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(CMlQuad _Quad) {
declare " . self::VAR_CHECKBOX_ENABLED . " as Enabled for _Quad = True;
Enabled = !Enabled;
_Quad.StyleSelected = Enabled;
declare " . self::VAR_CHECKBOX_DESIGNS . " as Designs for _Quad = Text[Boolean];
declare Design = Designs[Enabled];
declare DesignParts = TextLib::Split(\"|\", Design);
if (DesignParts.count > 1) {
_Quad.Style = DesignParts[0];
_Quad.Substyle = DesignParts[1];
} else {
_Quad.ImageUrl = Design;
}
declare " . self::VAR_CHECKBOX_ENTRY_ID . " as EntryId for _Quad = " . Builder::EMPTY_STRING . ";
if (EntryId != " . Builder::EMPTY_STRING . ") {
declare Value = \"0\";
if (Enabled) {
Value = \"1\";
}
declare Entry <=> (Page.GetFirstChild(EntryId) as CMlEntry);
Entry.Value = Value;
}
}";
}
/**
* Build the init script text
*
* @return string
*/
protected function buildInitScriptText() {
$quadId = $this->getQuad()->getId(true, true);
$entryId = '""';
if ($this->entry) {
$entryId = $this->entry->getId(true, true);
}
$default = Builder::getBoolean($this->default);
$enabledDesignString = $this->enabledDesign->getDesignString();
$disabledDesignString = $this->disabledDesign->getDesignString();
return "
declare Quad_CheckBox <=> (Page.GetFirstChild({$quadId}) as CMlQuad);
declare Text[Boolean] " . self::VAR_CHECKBOX_DESIGNS . " as Designs for Quad_CheckBox;
Designs[True] = {$enabledDesignString};
Designs[False] = {$disabledDesignString};
declare Boolean " . self::VAR_CHECKBOX_ENABLED . " as Enabled for Quad_CheckBox;
Enabled = !{$default};
declare Text " . self::VAR_CHECKBOX_ENTRY_ID . " as EntryId for Quad_CheckBox;
EntryId = {$entryId};
" . self::FUNCTION_UPDATE_QUAD_DESIGN . "(Quad_CheckBox);
";
}
/**
* Build the script text for Quad clicks
*
* @return string
*/
protected function buildClickScriptText() {
$quadId = $this->getQuad()->getId(true, true);
return "
if (Event.ControlId == {$quadId}) {
declare Quad_CheckBox <=> (Event.Control as CMlQuad);
" . self::FUNCTION_UPDATE_QUAD_DESIGN . "(Quad_CheckBox);
}";
}
}

View File

@ -0,0 +1,105 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Label;
use FML\Script\Script;
use FML\Script\ScriptInclude;
use FML\Script\ScriptLabel;
/**
* Script Feature showing the current time on a Label
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Clock extends ScriptFeature {
/*
* Protected properties
*/
/** @var Label $label */
protected $label = null;
protected $showSeconds = null;
protected $showFullDate = null;
/**
* Construct a new Clock Feature
*
* @param Label $label (optional) Clock Label
* @param bool $showSeconds (optional) Whether the seconds should be shown
* @param bool $showFullDate (optional) Whether the date should be shown
*/
public function __construct(Label $label = null, $showSeconds = true, $showFullDate = false) {
if ($label !== null) {
$this->setLabel($label);
}
$this->setShowSeconds($showSeconds);
$this->setShowFullDate($showFullDate);
}
/**
* Set the Label
*
* @param Label $label Clock Label
* @return static
*/
public function setLabel(Label $label) {
$this->label = $label->checkId();
return $this;
}
/**
* Set whether seconds should be shown
*
* @param bool $showSeconds Whether seconds should be shown
* @return static
*/
public function setShowSeconds($showSeconds) {
$this->showSeconds = (bool)$showSeconds;
return $this;
}
/**
* Set whether the full date should be shown
*
* @param bool $showFullDate Whether the full date should be shown
* @return static
*/
public function setShowFullDate($showFullDate) {
$this->showFullDate = (bool)$showFullDate;
return $this;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$script->setScriptInclude(ScriptInclude::TEXTLIB);
$script->appendGenericScriptLabel(ScriptLabel::TICK, $this->getScriptText(), true);
return $this;
}
/**
* Get the script text
*
* @return string
*/
protected function getScriptText() {
$controlId = $this->label->getId(true, true);
$scriptText = "
declare ClockLabel <=> (Page.GetFirstChild({$controlId}) as CMlLabel);
declare TimeText = CurrentLocalDateText;";
if (!$this->showSeconds) {
$scriptText .= "
TimeText = TextLib::SubText(TimeText, 0, 16);";
}
if (!$this->showFullDate) {
$scriptText .= "
TimeText = TextLib::SubText(TimeText, 11, 9);";
}
$scriptText .= "
ClockLabel.Value = TimeText;";
return $scriptText;
}
}

View File

@ -0,0 +1,125 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for a Control related script
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ControlScript extends ScriptFeature {
/*
* Protected properties
*/
/** @var Control $control */
protected $control = null;
protected $labelName = null;
protected $text = null;
/**
* Construct a new Control Script
*
* @param Control $control Event Control
* @param string $text Script text
* @param string $labelName (optional) Script Label name
*/
public function __construct(Control $control, $text, $labelName = ScriptLabel::MOUSECLICK) {
$this->setControl($control);
$this->setText($text);
$this->setLabelName($labelName);
}
/**
* Set the Control
*
* @param Control $control Event Control
* @return static
*/
public function setControl(Control $control) {
$this->control = $control->checkId();
$this->updateScriptEvents();
return $this;
}
/**
* Set the script text
*
* @param string $text Script text
* @return static
*/
public function setText($text) {
$this->text = (string)$text;
return $this;
}
/**
* Set the label name
*
* @param string $labelName Script Label name
* @return static
*/
public function setLabelName($labelName) {
$this->labelName = (string)$labelName;
$this->updateScriptEvents();
return $this;
}
/**
* Enable Script Events on the Control if needed
*/
protected function updateScriptEvents() {
if (!$this->control || !ScriptLabel::isEventLabel($this->labelName)) {
return;
}
if ($this->control instanceof Scriptable) {
$this->control->setScriptEvents(true);
}
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$isolated = !ScriptLabel::isEventLabel($this->labelName);
$script->appendGenericScriptLabel($this->labelName, $this->buildScriptText(), $isolated);
return $this;
}
/**
* Build the script text for the Control
*
* @return string
*/
protected function buildScriptText() {
$controlId = $this->control->getId(true);
$scriptText = '';
$closeBlock = false;
if (ScriptLabel::isEventLabel($this->labelName)) {
$scriptText .= '
if (Event.ControlId == "' . $controlId . '") {
declare Control <=> Event.Control;';
$closeBlock = true;
} else {
$scriptText .= '
declare Control <=> Page.GetFirstChild("' . $controlId . '");';
}
$class = $this->control->getManiaScriptClass();
$name = preg_replace('/^CMl/', '', $class, 1);
$scriptText .= '
declare ' . $name . ' <=> (Control as ' . $class . ');
';
$scriptText .= $this->text . '
';
if ($closeBlock) {
$scriptText .= '}';
}
return $scriptText;
}
}

View File

@ -0,0 +1,101 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Entry;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptInclude;
use FML\Script\ScriptLabel;
/**
* Script Feature for submitting an Entry
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class EntrySubmit extends ScriptFeature {
/*
* Protected properties
*/
/** @var Entry $entry */
protected $entry = null;
protected $url = null;
/**
* Construct a new Entry Submit Feature
*
* @param Entry $entry (optional) Entry Control
* @param string $url (optional) Submit url
*/
public function __construct(Entry $entry = null, $url = null) {
if ($entry !== null) {
$this->setEntry($entry);
}
$this->setUrl($url);
}
/**
* Set the Entry
*
* @param Entry $entry Entry Control
* @return static
*/
public function setEntry(Entry $entry) {
$this->entry = $entry->checkId()->setScriptEvents(true);
return $this;
}
/**
* Set the submit url
*
* @param string $url Submit url
* @return static
*/
public function setUrl($url) {
$this->url = (string)$url;
return $this;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$script->setScriptInclude(ScriptInclude::TEXTLIB);
$controlScript = new ControlScript($this->entry, $this->getScriptText(), ScriptLabel::ENTRYSUBMIT);
$controlScript->prepare($script);
return $this;
}
/**
* Get the script text
*
* @return string
*/
protected function getScriptText() {
$url = $this->buildCompatibleUrl();
$entryName = $this->entry->getName();
$link = Builder::escapeText($entryName . $url . '=', true);
return "
declare Value = TextLib::URLEncode(Entry.Value);
OpenLink({$link}^Value, CMlScript::LinkType::Goto);
";
}
/**
* Build the submit url compatible for the Entry parameter
*
* @return string
*/
protected function buildCompatibleUrl() {
$url = $this->url;
$paramsBegin = stripos($url, '?');
if (!is_int($paramsBegin) || $paramsBegin < 0) {
$url .= '?';
} else {
$url .= '&';
}
return $url;
}
}

View File

@ -0,0 +1,124 @@
<?php
namespace FML\Script\Features;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptLabel;
/**
* Script Feature for triggering a manialink page action on key press
*
* @author steeffeen
* @link http://destroflyer.mania-community.de/maniascript/keycharid_table.php
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class KeyAction extends ScriptFeature {
/*
* Protected properties
*/
protected $actionName = null;
protected $keyName = null;
protected $keyCode = null;
protected $charPressed = null;
/**
* Construct a new Key Action Feature
*
* @param string $actionName (optional) Triggered action
* @param string $keyName (optional) Key name
*/
public function __construct($actionName = null, $keyName = null) {
if ($actionName !== null) {
$this->setActionName($actionName);
}
if ($keyName !== null) {
$this->setKeyName($keyName);
}
}
/**
* Set the action to trigger
*
* @param string $actionName Triggered action
* @return static
*/
public function setActionName($actionName) {
$this->actionName = (string)$actionName;
return $this;
}
/**
* Set the key name for triggering the action
*
* @param string $keyName Key Name
* @return static
*/
public function setKeyName($keyName) {
$this->keyName = (string)$keyName;
$this->keyCode = null;
$this->charPressed = null;
return $this;
}
/**
* Set the key code for triggering the action
*
* @param int $keyCode Key Code
* @return static
*/
public function setKeyCode($keyCode) {
$this->keyCode = (int)$keyCode;
$this->keyName = null;
$this->charPressed = null;
return $this;
}
/**
* Set the char to press for triggering the action
*
* @param string $charPressed Pressed char
* @return static
*/
public function setCharPressed($charPressed) {
$this->charPressed = (string)$charPressed;
$this->keyName = null;
$this->keyCode = null;
return $this;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$script->appendGenericScriptLabel(ScriptLabel::KEYPRESS, $this->getScriptText());
return $this;
}
/**
* Get the script text
*
* @return string
*/
protected function getScriptText() {
$actionName = Builder::escapeText($this->actionName, true);
$key = null;
$value = null;
if ($this->keyName !== null) {
$key = 'KeyName';
$value = $this->keyName;
} else if ($this->keyCode !== null) {
$key = 'KeyCode';
$value = $this->keyCode;
} else if ($this->charPressed !== null) {
$key = 'CharPressed';
$value = $this->charPressed;
}
$value = Builder::escapeText($value, true);
return "
if (Event.{$key} == {$value}) {
TriggerPageAction({$actionName});
}";
}
}

View File

@ -0,0 +1,91 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for opening the map info
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class MapInfo extends ScriptFeature {
/*
* Protected properties
*/
/** @var Control $control */
protected $control = null;
protected $labelName = null;
/**
* Construct a new Map Info Feature
*
* @param Control $control (optional) Map Info Control
* @param string $labelName (optional) Script Label name
*/
public function __construct(Control $control, $labelName = ScriptLabel::MOUSECLICK) {
$this->setControl($control);
$this->setLabelName($labelName);
}
/**
* Set the Control
*
* @param Control $control Map Info Control
* @return static
*/
public function setControl(Control $control) {
$control->checkId();
if ($control instanceof Scriptable) {
$control->setScriptEvents(true);
}
$this->control = $control;
return $this;
}
/**
* Set the label name
*
* @param string $labelName Script Label name
* @return static
*/
public function setLabelName($labelName) {
$this->labelName = (string)$labelName;
return $this;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
return $this;
}
/**
* Get the script text
*
* @return string
*/
protected function getScriptText() {
if ($this->control) {
// Control event
$controlId = Builder::escapeText($this->control->getId(), true);
$scriptText = "
if (Event.Control.ControlId == {$controlId}) {
ShowCurChallengeCard();
}";
} else {
// Other
$scriptText = "
ShowCurChallengeCard();";
}
return $scriptText;
}
}

View File

@ -0,0 +1,140 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptLabel;
/**
* Script Feature realising a Menu showing specific Controls for the different items
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Menu extends ScriptFeature {
/*
* Constants
*/
const FUNCTION_UPDATE_MENU = 'FML_UpdateMenu';
/*
* Protected properties
*/
/** @var MenuElement[] $elements */
protected $elements = array();
/** @var MenuElement $startElement */
protected $startElement = null;
/**
* Construct a new Menu Feature
*
* @param Control $item (optional) Item Control in the Menu bar
* @param Control $control (optional) Toggled Menu Control
*/
public function __construct(Control $item = null, Control $control = null) {
if ($item && $control) {
$this->addElement($item, $control);
}
}
/**
* Add a new Element to the Menu
*
* @param Control $item Item Control in the Menu bar
* @param Control $control Toggled Menu Control
* @param bool $isStartElement (optional) Whether the Menu should start with this Element
* @return static
*/
public function addElement(Control $item, Control $control, $isStartElement = false) {
$menuElement = new MenuElement($item, $control);
$this->appendElement($menuElement, $isStartElement);
return $this;
}
/**
* Append an Element to the Menu
*
* @param MenuElement $menuElement Menu Element
* @param bool $isStartElement (optional) Whether the Menu should start with this Element
* @return static
*/
public function appendElement(MenuElement $menuElement, $isStartElement = false) {
if (!in_array($menuElement, $this->elements, true)) {
array_push($this->elements, $menuElement);
if ($isStartElement) {
$this->setStartElement($menuElement);
} else if (count($this->elements) > 1) {
$menuElement->getControl()->setVisible(false);
}
}
return $this;
}
/**
* Set the Element to start with
*
* @param MenuElement $startElement Starting Element
* @return static
*/
public function setStartElement(MenuElement $startElement) {
$this->startElement = $startElement;
if (!in_array($startElement, $this->elements, true)) {
array_push($this->elements, $startElement);
}
return $this;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$updateFunctionName = self::FUNCTION_UPDATE_MENU;
$elementsArrayText = $this->getElementsArrayText();
// OnInit
if ($this->startElement) {
$startControlId = $this->startElement->getControl()->getId(true, true);
$initScriptText = "
{$updateFunctionName}({$elementsArrayText}, {$startControlId});";
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $initScriptText, true);
}
// MouseClick
$scriptText = "
declare MenuElements = {$elementsArrayText};
if (MenuElements.existskey(Event.Control.ControlId)) {
declare ShownControlId = MenuElements[Event.Control.ControlId];
{$updateFunctionName}(MenuElements, ShownControlId);
}";
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $scriptText, true);
// Update menu function
$updateFunctionText = "
Void {$updateFunctionName}(Text[Text] _Elements, Text _ShownControlId) {
foreach (ItemId => ControlId in _Elements) {
declare Control <=> (Page.GetFirstChild(ControlId));
Control.Visible = (ControlId == _ShownControlId);
}
}";
$script->addScriptFunction($updateFunctionName, $updateFunctionText);
return $this;
}
/**
* Build the array text for the Elements
*
* @return string
*/
protected function getElementsArrayText() {
$elements = array();
foreach ($this->elements as $element) {
$elementId = $element->getItem()->getId();
$elements[$elementId] = $element->getControl()->getId();
}
return Builder::getArray($elements, true);
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Types\Scriptable;
/**
* Menu Element for the Menu Feature
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class MenuElement {
/*
* Protected properties
*/
protected $item = null;
protected $control = null;
/**
* Create a new Menu Element
*
* @param Control $item (optional) Item Control in the Menu bar
* @param Control $control (optional) Toggled Menu Control
*/
public function __construct(Control $item = null, Control $control = null) {
if ($item !== null) {
$this->setItem($item);
}
if ($control !== null) {
$this->setControl($control);
}
}
/**
* Set the Item Control
*
* @param Control $item Item Control in the Menu bar
* @return static
*/
public function setItem(Control $item) {
$item->checkId();
if ($item instanceof Scriptable) {
$item->setScriptEvents(true);
}
$this->item = $item;
return $this;
}
/**
* Get the Item Control
*
* @return \FML\Controls\Control
*/
public function getItem() {
return $this->item;
}
/**
* Set the Menu Control
*
* @param Control $control Toggled Menu Control
* @return static
*/
public function setControl(Control $control) {
$this->control = $control->checkId();
return $this;
}
/**
* Get the Menu Control
*
* @return \FML\Controls\Control
*/
public function getControl() {
return $this->control;
}
}

View File

@ -0,0 +1,348 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Controls\Label;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptInclude;
use FML\Script\ScriptLabel;
/**
* Script Feature realising a mechanism for browsing through Pages
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Paging extends ScriptFeature {
/*
* Constants
*/
const VAR_CURRENT_PAGE = 'FML_Paging_CurrentPage';
const FUNCTION_UPDATE_CURRENT_PAGE = 'FML_UpdateCurrentPage';
/*
* Protected properties
*/
/** @var PagingPage[] $pages */
protected $pages = array();
/** @var PagingButton[] $buttons */
protected $buttons = array();
/** @var Label $label */
protected $label = null;
protected $startPageNumber = null;
protected $customMaxPageNumber = null;
protected $previousChunkAction = null;
protected $nextChunkAction = null;
protected $chunkActionAppendsPageNumber = null;
/**
* Construct a new Paging Script Feature
*
* @param Label $label (optional) Page number Label
*/
public function __construct(Label $label = null) {
if ($label !== null) {
$this->setLabel($label);
}
}
/**
* Add a new Page Control
*
* @param Control $pageControl Page Control
* @param string $pageNumber (optional) Page number
* @return static
*/
public function addPage(Control $pageControl, $pageNumber = null) {
if ($pageNumber === null) {
$pageNumber = count($this->pages) + 1;
}
$page = new PagingPage($pageControl, $pageNumber);
$this->appendPage($page);
return $this;
}
/**
* Append a Page
*
* @param PagingPage $page Paging Page
* @return static
*/
public function appendPage(PagingPage $page) {
if (!in_array($page, $this->pages, true)) {
array_push($this->pages, $page);
}
return $this;
}
/**
* Add a new Button to browse through the Pages
*
* @param Control $buttonControl Button used for browsing
* @param int $browseAction (optional) Number of browsed Pages per click
* @return static
*/
public function addButton(Control $buttonControl, $browseAction = null) {
if ($browseAction === null) {
$buttonCount = count($this->buttons);
if ($buttonCount % 2 === 0) {
$browseAction = $buttonCount / 2 + 1;
} else {
$browseAction = $buttonCount / -2 - 1;
}
}
$button = new PagingButton($buttonControl, $browseAction);
$this->appendButton($button);
return $this;
}
/**
* Append a Button to browse through Pages
*
* @param PagingButton $button Paging Button
* @return static
*/
public function appendButton(PagingButton $button) {
if (!in_array($button, $this->buttons, true)) {
array_push($this->buttons, $button);
}
return $this;
}
/**
* Set the Label showing the Page number
*
* @param Label $label Page number Label
* @return static
*/
public function setLabel(Label $label) {
$this->label = $label->checkId();
return $this;
}
/**
* Set the Start Page number
*
* @param int $startPageNumber Page number to start with
* @return static
*/
public function setStartPageNumber($startPageNumber) {
$this->startPageNumber = (int)$startPageNumber;
}
/**
* Set a custom maximum Page number for using chunks
*
* @param int $maxPageNumber Custom maximum Page number
* @return static
*/
public function setCustomMaxPageNumber($maxPageNumber) {
$this->customMaxPageNumber = (int)$maxPageNumber;
return $this;
}
/**
* Set the action triggered when the previous chunk is needed
*
* @param string $previousChunkAction Triggered action
* @return static
*/
public function setPreviousChunkAction($previousChunkAction) {
$this->previousChunkAction = (string)$previousChunkAction;
return $this;
}
/**
* Set the action triggered when the next chunk is needed
*
* @param string $nextChunkAction Triggered action
* @return static
*/
public function setNextChunkAction($nextChunkAction) {
$this->nextChunkAction = (string)$nextChunkAction;
return $this;
}
/**
* Set the actions triggered when another chunk is needed
*
* @param string $chunkAction Triggered action
* @return static
*/
public function setChunkActions($chunkAction) {
$this->setNextChunkAction($chunkAction);
$this->setPreviousChunkAction($chunkAction);
return $this;
}
/**
* Set if the chunk action should get the needed Page number appended
*
* @param bool $appendPageNumber Whether to append the needed Page number
* @return static
*/
public function setChunkActionAppendsPageNumber($appendPageNumber) {
$this->chunkActionAppendsPageNumber = (bool)$appendPageNumber;
return $this;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
if (empty($this->pages)) {
return $this;
}
$script->setScriptInclude(ScriptInclude::TEXTLIB);
$currentPageVariable = self::VAR_CURRENT_PAGE;
$updatePageFunction = self::FUNCTION_UPDATE_CURRENT_PAGE;
$minPageNumber = 1;
$startPageNumber = (is_int($this->startPageNumber) ? $this->startPageNumber : $minPageNumber);
$maxPage = $this->getMaxPage();
$maxPageNumber = $this->customMaxPageNumber;
if (!is_int($maxPageNumber)) {
$maxPageNumber = $maxPage->getPageNumber();
}
$pagingId = $maxPage->getControl()->getId(true, true);
$pageLabelId = '""';
if ($this->label) {
$pageLabelId = $this->label->getId(true, true);
}
$pagesArrayText = $this->getPagesArrayText();
$pageButtonsArrayText = $this->getPageButtonsArrayText();
$previousChunkAction = Builder::escapeText($this->previousChunkAction, true);
$nextChunkAction = Builder::escapeText($this->nextChunkAction, true);
$chunkActionAppendsPageNumber = Builder::getBoolean($this->chunkActionAppendsPageNumber);
// Init
$initScriptText = "
declare {$currentPageVariable} for This = Integer[Text];
{$currentPageVariable}[{$pagingId}] = {$startPageNumber};
{$updatePageFunction}({$pagingId}, {$pageLabelId}, 0, {$minPageNumber}, {$maxPageNumber}, {$pagesArrayText}, {$previousChunkAction}, {$nextChunkAction}, {$chunkActionAppendsPageNumber});";
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $initScriptText, true);
// MouseClick
$clickScriptText = "
declare PageButtons = {$pageButtonsArrayText};
if (PageButtons.existskey(Event.Control.ControlId)) {
declare BrowseAction = PageButtons[Event.Control.ControlId];
{$updatePageFunction}({$pagingId}, {$pageLabelId}, BrowseAction, {$minPageNumber}, {$maxPageNumber}, {$pagesArrayText}, {$previousChunkAction}, {$nextChunkAction}, {$chunkActionAppendsPageNumber});
}";
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $clickScriptText, true);
// Update function
$functionText = "
Void {$updatePageFunction}(Text _PagingId, Text _PageLabelId, Integer _BrowseAction, Integer _MinPageNumber, Integer _MaxPageNumber, Text[Integer] _Pages, Text _PreviousChunkAction, Text _NextChunkAction, Boolean _ChunkActionAppendPageNumber) {
declare {$currentPageVariable} for This = Integer[Text];
if (!{$currentPageVariable}.existskey(_PagingId)) return;
declare CurrentPage = {$currentPageVariable}[_PagingId] + _BrowseAction;
if (CurrentPage < _MinPageNumber) {
CurrentPage = _MinPageNumber;
} else if (CurrentPage > _MaxPageNumber) {
CurrentPage = _MaxPageNumber;
}
{$currentPageVariable}[_PagingId] = CurrentPage;
declare PageFound = False;
foreach (PageNumber => PageId in _Pages) {
declare PageControl <=> Page.GetFirstChild(PageId);
PageControl.Visible = (CurrentPage == PageNumber);
if (PageControl.Visible) {
PageFound = True;
}
}
if (!PageFound && _BrowseAction != 0) {
declare Text ChunkAction;
if (_BrowseAction < 0) {
ChunkAction = _PreviousChunkAction;
} else {
ChunkAction = _NextChunkAction;
}
if (_ChunkActionAppendPageNumber) {
ChunkAction ^= CurrentPage;
}
TriggerPageAction(ChunkAction);
}
if (_PageLabelId == " . Builder::EMPTY_STRING . ") return;
declare PageLabel <=> (Page.GetFirstChild(_PageLabelId) as CMlLabel);
if (PageLabel == Null) return;
PageLabel.Value = CurrentPage^\"/\"^_MaxPageNumber;
}";
$script->addScriptFunction($updatePageFunction, $functionText);
return $this;
}
/**
* Get the minimum Page
*
* @return \FML\Script\Features\PagingPage
*/
protected function getMinPage() {
$minPageNumber = null;
$minPage = null;
foreach ($this->pages as $page) {
$pageNumber = $page->getPageNumber();
if ($minPageNumber === null || $pageNumber < $minPageNumber) {
$minPageNumber = $pageNumber;
$minPage = $page;
}
}
return $minPage;
}
/**
* Get the maximum Page
*
* @return \FML\Script\Features\PagingPage
*/
protected function getMaxPage() {
$maxPageNumber = null;
$maxPage = null;
foreach ($this->pages as $page) {
$pageNumber = $page->getPageNumber();
if ($maxPageNumber === null || $pageNumber > $maxPageNumber) {
$maxPageNumber = $pageNumber;
$maxPage = $page;
}
}
return $maxPage;
}
/**
* Build the array text for the Pages
*
* @return string
*/
protected function getPagesArrayText() {
if (empty($this->pages)) {
return Builder::getArray(array(0 => ''), true);
}
$pages = array();
foreach ($this->pages as $page) {
$pages[$page->getPageNumber()] = $page->getControl()->getId();
}
return Builder::getArray($pages, true);
}
/**
* Build the array text for the Page Buttons
*
* @return string
*/
protected function getPageButtonsArrayText() {
if (empty($this->buttons)) {
return Builder::getArray(array('' => 0), true);
}
$pageButtons = array();
foreach ($this->buttons as $pageButton) {
$pageButtons[$pageButton->getControl()->getId()] = $pageButton->getBrowseAction();
}
return Builder::getArray($pageButtons, true);
}
}

View File

@ -0,0 +1,81 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Types\Scriptable;
/**
* Paging Button for browsing through Pages
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class PagingButton {
/*
* Protected properties
*/
/** @var Control $control */
protected $control = null;
protected $browseAction = null;
/**
* Construct a new Paging Button
*
* @param Control $control (optional) Browse Control
* @param int $browseAction (optional) Number of browsed Pages per Click
*/
public function __construct(Control $control = null, $browseAction = null) {
if ($control !== null) {
$this->setControl($control);
}
if ($browseAction !== null) {
$this->setBrowseAction($browseAction);
}
}
/**
* Set the Button Control
*
* @param Control $control Browse Control
* @return static
*/
public function setControl(Control $control) {
$control->checkId();
if ($control instanceof Scriptable) {
$control->setScriptEvents(true);
}
$this->control = $control;
return $this;
}
/**
* Get the Button Control
*
* @return \FML\Controls\Control
*/
public function getControl() {
return $this->control;
}
/**
* Set the browse action
*
* @param int $browseAction Number of browsed Pages per click
* @return static
*/
public function setBrowseAction($browseAction) {
$this->browseAction = (int)$browseAction;
return $this;
}
/**
* Get the browse action
*
* @return int
*/
public function getBrowseAction() {
return $this->browseAction;
}
}

View File

@ -0,0 +1,74 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
/**
* Paging Page
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class PagingPage {
/*
* Protected properties
*/
/** @var Control $control */
protected $control = null;
protected $number = null;
/**
* Construct a new Paging Page
*
* @param Control $control (optional) Page Control
* @param int $pageNumber (optional) Number of the Page
*/
public function __construct(Control $control = null, $pageNumber = 1) {
if ($control !== null) {
$this->setControl($control);
}
$this->setPageNumber($pageNumber);
}
/**
* Set the Page Control
*
* @param Control $control Page Control
* @return static
*/
public function setControl(Control $control) {
$this->control = $control->checkId();
return $this;
}
/**
* Get the Page Control
*
* @return \FML\Controls\Control
*/
public function getControl() {
return $this->control;
}
/**
* Set the Page number
*
* @param int $pageNumber Number of the Page
* @return static
*/
public function setPageNumber($pageNumber) {
$this->number = (int)$pageNumber;
return $this;
}
/**
* Get the Page number
*
* @return int
*/
public function getPageNumber() {
return $this->number;
}
}

View File

@ -0,0 +1,108 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for opening a player profile
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class PlayerProfile extends ScriptFeature {
/*
* Protected properties
*/
protected $login = null;
/** @var Control $control */
protected $control = null;
protected $labelName = null;
/**
* Construct a new Player Profile Feature
*
* @param string $login (optional) Player login
* @param Control $control (optional) Action Control
* @param string $labelName (optional) Script Label name
*/
public function __construct($login = null, Control $control = null, $labelName = ScriptLabel::MOUSECLICK) {
$this->setLogin($login);
if ($control !== null) {
$this->setControl($control);
}
$this->setLabelName($labelName);
}
/**
* Set the login of the opened player
*
* @param string $login Player login
* @return static
*/
public function setLogin($login) {
$this->login = $login;
return $this;
}
/**
* Set the Control
*
* @param Control $control Profile Control
* @return static
*/
public function setControl(Control $control) {
$control->checkId();
if ($control instanceof Scriptable) {
$control->setScriptEvents(true);
}
$this->control = $control;
return $this;
}
/**
* Set the label name
*
* @param string $labelName Script Label name
* @return static
*/
public function setLabelName($labelName) {
$this->labelName = (string)$labelName;
return $this;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
return $this;
}
/**
* Get the script text
*
* @return string
*/
protected function getScriptText() {
$login = Builder::escapeText($this->login, true);
if ($this->control) {
// Control event
$controlId = Builder::escapeText($this->control->getId(), true);
$scriptText = "
if (Event.Control.ControlId == {$controlId}) {
ShowProfile({$login});
}";
} else {
// Other
$scriptText = "
ShowProfile({$login});";
}
return $scriptText;
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace FML\Script\Features;
use FML\Script\Script;
use FML\Types\ScriptFeatureable;
/**
* ManiaLink Script Feature Class
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
abstract class ScriptFeature {
/**
* Collect the Script Features of the given objects
*
* @return ScriptFeature[]
*/
public static function collect() {
$params = func_get_args();
$scriptFeatures = array();
foreach ($params as $object) {
if ($object instanceof ScriptFeatureable) {
$scriptFeatures = array_merge($scriptFeatures, $object->getScriptFeatures());
} else if ($object instanceof ScriptFeature) {
array_push($scriptFeatures, $object);
}
}
return $scriptFeatures;
}
/**
* Prepare the given Script for rendering by adding the needed Labels, etc.
*
* @param Script $script Script to prepare
* @return static
*/
public abstract function prepare(Script $script);
}

View File

@ -0,0 +1,138 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for toggling Controls
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Toggle extends ScriptFeature {
/*
* Protected properties
*/
/** @var Control $togglingControl */
protected $togglingControl = null;
/** @var Control $toggledControl */
protected $toggledControl = null;
protected $labelName = null;
protected $onlyShow = null;
protected $onlyHide = null;
/**
* Construct a new Toggle Feature
*
* @param Control $togglingControl (optional) Toggling Control
* @param Control $toggledControl (optional) Toggled Control
* @param string $labelName (optional) Script Label name
* @param bool $onlyShow (optional) Whether it should only show the Control but not toggle
* @param bool $onlyHide (optional) Whether it should only hide the Control but not toggle
*/
public function __construct(Control $togglingControl = null, Control $toggledControl = null, $labelName = ScriptLabel::MOUSECLICK,
$onlyShow = false, $onlyHide = false) {
if ($togglingControl !== null) {
$this->setTogglingControl($togglingControl);
}
if ($toggledControl !== null) {
$this->setToggledControl($toggledControl);
}
$this->setLabelName($labelName);
$this->setOnlyShow($onlyShow);
$this->setOnlyHide($onlyHide);
}
/**
* Set the toggling Control
*
* @param Control $control Toggling Control
* @return static
*/
public function setTogglingControl(Control $control) {
$control->checkId();
if ($control instanceof Scriptable) {
$control->setScriptEvents(true);
}
$this->togglingControl = $control;
return $this;
}
/**
* Set the toggled Control
*
* @param Control $control Toggling Control
* @return static
*/
public function setToggledControl(Control $control) {
$this->toggledControl = $control->checkId();
return $this;
}
/**
* Set the label name
*
* @param string $labelName Script Label Name
* @return static
*/
public function setLabelName($labelName) {
$this->labelName = (string)$labelName;
return $this;
}
/**
* Set to only show
*
* @param bool $onlyShow Whether it should only show the Control but not toggle
* @return static
*/
public function setOnlyShow($onlyShow) {
$this->onlyShow = (bool)$onlyShow;
return $this;
}
/**
* Set to only hide
*
* @param bool $onlyHide Whether it should only hide the Control but not toggle
* @return static
*/
public function setOnlyHide($onlyHide) {
$this->onlyHide = (bool)$onlyHide;
return $this;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
return $this;
}
/**
* Get the script text
*
* @return string
*/
protected function getScriptText() {
$togglingControlId = $this->togglingControl->getId(true, true);
$toggledControlId = $this->toggledControl->getId(true, true);
$visibility = '!ToggleControl.Visible';
if ($this->onlyShow) {
$visibility = 'True';
} else if ($this->onlyHide) {
$visibility = 'False';
}
return "
if (Event.Control.ControlId == {$togglingControlId}) {
declare ToggleControl = Page.GetFirstChild({$toggledControlId});
ToggleControl.Visible = {$visibility};
}";
}
}

View File

@ -0,0 +1,162 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Controls\Label;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for showing Tooltips
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Tooltip extends ScriptFeature {
/*
* Protected properties
*/
/** @var Control $hoverControl */
protected $hoverControl = null;
/** @var Control $tooltipControl */
protected $tooltipControl = null;
protected $stayOnClick = null;
protected $invert = null;
protected $text = null;
/**
* Construct a new Tooltip Feature
*
* @param Control $hoverControl (optional) Hover Control
* @param Control $tooltipControl (optional) Tooltip Control
* @param bool $stayOnClick (optional) Whether the Tooltip should stay on click
* @param bool $invert (optional) Whether the visibility toggling should be inverted
* @param string $text (optional) Text to display if the TooltipControl is a Label
*/
public function __construct(Control $hoverControl = null, Control $tooltipControl = null, $stayOnClick = false, $invert = false, $text = null) {
if ($hoverControl !== null) {
$this->setHoverControl($hoverControl);
}
if ($tooltipControl !== null) {
$this->setTooltipControl($tooltipControl);
}
$this->setStayOnClick($stayOnClick);
$this->setInvert($invert);
if ($text !== null) {
$this->setText($text);
}
}
/**
* Set the Hover Control
*
* @param Control $hoverControl Hover Control
* @return static
*/
public function setHoverControl(Control $hoverControl) {
$hoverControl->checkId();
if ($hoverControl instanceof Scriptable) {
$hoverControl->setScriptEvents(true);
}
$this->hoverControl = $hoverControl;
return $this;
}
/**
* Set the Tooltip Control
*
* @param Control $tooltipControl Tooltip Control
* @return static
*/
public function setTooltipControl(Control $tooltipControl) {
$this->tooltipControl = $tooltipControl->checkId()->setVisible(false);
return $this;
}
/**
* Set to only show
*
* @param bool $stayOnClick (optional) Whether the Tooltip should stay on click
* @return static
*/
public function setStayOnClick($stayOnClick) {
$this->stayOnClick = (bool)$stayOnClick;
return $this;
}
/**
* Set to only hide
*
* @param bool $invert (optional) Whether the visibility toggling should be inverted
* @return static
*/
public function setInvert($invert) {
$this->invert = (bool)$invert;
return $this;
}
/**
* Set text
*
* @param string $text (optional) Text to display if the TooltipControl is a Label
* @return static
*/
public function setText($text) {
$this->text = (string)$text;
return $this;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$hoverControlId = $this->hoverControl->getId(true, true);
$tooltipControlId = $this->tooltipControl->getId(true, true);
// MouseOver
$visibility = ($this->invert ? 'False' : 'True');
$scriptText = "
if (Event.Control.ControlId == {$hoverControlId}) {
declare TooltipControl = Page.GetFirstChild({$tooltipControlId});
TooltipControl.Visible = {$visibility};";
if (is_string($this->text) && ($this->tooltipControl instanceof Label)) {
$tooltipText = Builder::escapeText($this->text, true);
$scriptText .= "
declare TooltipLabel = (TooltipControl as CMlLabel);
TooltipLabel.Value = {$tooltipText};";
}
$scriptText .= "
}";
$script->appendGenericScriptLabel(ScriptLabel::MOUSEOVER, $scriptText);
// MouseOut
$visibility = ($this->invert ? 'True' : 'False');
$scriptText = "
if (Event.Control.ControlId == {$hoverControlId}) {
declare TooltipControl = Page.GetFirstChild({$tooltipControlId});";
if ($this->stayOnClick) {
$scriptText .= "
declare FML_Clicked for Event.Control = False;
if (!FML_Clicked) ";
}
$scriptText .= "
TooltipControl.Visible = {$visibility};
}";
$script->appendGenericScriptLabel(ScriptLabel::MOUSEOUT, $scriptText);
// MouseClick
if ($this->stayOnClick) {
$scriptText = "
if (Event.Control.ControlId == {$hoverControlId}) {
declare FML_Clicked for Event.Control = False;
FML_Clicked = !FML_Clicked;
}";
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $scriptText);
}
return $this;
}
}

View File

@ -0,0 +1,168 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Control;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptLabel;
use FML\Types\Scriptable;
/**
* Script Feature for playing a UISound
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class UISound extends ScriptFeature {
/*
* Constants
*/
const Bonus = 'Bonus';
const Capture = 'Capture';
const Checkpoint = 'Checkpoint';
const Combo = 'Combo';
const Custom1 = 'Custom1';
const Custom2 = 'Custom2';
const Custom3 = 'Custom3';
const Custom4 = 'Custom4';
const Default_ = 'Default';
const EndMatch = 'EndMatch';
const EndRound = 'EndRound';
const Finish = 'Finish';
const FirstHit = 'FirstHit';
const Notice = 'Notice';
const PhaseChange = 'PhaseChange';
const PlayerEliminated = 'PlayerEliminated';
const PlayerHit = 'PlayerHit';
const PlayersRemaining = 'PlayersRemaining';
const RankChange = 'RankChange';
const Record = 'Record';
const ScoreProgress = 'ScoreProgress';
const Silence = 'Silence';
const StartMatch = 'StartMatch';
const StartRound = 'StartRound';
const TieBreakPoint = 'TieBreakPoint';
const TiePoint = 'TiePoint';
const TimeOut = 'TimeOut';
const VictoryPoint = 'VictoryPoint';
const Warning = 'Warning';
/*
* Protected properties
*/
protected $soundName = null;
/** @var Control $control */
protected $control = null;
protected $variant = 0;
protected $volume = 1.;
protected $labelName = null;
/**
* Construct a new UISound Feature
*
* @param string $soundName (optional) Played sound
* @param Control $control (optional) Action Control
* @param int $variant (optional) Sound variant
* @param string $labelName (optional) Script Label name
*/
public function __construct($soundName = null, Control $control = null, $variant = 0, $labelName = ScriptLabel::MOUSECLICK) {
if ($soundName !== null) {
$this->setSoundName($soundName);
}
if ($control !== null) {
$this->setControl($control);
}
$this->setVariant($variant);
$this->setLabelName($labelName);
}
/**
* Set the sound to play
*
* @param string $soundName Sound name
* @return static
*/
public function setSoundName($soundName) {
$this->soundName = (string)$soundName;
return $this;
}
/**
* Set the Control
*
* @param Control $control Action Control
* @return static
*/
public function setControl(Control $control) {
$control->checkId();
if ($control instanceof Scriptable) {
$control->setScriptEvents(true);
}
$this->control = $control;
return $this;
}
/**
* Set the sound variant
*
* @param int $variant Sound variant
* @return static
*/
public function setVariant($variant) {
$this->variant = (int)$variant;
return $this;
}
/**
* Set the volume
*
* @param float $volume Sound volume
* @return static
*/
public function setVolume($volume) {
$this->volume = (float)$volume;
return $this;
}
/**
* Set the label name
*
* @param string $labelName Script Label name
* @return static
*/
public function setLabelName($labelName) {
$this->labelName = (string)$labelName;
return $this;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
$script->appendGenericScriptLabel($this->labelName, $this->getScriptText());
return $this;
}
/**
* Get the script text
*
* @return string
*/
protected function getScriptText() {
if ($this->control) {
// Control event
$controlId = Builder::escapeText($this->control->getId(), true);
$scriptText = "
if (Event.Control.ControlId == {$controlId}) {
PlayUiSound(CMlScriptIngame::EUISound::{$this->soundName}, {$this->variant}, {$this->volume});
}";
} else {
// Other
$scriptText = "
PlayUiSound(CMlScriptIngame::EUISound::{$this->soundName}, {$this->variant}, {$this->volume});";
}
return $scriptText;
}
}

View File

@ -0,0 +1,226 @@
<?php
namespace FML\Script\Features;
use FML\Controls\Entry;
use FML\Controls\Label;
use FML\Script\Builder;
use FML\Script\Script;
use FML\Script\ScriptInclude;
use FML\Script\ScriptLabel;
/**
* Script Feature for creating a ValuePicker behavior
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ValuePickerFeature extends ScriptFeature {
/*
* Constants
*/
const FUNCTION_UPDATE_PICKER_VALUE = 'FML_UpdatePickerValue';
const VAR_PICKER_VALUES = 'FML_Picker_Values';
const VAR_PICKER_DEFAULT_VALUE = 'FML_Picker_Default_Value';
const VAR_PICKER_ENTRY_ID = 'FML_Picker_EntryId';
/*
* Protected properties
*/
/** @var Label $label */
protected $label = null;
/** @var Entry $entry */
protected $entry = null;
protected $values = array();
protected $default = null;
/**
* Construct a new ValuePicker Feature
*
* @param Label $label (optional) ValuePicker Label
* @param Entry $entry (optional) Hidden Entry
* @param array $values (optional) Possible values
* @param string $default (optional) Default value
*/
public function __construct(Label $label = null, Entry $entry = null, array $values = array(), $default = null) {
if ($label !== null) {
$this->setLabel($label);
}
if ($entry !== null) {
$this->setEntry($entry);
}
if (!empty($values)) {
$this->setValues($values);
}
if ($default !== null) {
$this->setDefault($default);
}
}
/**
* Set the ValuePicker Label
*
* @param Label $label ValuePicker Label
* @return static
*/
public function setLabel(Label $label) {
$this->label = $label->checkId()->setScriptEvents(true);
return $this;
}
/**
* Get the ValuePicker Label
*
* @return \FML\Controls\Label
*/
public function getLabel() {
return $this->label;
}
/**
* Set the hidden Entry
*
* @param Entry $entry Hidden Entry
* @return static
*/
public function setEntry(Entry $entry) {
$this->entry = $entry->checkId();
return $this;
}
/**
* Get the hidden Entry
*
* @return \FML\Controls\Entry
*/
public function getEntry() {
return $this->entry;
}
/**
* Set the possible values
*
* @param array $values Possible values
* @return static
*/
public function setValues(array $values) {
$this->values = array();
foreach ($values as $value) {
array_push($this->values, (string)$value);
}
return $this;
}
/**
* Set the default value
*
* @param string $default Default value
* @return static
*/
public function setDefault($default) {
$this->default = (string)$default;
}
/**
* Get the default value
*
* @return string
*/
public function getDefault() {
if ($this->default) {
return $this->default;
}
if (!empty($this->values)) {
return reset($this->values);
}
return null;
}
/**
* @see \FML\Script\Features\ScriptFeature::prepare()
*/
public function prepare(Script $script) {
if ($this->label) {
$script->setScriptInclude(ScriptInclude::TEXTLIB);
$script->addScriptFunction(self::FUNCTION_UPDATE_PICKER_VALUE, $this->buildUpdatePickerValueFunction());
$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->buildInitScriptText(), true);
$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $this->buildClickScriptText());
}
return $this;
}
/**
* Build the function text
*
* @return string
*/
protected function buildUpdatePickerValueFunction() {
return "
Void " . self::FUNCTION_UPDATE_PICKER_VALUE . "(CMlLabel _Label) {
declare " . self::VAR_PICKER_VALUES . " as Values for _Label = Text[];
declare NewValueIndex = -1;
if (Values.exists(_Label.Value)) {
declare ValueIndex = Values.keyof(_Label.Value);
ValueIndex += 1;
if (Values.existskey(ValueIndex)) {
NewValueIndex = ValueIndex;
} else {
NewValueIndex = 0;
}
}
declare NewValue = " . Builder::EMPTY_STRING . ";
if (Values.existskey(NewValueIndex)) {
NewValue = Values[NewValueIndex];
} else {
declare " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for _Label = " . Builder::EMPTY_STRING . ";
NewValue = Default;
}
_Label.Value = NewValue;
declare " . self::VAR_PICKER_ENTRY_ID . " as EntryId for _Label = " . Builder::EMPTY_STRING . ";
if (EntryId != " . Builder::EMPTY_STRING . ") {
declare Entry <=> (Page.GetFirstChild(EntryId) as CMlEntry);
Entry.Value = NewValue;
}
}";
}
/**
* Build the init script text
*
* @return string
*/
protected function buildInitScriptText() {
$labelId = $this->label->getId(true, true);
$entryId = '""';
if ($this->entry) {
$entryId = $this->entry->getId(true, true);
}
$values = Builder::getArray($this->values);
$default = Builder::escapeText($this->getDefault(), true);
return "
declare Label_Picker <=> (Page.GetFirstChild({$labelId}) as CMlLabel);
declare Text[] " . self::VAR_PICKER_VALUES . " as Values for Label_Picker;
Values = {$values};
declare Text " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for Label_Picker;
Default = {$default};
declare Text " . self::VAR_PICKER_ENTRY_ID . " as EntryId for Label_Picker;
EntryId = {$entryId};
" . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker);
";
}
/**
* Build the script text for Label clicks
*
* @return string
*/
protected function buildClickScriptText() {
$labelId = $this->label->getId(true, true);
return "
if (Event.ControlId == {$labelId}) {
declare Label_Picker <=> (Event.Control as CMlLabel);
" . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker);
}";
}
}

317
libs/FML/Script/Script.php Normal file
View File

@ -0,0 +1,317 @@
<?php
namespace FML\Script;
use FML\Script\Features\ScriptFeature;
/**
* Class representing the ManiaLink Script
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Script {
/*
* Constants
*/
const TICKINTERVAL = 250;
const VAR_ScriptStart = 'FML_ScriptStart';
const VAR_LoopCounter = 'FML_LoopCounter';
const VAR_LastTick = 'FML_LastTick';
/*
* Protected properties
*/
protected $tagName = 'script';
protected $features = array();
protected $includes = array();
protected $constants = array();
protected $functions = array();
protected $customLabels = array();
protected $genericLabels = array();
/**
* Set a Script Include
*
* @param string $file Include file
* @param string $namespace Include namespace
* @return static
*/
public function setScriptInclude($file, $namespace = null) {
if ($file instanceof ScriptInclude) {
$scriptInclude = $file;
} else {
$scriptInclude = new ScriptInclude($file, $namespace);
}
$this->includes[$scriptInclude->getNamespace()] = $scriptInclude;
return $this;
}
/**
* Add a Script Constant
*
* @param string $name Constant name
* @param string $value Constant value
* @return static
*/
public function addScriptConstant($name, $value = null) {
if ($name instanceof ScriptConstant) {
$scriptConstant = $name;
} else {
$scriptConstant = new ScriptConstant($name, $value);
}
if (!in_array($scriptConstant, $this->constants)) {
array_push($this->constants, $scriptConstant);
}
return $this;
}
/**
* Add a Script Function
*
* @param string $name Function name
* @param string $text Function text
* @return static
*/
public function addScriptFunction($name, $text = null) {
if ($name instanceof ScriptFunction) {
$scriptFunction = $name;
} else {
$scriptFunction = new ScriptFunction($name, $text);
}
if (!in_array($scriptFunction, $this->functions)) {
array_push($this->functions, $scriptFunction);
}
return $this;
}
/**
* Add a custom Script text
*
* @param string $name Label name
* @param string $text Script text
* @return static
*/
public function addCustomScriptLabel($name, $text = null) {
if ($name instanceof ScriptLabel) {
$scriptLabel = $name;
} else {
$scriptLabel = new ScriptLabel($name, $text);
}
array_push($this->customLabels, $scriptLabel);
return $this;
}
/**
* Append a generic Script text for the next rendering
*
* @param string $name Label name
* @param string $text Script text
* @param bool $isolated (optional) Whether to isolate the Label Script
* @return static
*/
public function appendGenericScriptLabel($name, $text = null, $isolated = false) {
if ($name instanceof ScriptLabel) {
$scriptLabel = $name;
} else {
$scriptLabel = new ScriptLabel($name, $text, $isolated);
}
array_push($this->genericLabels, $scriptLabel);
return $this;
}
/**
* Remove all generic Script texts
*
* @return static
*/
public function resetGenericScriptLabels() {
$this->genericLabels = array();
return $this;
}
/**
* Add a Script Feature
*
* @param ScriptFeature $feature Script Feature
* @return static
*/
public function addFeature(ScriptFeature $feature) {
if (!in_array($feature, $this->features, true)) {
array_push($this->features, $feature);
}
return $this;
}
/**
* Load the given Script Feature
*
* @param ScriptFeature $scriptFeature Script Feature to load
* @return static
*/
public function loadFeature(ScriptFeature $scriptFeature) {
$scriptFeature->prepare($this);
return $this;
}
/**
* Load the given Script Features
*
* @param ScriptFeature[] $scriptFeatures Script Features to load
* @return static
*/
public function loadFeatures(array $scriptFeatures) {
foreach ($scriptFeatures as $scriptFeature) {
$this->loadFeature($scriptFeature);
}
return $this;
}
/**
* Check if the Script has content so that it needs to be rendered
*
* @return bool
*/
public function needsRendering() {
if ($this->features || $this->customLabels || $this->genericLabels) {
return true;
}
return false;
}
/**
* Build the complete Script text
*
* @return string
*/
public function buildScriptText() {
$scriptText = PHP_EOL;
$scriptText .= $this->getHeaderComment();
$scriptText .= $this->getIncludes();
$scriptText .= $this->getConstants();
$scriptText .= $this->getFunctions();
$scriptText .= $this->getLabels();
$scriptText .= $this->getMainFunction();
return $scriptText;
}
/**
* Build the Script XML element
*
* @param \DOMDocument $domDocument DOMDocument for which the XML element should be created
* @return \DOMElement
*/
public function render(\DOMDocument $domDocument) {
$this->loadFeatures($this->features);
$scriptXml = $domDocument->createElement($this->tagName);
$scriptText = $this->buildScriptText();
$scriptComment = $domDocument->createComment($scriptText);
$scriptXml->appendChild($scriptComment);
return $scriptXml;
}
/**
* Get the header comment
*
* @return string
*/
protected function getHeaderComment() {
$headerComment = '/****************************************************
* FancyManiaLinks';
if (defined('FML_VERSION')) {
$headerComment .= ' v' . FML_VERSION;
}
$headerComment .= ' by steeffeen *
* http://github.com/steeffeen/FancyManiaLinks *
****************************************************/
';
return $headerComment;
}
/**
* Get the Includes text
*
* @return string
*/
protected function getIncludes() {
$includesText = implode(PHP_EOL, $this->includes);
return $includesText;
}
/**
* Get the Constants text
*
* @return string
*/
protected function getConstants() {
$constantsText = implode(PHP_EOL, $this->constants);
return $constantsText;
}
/**
* Get the Functions text
*
* @return string
*/
protected function getFunctions() {
$functionsText = implode(PHP_EOL, $this->functions);
return $functionsText;
}
/**
* Get the Labels text
*
* @return string
*/
protected function getLabels() {
$customLabelsText = implode(PHP_EOL, $this->customLabels);
$genericLabelsText = implode(PHP_EOL, $this->genericLabels);
return $customLabelsText . $genericLabelsText;
}
/**
* Get the main function text
*
* @return string
*/
protected function getMainFunction() {
$mainFunction = '
Void FML_Dummy() {}
main() {
declare ' . self::VAR_ScriptStart . ' = Now;
+++' . ScriptLabel::ONINIT . '+++
declare ' . self::VAR_LoopCounter . ' = 0;
declare ' . self::VAR_LastTick . ' = 0;
while (True) {
yield;
foreach (Event in PendingEvents) {
switch (Event.Type) {
case CMlEvent::Type::EntrySubmit: {
+++' . ScriptLabel::ENTRYSUBMIT . '+++
}
case CMlEvent::Type::KeyPress: {
+++' . ScriptLabel::KEYPRESS . '+++
}
case CMlEvent::Type::MouseClick: {
+++' . ScriptLabel::MOUSECLICK . '+++
}
case CMlEvent::Type::MouseOut: {
+++' . ScriptLabel::MOUSEOUT . '+++
}
case CMlEvent::Type::MouseOver: {
+++' . ScriptLabel::MOUSEOVER . '+++
}
}
}
+++' . ScriptLabel::LOOP . '+++
' . self::VAR_LoopCounter . ' += 1;
if (' . self::VAR_LastTick . ' + ' . self::TICKINTERVAL . ' > Now) continue;
+++' . ScriptLabel::TICK . '+++
' . self::VAR_LastTick . ' = Now;
}
}';
return $mainFunction;
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace FML\Script;
/**
* Class representing a Constant of the ManiaLink Script
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ScriptConstant {
/*
* Protected properties
*/
protected $name = null;
protected $value = null;
/**
* Construct a new Script Constant
*
* @param string $name (optional) Constant name
* @param string $value (optional) Constant value
*/
public function __construct($name = null, $value = null) {
$this->setName($name);
$this->setValue($value);
}
/**
* Set the name
*
* @param string $name Constant name
* @return static
*/
public function setName($name) {
$this->name = (string)$name;
return $this;
}
/**
* Set the value
*
* @param string $value Constant value
* @return static
*/
public function setValue($value) {
$this->value = $value;
return $this;
}
/**
* Build the Script Constant text
*
* @return string
*/
public function __toString() {
return Builder::getConstant($this->name, $this->value);
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace FML\Script;
/**
* Class representing a Function of the ManiaLink Script
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ScriptFunction {
/*
* Protected properties
*/
protected $name = null;
protected $text = null;
/**
* Construct a new Script Function
*
* @param string $name (optional) Function name
* @param string $text (optional) Function text
*/
public function __construct($name = null, $text = null) {
$this->setName($name);
$this->setText($text);
}
/**
* Set the name
*
* @param string $name Function name
* @return static
*/
public function setName($name) {
$this->name = (string)$name;
return $this;
}
/**
* Set the text
*
* @param string $text Function text
* @return static
*/
public function setText($text) {
$this->text = (string)$text;
return $this;
}
/**
* Get the Script Function text
*
* @return string
*/
public function __toString() {
return $this->text;
}
}

View File

@ -0,0 +1,75 @@
<?php
namespace FML\Script;
/**
* Class representing an Include of the ManiaLink Script
*
* @author steeffeen
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ScriptInclude {
/*
* Constants
*/
const MATHLIB = 'MathLib';
const TEXTLIB = 'TextLib';
/*
* Protected properties
*/
protected $file = null;
protected $namespace = null;
/**
* Construct a new Script Include
*
* @param string $file (optional) Include file
* @param string $namespace (optional) Include namespace
*/
public function __construct($file = null, $namespace = null) {
$this->setFile($file);
$this->setNamespace($namespace);
}
/**
* Set the file
*
* @param string $file Include file
* @return static
*/
public function setFile($file) {
$this->file = (string)$file;
return $this;
}
/**
* Set the namespace
*
* @param string $namespace Include namespace
* @return static
*/
public function setNamespace($namespace) {
$this->namespace = (string)$namespace;
return $this;
}
/**
* Get the namespace
*
* @return string
*/
public function getNamespace() {
return $this->namespace;
}
/**
* Build the Script Include text
*
* @return string
*/
public function __toString() {
return Builder::getInclude($this->file, $this->namespace);
}
}

View File

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