load def scriptsettings on mapbegin, settings changed cb
This commit is contained in:
parent
e4095b82e6
commit
5ed1027eec
@ -12,6 +12,7 @@ use FML\Script\Script;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Maps\MapManager;
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
/**
|
||||
@ -28,6 +29,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
const CB_SCRIPTSETTING_CHANGED = 'ScriptSettings.SettingChanged';
|
||||
const CB_SCRIPTSETTINGS_CHANGED = 'ScriptSettings.SettingsChanged';
|
||||
const TABLE_SCRIPT_SETTINGS = 'mc_scriptsettings';
|
||||
const SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN = 'Load Stored Script-Settings on Map-Begin';
|
||||
|
||||
/**
|
||||
* Private Properties
|
||||
@ -45,6 +47,8 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'onBeginMap');
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, true);
|
||||
$this->initTables();
|
||||
}
|
||||
|
||||
@ -83,6 +87,18 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
*/
|
||||
public function onInit(array $callback) {
|
||||
$this->loadSettingsFromDatabase();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle OnBegin Map Callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function onBeginMap(array $callback) {
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN)) {
|
||||
$this->loadSettingsFromDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,9 +107,9 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
* @return bool
|
||||
*/
|
||||
public function loadSettingsFromDatabase() {
|
||||
try{
|
||||
try {
|
||||
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
||||
} catch (\Exception $e){
|
||||
} catch(\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ class SettingManager {
|
||||
const TYPE_REAL = 'real';
|
||||
const TYPE_BOOL = 'bool';
|
||||
const TYPE_ARRAY = 'array';
|
||||
const CB_SETTINGS_CHANGED = 'SettingManager.SettingsChanged';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
@ -88,7 +89,7 @@ class SettingManager {
|
||||
return $object;
|
||||
}
|
||||
trigger_error('Invalid class param. ' . $object);
|
||||
return (string) $object;
|
||||
return (string)$object;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,16 +127,16 @@ class SettingManager {
|
||||
*/
|
||||
private function castSetting($type, $value) {
|
||||
if ($type === self::TYPE_INT) {
|
||||
return (int) $value;
|
||||
return (int)$value;
|
||||
}
|
||||
if ($type === self::TYPE_REAL) {
|
||||
return (float) $value;
|
||||
return (float)$value;
|
||||
}
|
||||
if ($type === self::TYPE_BOOL) {
|
||||
return (bool) $value;
|
||||
return (bool)$value;
|
||||
}
|
||||
if ($type === self::TYPE_STRING) {
|
||||
return (string) $value;
|
||||
return (string)$value;
|
||||
}
|
||||
if ($type === self::TYPE_ARRAY) {
|
||||
return explode($this->arrayDelimiter, $value);
|
||||
@ -326,6 +327,9 @@ class SettingManager {
|
||||
public function setSetting($object, $settingName, $value) {
|
||||
$className = $this->getClassName($object);
|
||||
$this->updateSetting($className, $settingName, $value);
|
||||
|
||||
//Trigger settings changed Callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_SETTINGS_CHANGED, array(self::CB_SETTINGS_CHANGED, $className, $settingName, $value));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -403,9 +407,8 @@ class SettingManager {
|
||||
return null;
|
||||
}
|
||||
$settings = array();
|
||||
while ($setting = $result->fetch_object()) {
|
||||
while($setting = $result->fetch_object()) {
|
||||
$settings[$setting->index] = $setting;
|
||||
// array_push($settings, $setting);
|
||||
}
|
||||
$result->free();
|
||||
return $settings;
|
||||
@ -426,9 +429,8 @@ class SettingManager {
|
||||
return null;
|
||||
}
|
||||
$settings = array();
|
||||
while ($setting = $result->fetch_object()) {
|
||||
while($setting = $result->fetch_object()) {
|
||||
$settings[$setting->index] = $setting;
|
||||
// array_push($settings, $setting);
|
||||
}
|
||||
$result->free();
|
||||
return $settings;
|
||||
|
Loading…
Reference in New Issue
Block a user