2014-01-03 17:18:14 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FML\Script;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builder Class offering Methods to build ManiaScript
|
|
|
|
*
|
|
|
|
* @author steeffeen
|
2014-04-13 18:21:40 +02:00
|
|
|
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-01-03 17:18:14 +01:00
|
|
|
*/
|
|
|
|
abstract class Builder {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build a Label Implementation Block
|
|
|
|
*
|
2014-01-12 00:51:46 +01:00
|
|
|
* @param string $labelName Name of the Label
|
|
|
|
* @param string $implementationCode Label Implementation Coding (without declaration)
|
2014-01-03 17:18:14 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getLabelImplementationBlock($labelName, $implementationCode) {
|
|
|
|
$labelText = PHP_EOL . "***{$labelName}***" . PHP_EOL . "***{$implementationCode}***" . PHP_EOL;
|
|
|
|
return $labelText;
|
|
|
|
}
|
2014-01-05 16:04:55 +01:00
|
|
|
|
2014-01-19 19:30:21 +01:00
|
|
|
/**
|
|
|
|
* Escape dangerous Characters in the given Text
|
|
|
|
*
|
|
|
|
* @param string $text Text to escape
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function escapeText($text) {
|
|
|
|
$escapedText = $text;
|
2014-04-13 18:21:40 +02:00
|
|
|
$dangers = array('\\', '"', "\n");
|
|
|
|
$replacements = array('\\\\', '\\"', '\n');
|
2014-01-19 19:30:21 +01:00
|
|
|
$escapedText = str_ireplace($dangers, $replacements, $escapedText);
|
|
|
|
return $escapedText;
|
|
|
|
}
|
|
|
|
|
2014-01-05 16:04:55 +01:00
|
|
|
/**
|
|
|
|
* Get the Real String-Representation of the given Value
|
|
|
|
*
|
2014-01-19 19:30:21 +01:00
|
|
|
* @param float $value The Float Value to convert to a ManiaScript Real
|
2014-01-05 16:04:55 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getReal($value) {
|
|
|
|
$value = (float) $value;
|
|
|
|
$stringVal = (string) $value;
|
|
|
|
if (!fmod($value, 1)) $stringVal .= '.';
|
|
|
|
return $stringVal;
|
|
|
|
}
|
2014-02-16 13:59:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Boolean String-Representation of the given Value
|
|
|
|
*
|
|
|
|
* @param bool $value The Value to convert to a ManiaScript Boolean
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getBoolean($value) {
|
|
|
|
$bool = (bool) $value;
|
|
|
|
if ($bool) {
|
|
|
|
return "True";
|
|
|
|
}
|
|
|
|
return "False";
|
|
|
|
}
|
2013-12-31 02:55:19 +01:00
|
|
|
}
|