fml update
This commit is contained in:
parent
81af68838b
commit
6e37411fc4
@ -18,6 +18,7 @@ use FML\ManiaCode\PlayMap;
|
|||||||
use FML\ManiaCode\PlayReplay;
|
use FML\ManiaCode\PlayReplay;
|
||||||
use FML\ManiaCode\ShowMessage;
|
use FML\ManiaCode\ShowMessage;
|
||||||
use FML\ManiaCode\ViewReplay;
|
use FML\ManiaCode\ViewReplay;
|
||||||
|
use FML\ManiaCode\InstallMacroblock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing a ManiaCode
|
* Class representing a ManiaCode
|
||||||
@ -85,6 +86,20 @@ class ManiaCode {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install a Macroblock
|
||||||
|
*
|
||||||
|
* @param string $name Macroblock Name
|
||||||
|
* @param string $file Macroblock File
|
||||||
|
* @param string $url Macroblock Url
|
||||||
|
* @return \FML\ManiaCode
|
||||||
|
*/
|
||||||
|
public function addInstallMacroblock($name, $file, $url) {
|
||||||
|
$macroblockElement = new InstallMacroblock($name, $file, $url);
|
||||||
|
$this->addElement($macroblockElement);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install a Map
|
* Install a Map
|
||||||
*
|
*
|
||||||
|
98
application/core/Libs/FML/ManiaCode/InstallMacroblock.php
Normal file
98
application/core/Libs/FML/ManiaCode/InstallMacroblock.php
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FML\ManiaCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ManiaCode Element installing a Macroblock
|
||||||
|
*
|
||||||
|
* @author steeffeen
|
||||||
|
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||||
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
|
*/
|
||||||
|
class InstallMacroblock implements Element {
|
||||||
|
/*
|
||||||
|
* Protected Properties
|
||||||
|
*/
|
||||||
|
protected $tagName = 'install_macroblock';
|
||||||
|
protected $name = '';
|
||||||
|
protected $file = '';
|
||||||
|
protected $url = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new InstallMacroblock Element
|
||||||
|
*
|
||||||
|
* @param string $name (optional) Macroblock Name
|
||||||
|
* @param string $url (optional) Macroblock Url
|
||||||
|
* @return \FML\ManiaCode\InstallMacroblock
|
||||||
|
*/
|
||||||
|
public static function create($name = null, $url = null) {
|
||||||
|
$installMacroblock = new InstallMacroblock($name, $url);
|
||||||
|
return $installMacroblock;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new InstallMacroblock Element
|
||||||
|
*
|
||||||
|
* @param string $name (optional) Macroblock Name
|
||||||
|
* @param string $url (optional) Macroblock Url
|
||||||
|
*/
|
||||||
|
public function __construct($name = null, $file = null, $url = null) {
|
||||||
|
if ($name !== null) {
|
||||||
|
$this->setName($name);
|
||||||
|
}
|
||||||
|
if ($file !== null) {
|
||||||
|
$this->setFile($file);
|
||||||
|
}
|
||||||
|
if ($url !== null) {
|
||||||
|
$this->setUrl($url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Name of the Macroblock
|
||||||
|
*
|
||||||
|
* @param string $name Macroblock Name
|
||||||
|
* @return \FML\ManiaCode\InstallMacroblock
|
||||||
|
*/
|
||||||
|
public function setName($name) {
|
||||||
|
$this->name = (string) $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the File of the Macroblock
|
||||||
|
*
|
||||||
|
* @param string $file Macroblock File
|
||||||
|
* @return \FML\ManiaCode\InstallMacroblock
|
||||||
|
*/
|
||||||
|
public function setFile($file) {
|
||||||
|
$this->file = (string) $file;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Url of the Macroblock
|
||||||
|
*
|
||||||
|
* @param string $url Macroblock Url
|
||||||
|
* @return \FML\ManiaCode\InstallMacroblock
|
||||||
|
*/
|
||||||
|
public function setUrl($url) {
|
||||||
|
$this->url = (string) $url;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @see \FML\ManiaCode\Element::render()
|
||||||
|
*/
|
||||||
|
public function render(\DOMDocument $domDocument) {
|
||||||
|
$xmlElement = $domDocument->createElement($this->tagName);
|
||||||
|
$nameElement = $domDocument->createElement('name', $this->name);
|
||||||
|
$xmlElement->appendChild($nameElement);
|
||||||
|
$fileElement = $domDocument->createElement('file', $this->file);
|
||||||
|
$xmlElement->appendChild($fileElement);
|
||||||
|
$urlElement = $domDocument->createElement('url', $this->url);
|
||||||
|
$xmlElement->appendChild($urlElement);
|
||||||
|
return $xmlElement;
|
||||||
|
}
|
||||||
|
}
|
@ -51,7 +51,7 @@ class InstallPack implements Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Name of the Script
|
* Set the Name of the Pack
|
||||||
*
|
*
|
||||||
* @param string $name Pack Name
|
* @param string $name Pack Name
|
||||||
* @return \FML\ManiaCode\InstallPack
|
* @return \FML\ManiaCode\InstallPack
|
||||||
@ -62,7 +62,7 @@ class InstallPack implements Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the File of the Script
|
* Set the File of the Pack
|
||||||
*
|
*
|
||||||
* @param string $file Pack File
|
* @param string $file Pack File
|
||||||
* @return \FML\ManiaCode\InstallPack
|
* @return \FML\ManiaCode\InstallPack
|
||||||
@ -73,7 +73,7 @@ class InstallPack implements Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Url of the Script
|
* Set the Url of the Pack
|
||||||
*
|
*
|
||||||
* @param string $url Pack Url
|
* @param string $url Pack Url
|
||||||
* @return \FML\ManiaCode\InstallPack
|
* @return \FML\ManiaCode\InstallPack
|
||||||
|
@ -693,7 +693,43 @@ if (Event.Control.HasClass(\"" . self::CLASS_MENUBUTTON . "\")) {
|
|||||||
$this->setInclude('TextLib', 'TextLib');
|
$this->setInclude('TextLib', 'TextLib');
|
||||||
$pagesNumberPrefix = self::CLASS_PAGE . '-P';
|
$pagesNumberPrefix = self::CLASS_PAGE . '-P';
|
||||||
$pagesNumberPrefixLength = strlen($pagesNumberPrefix);
|
$pagesNumberPrefixLength = strlen($pagesNumberPrefix);
|
||||||
$pagesScript = "
|
|
||||||
|
$pagesInitScript = "
|
||||||
|
declare PageLabelControls = CMlControl[];
|
||||||
|
Page.GetClassChildren(\"" . self::CLASS_PAGELABEL . "\", Page.MainFrame, True);
|
||||||
|
foreach (PageLabelControl in Page.GetClassChildren_Result) {
|
||||||
|
declare Temp = PageLabelControl;
|
||||||
|
PageLabelControls.add(Temp);
|
||||||
|
}
|
||||||
|
declare FML_MinPageNumber for This = Integer[Text];
|
||||||
|
declare FML_MaxPageNumber for This = Integer[Text];
|
||||||
|
declare FML_PageNumber for This = Integer[Text];
|
||||||
|
foreach (PageLabelControl in PageLabelControls) {
|
||||||
|
foreach (ControlClass in PageLabelControl.ControlClasses) {
|
||||||
|
Page.GetClassChildren(ControlClass, Page.MainFrame, True);
|
||||||
|
foreach (PageControl in Page.GetClassChildren_Result) {
|
||||||
|
if (!PageControl.HasClass(\"" . self::CLASS_PAGE . "\")) continue;
|
||||||
|
foreach (PageControlClass in PageControl.ControlClasses) {
|
||||||
|
if (TextLib::SubText(PageControlClass, 0, {$pagesNumberPrefixLength}) != \"{$pagesNumberPrefix}\") continue;
|
||||||
|
declare PageNumber = TextLib::ToInteger(TextLib::SubText(PageControlClass, {$pagesNumberPrefixLength}, TextLib::Length(PageControlClass)));
|
||||||
|
if (!FML_MinPageNumber.existskey(ControlClass) || PageNumber < FML_MinPageNumber[ControlClass]) {
|
||||||
|
FML_MinPageNumber[ControlClass] = PageNumber;
|
||||||
|
}
|
||||||
|
if (!FML_MaxPageNumber.existskey(ControlClass) || PageNumber > FML_MaxPageNumber[ControlClass]) {
|
||||||
|
FML_MaxPageNumber[ControlClass] = PageNumber;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (FML_MinPageNumber.existskey(ControlClass)) {
|
||||||
|
FML_PageNumber[ControlClass] = FML_MinPageNumber[ControlClass];
|
||||||
|
declare PageLabel <=> (PageLabelControl as CMlLabel);
|
||||||
|
PageLabel.Value = FML_PageNumber[ControlClass]^\"/\"^FML_MaxPageNumber[ControlClass];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}";
|
||||||
|
|
||||||
|
$pagesClickScript = "
|
||||||
if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) {
|
if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) {
|
||||||
declare Text PagesId;
|
declare Text PagesId;
|
||||||
declare Integer PagingAction;
|
declare Integer PagingAction;
|
||||||
@ -710,28 +746,9 @@ if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare FML_PagesLastScriptStart for This = FML_ScriptStart;
|
|
||||||
declare FML_MinPageNumber for This = Integer[Text];
|
declare FML_MinPageNumber for This = Integer[Text];
|
||||||
declare FML_MaxPageNumber for This = Integer[Text];
|
declare FML_MaxPageNumber for This = Integer[Text];
|
||||||
declare FML_PageNumber for This = Integer[Text];
|
declare FML_PageNumber for This = Integer[Text];
|
||||||
if (FML_PagesLastScriptStart != FML_ScriptStart || !FML_PageNumber.existskey(PagesId) || !FML_MinPageNumber.existskey(PagesId) || !FML_MaxPageNumber.existskey(PagesId)) {
|
|
||||||
Page.GetClassChildren(PagesId, Page.MainFrame, True);
|
|
||||||
foreach (PageControl in Page.GetClassChildren_Result) {
|
|
||||||
if (!PageControl.HasClass(\"" . self::CLASS_PAGE . "\")) continue;
|
|
||||||
foreach (ControlClass in PageControl.ControlClasses) {
|
|
||||||
if (TextLib::SubText(ControlClass, 0, {$pagesNumberPrefixLength}) != \"{$pagesNumberPrefix}\") continue;
|
|
||||||
declare PageNumber = TextLib::ToInteger(TextLib::SubText(ControlClass, {$pagesNumberPrefixLength}, TextLib::Length(ControlClass)));
|
|
||||||
if (!FML_MinPageNumber.existskey(PagesId) || PageNumber < FML_MinPageNumber[PagesId]) {
|
|
||||||
FML_MinPageNumber[PagesId] = PageNumber;
|
|
||||||
}
|
|
||||||
if (!FML_MaxPageNumber.existskey(PagesId) || PageNumber > FML_MaxPageNumber[PagesId]) {
|
|
||||||
FML_MaxPageNumber[PagesId] = PageNumber;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FML_PageNumber[PagesId] = FML_MinPageNumber[PagesId];
|
|
||||||
}
|
|
||||||
FML_PageNumber[PagesId] += PagingAction;
|
FML_PageNumber[PagesId] += PagingAction;
|
||||||
if (FML_PageNumber[PagesId] < FML_MinPageNumber[PagesId]) {
|
if (FML_PageNumber[PagesId] < FML_MinPageNumber[PagesId]) {
|
||||||
FML_PageNumber[PagesId] = FML_MinPageNumber[PagesId];
|
FML_PageNumber[PagesId] = FML_MinPageNumber[PagesId];
|
||||||
@ -739,7 +756,6 @@ if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) {
|
|||||||
if (FML_PageNumber[PagesId] > FML_MaxPageNumber[PagesId]) {
|
if (FML_PageNumber[PagesId] > FML_MaxPageNumber[PagesId]) {
|
||||||
FML_PageNumber[PagesId] = FML_MaxPageNumber[PagesId];
|
FML_PageNumber[PagesId] = FML_MaxPageNumber[PagesId];
|
||||||
}
|
}
|
||||||
FML_PagesLastScriptStart = FML_ScriptStart;
|
|
||||||
Page.GetClassChildren(PagesId, Page.MainFrame, True);
|
Page.GetClassChildren(PagesId, Page.MainFrame, True);
|
||||||
foreach (PageControl in Page.GetClassChildren_Result) {
|
foreach (PageControl in Page.GetClassChildren_Result) {
|
||||||
if (!PageControl.HasClass(\"" . self::CLASS_PAGE . "\")) continue;
|
if (!PageControl.HasClass(\"" . self::CLASS_PAGE . "\")) continue;
|
||||||
@ -758,7 +774,9 @@ if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) {
|
|||||||
PageLabel.Value = FML_PageNumber[PagesId]^\"/\"^FML_MaxPageNumber[PagesId];
|
PageLabel.Value = FML_PageNumber[PagesId]^\"/\"^FML_MaxPageNumber[PagesId];
|
||||||
}
|
}
|
||||||
}";
|
}";
|
||||||
$pagesLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $pagesScript);
|
|
||||||
|
$pagesLabels = Builder::getLabelImplementationBlock(self::LABEL_ONINIT, $pagesInitScript);
|
||||||
|
$pagesLabels .= Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $pagesClickScript);
|
||||||
return $pagesLabels;
|
return $pagesLabels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,20 +9,65 @@
|
|||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
if (!defined('FML_PATH')) {
|
if (!defined('FML_PATH')) {
|
||||||
define('FML_PATH', __DIR__ . '/../');
|
define('FML_PATH', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
|
||||||
}
|
}
|
||||||
if (!defined('FML_VERSION')) {
|
if (!defined('FML_VERSION')) {
|
||||||
define('FML_VERSION', 1.0);
|
define('FML_VERSION', 1.0);
|
||||||
}
|
}
|
||||||
|
if (!defined('FML_SIMPLE_CLASSES')) {
|
||||||
|
define('FML_SIMPLE_CLASSES', false);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Autoload Function that loads FML Class Files on Demand
|
* Autoload Function that loads FML Class Files on Demand
|
||||||
*/
|
*/
|
||||||
spl_autoload_register(
|
if (!defined('FML_AUTOLOAD_DEFINED')) {
|
||||||
function ($className) {
|
define('FML_AUTOLOAD_DEFINED', true);
|
||||||
|
spl_autoload_register(function ($className) {
|
||||||
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className);
|
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className);
|
||||||
$filePath = FML_PATH . DIRECTORY_SEPARATOR . $classPath . '.php';
|
$filePath = FML_PATH . $classPath . '.php';
|
||||||
if (file_exists($filePath)) {
|
if (file_exists($filePath)) {
|
||||||
|
// Load with FML namespace
|
||||||
require_once $filePath;
|
require_once $filePath;
|
||||||
}
|
}
|
||||||
|
else if (FML_SIMPLE_CLASSES) {
|
||||||
|
// Load as simple class name
|
||||||
|
if (!function_exists('loadSimpleClass')) {
|
||||||
|
|
||||||
|
function loadSimpleClass($className, $directory, $excludes, $baseNamespace) {
|
||||||
|
if ($dirHandle = opendir($directory)) {
|
||||||
|
$classParts = explode('\\', $className);
|
||||||
|
$simpleClassName = end($classParts);
|
||||||
|
$classFileName = $simpleClassName . '.php';
|
||||||
|
while ($fileName = readdir($dirHandle)) {
|
||||||
|
if (in_array($fileName, $excludes)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$filePath = $directory . $fileName;
|
||||||
|
if (is_dir($filePath)) {
|
||||||
|
$subDirectory = $filePath . DIRECTORY_SEPARATOR;
|
||||||
|
$namespace = $baseNamespace . $fileName . '\\';
|
||||||
|
$success = loadSimpleClass($className, $subDirectory, $excludes, $namespace);
|
||||||
|
if ($success) return true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (is_file($filePath)) {
|
||||||
|
if ($fileName == $classFileName) {
|
||||||
|
require_once $filePath;
|
||||||
|
class_alias($baseNamespace . $simpleClassName, $className, false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($dirHandle);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$excludes = array('.', '..');
|
||||||
|
$baseNamespace = 'FML\\';
|
||||||
|
loadSimpleClass($className, FML_PATH . 'FML' . DIRECTORY_SEPARATOR, $excludes, $baseNamespace);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user