2017-02-08 14:36:28 +01:00
|
|
|
$(document).ready( function() {
|
|
|
|
performTranslation();
|
2016-11-21 22:16:57 +01:00
|
|
|
var oldDelList = [];
|
2017-02-08 14:36:28 +01:00
|
|
|
var effectName = "";
|
2019-01-06 19:49:56 +01:00
|
|
|
var imageData = "";
|
2017-10-12 11:55:03 +02:00
|
|
|
var effects_editor = null;
|
2017-02-08 14:36:28 +01:00
|
|
|
var effectPy = "";
|
2017-02-15 15:53:35 +01:00
|
|
|
var testrun;
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
if(showOptHelp)
|
|
|
|
createHintH("intro", $.i18n('effectsconfigurator_label_intro'), "intro_effc");
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
function updateDelEffectlist(){
|
2017-03-18 00:05:04 +01:00
|
|
|
var newDelList = serverInfo.effects;
|
2016-11-21 22:16:57 +01:00
|
|
|
if(newDelList.length != oldDelList.length)
|
|
|
|
{
|
2017-07-30 14:36:23 +02:00
|
|
|
$('#effectsdellist').html("");
|
|
|
|
var usrEffArr = [];
|
|
|
|
var sysEffArr = [];
|
2016-11-21 22:16:57 +01:00
|
|
|
for(var idx=0; idx<newDelList.length; idx++)
|
|
|
|
{
|
|
|
|
if(!/^\:/.test(newDelList[idx].file))
|
2017-07-30 14:36:23 +02:00
|
|
|
usrEffArr.push('ext_'+newDelList[idx].name+':'+newDelList[idx].name);
|
|
|
|
else
|
|
|
|
sysEffArr.push('int_'+newDelList[idx].name+':'+newDelList[idx].name);
|
2016-11-21 22:16:57 +01:00
|
|
|
}
|
2017-07-30 14:36:23 +02:00
|
|
|
$('#effectsdellist').append(createSel(usrEffArr, $.i18n('remote_optgroup_usreffets'), true)).append(createSel(sysEffArr, $.i18n('remote_optgroup_syseffets'), true)).trigger('change');
|
2016-11-21 22:16:57 +01:00
|
|
|
oldDelList = newDelList;
|
|
|
|
}
|
|
|
|
}
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2016-10-31 06:26:54 +01:00
|
|
|
function triggerTestEffect() {
|
2017-02-15 15:53:35 +01:00
|
|
|
testrun = true;
|
2016-10-31 06:26:54 +01:00
|
|
|
var args = effects_editor.getEditor('root.args');
|
2019-01-06 19:49:56 +01:00
|
|
|
requestTestEffect(effectName, ":/effects/" + effectPy.slice(1), JSON.stringify(args.getValue()), imageData);
|
2016-10-31 06:26:54 +01:00
|
|
|
};
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2019-01-06 19:49:56 +01:00
|
|
|
// Specify upload handler for image files
|
|
|
|
JSONEditor.defaults.options.upload = function(type, file, cbs) {
|
|
|
|
var fileReader = new FileReader();
|
|
|
|
|
|
|
|
//check file
|
|
|
|
if (!file.type.startsWith('image')) {
|
|
|
|
imageData = "";
|
|
|
|
cbs.failure('File upload error');
|
|
|
|
// TODO clear file dialog.
|
|
|
|
showInfoDialog('error', "", $.i18n('infoDialog_writeimage_error_text', file.name));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileReader.onload = function () {
|
|
|
|
imageData = this.result.split(',')[1];
|
|
|
|
cbs.success(file.name);
|
|
|
|
};
|
|
|
|
|
|
|
|
fileReader.readAsDataURL(file);
|
|
|
|
};
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2016-10-30 17:54:38 +01:00
|
|
|
$("#effectslist").off().on("change", function(event) {
|
2017-07-30 14:36:23 +02:00
|
|
|
if(effects_editor != null)
|
|
|
|
effects_editor.destroy();
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2016-10-30 17:54:38 +01:00
|
|
|
for(var idx=0; idx<effects.length; idx++){
|
2017-07-30 14:36:23 +02:00
|
|
|
if (effects[idx].schemaContent.script == this.value)
|
|
|
|
{
|
2016-10-30 17:54:38 +01:00
|
|
|
effects_editor = createJsonEditor('editor_container', {
|
|
|
|
args : effects[idx].schemaContent,
|
2017-07-30 14:36:23 +02:00
|
|
|
},false, true, false);
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
effectPy = ':';
|
|
|
|
effectPy += effects[idx].schemaContent.script;
|
2019-01-06 19:49:56 +01:00
|
|
|
imageData = "";
|
2017-07-30 14:36:23 +02:00
|
|
|
$("#name-input").trigger("change");
|
|
|
|
|
|
|
|
$("#eff_desc").html(createEffHint($.i18n(effects[idx].schemaContent.title),$.i18n(effects[idx].schemaContent.title+'_desc')));
|
|
|
|
break;
|
2016-10-30 17:54:38 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-31 06:26:54 +01:00
|
|
|
effects_editor.on('change',function() {
|
2017-02-08 14:36:28 +01:00
|
|
|
if ($("#btn_cont_test").hasClass("btn-success") && effects_editor.validate().length == 0 && effectName != "")
|
2016-10-31 06:26:54 +01:00
|
|
|
{
|
|
|
|
triggerTestEffect();
|
|
|
|
}
|
2017-02-08 14:36:28 +01:00
|
|
|
if( effects_editor.validate().length == 0 && effectName != "")
|
|
|
|
{
|
2017-07-30 14:36:23 +02:00
|
|
|
$('#btn_start_test, #btn_write').attr('disabled', false);
|
2017-02-08 14:36:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-30 14:36:23 +02:00
|
|
|
$('#btn_start_test, #btn_write').attr('disabled', true);
|
2017-02-08 14:36:28 +01:00
|
|
|
}
|
2016-10-31 06:26:54 +01:00
|
|
|
});
|
2016-10-30 17:54:38 +01:00
|
|
|
});
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2018-12-20 14:29:18 +01:00
|
|
|
// disable or enable control elements
|
2017-02-08 14:36:28 +01:00
|
|
|
$("#name-input").on('change keyup', function(event) {
|
2016-12-04 19:32:23 +01:00
|
|
|
effectName = $(this).val();
|
|
|
|
if ($(this).val() == '') {
|
|
|
|
effects_editor.disable();
|
|
|
|
$("#eff_footer").children().attr('disabled',true);
|
|
|
|
} else {
|
|
|
|
effects_editor.enable();
|
|
|
|
$("#eff_footer").children().attr('disabled',false);
|
|
|
|
}
|
|
|
|
});
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2018-12-20 14:29:18 +01:00
|
|
|
// Save Effect
|
2016-10-30 17:54:38 +01:00
|
|
|
$('#btn_write').off().on('click',function() {
|
2019-01-06 19:49:56 +01:00
|
|
|
requestWriteEffect(effectName,effectPy,JSON.stringify(effects_editor.getValue()),imageData);
|
2017-02-08 14:36:28 +01:00
|
|
|
$(hyperion).one("cmd-create-effect", function(event) {
|
|
|
|
if (event.response.success)
|
|
|
|
showInfoDialog('success', "", $.i18n('infoDialog_effconf_created_text', effectName));
|
|
|
|
});
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-02-15 15:53:35 +01:00
|
|
|
if (testrun)
|
|
|
|
setTimeout(requestPriorityClear,100);
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2016-10-30 17:54:38 +01:00
|
|
|
});
|
|
|
|
|
2018-12-20 14:29:18 +01:00
|
|
|
// Start test
|
2016-10-31 06:26:54 +01:00
|
|
|
$('#btn_start_test').off().on('click',function() {
|
2017-02-08 14:36:28 +01:00
|
|
|
triggerTestEffect();
|
2016-10-31 06:26:54 +01:00
|
|
|
});
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2018-12-20 14:29:18 +01:00
|
|
|
// Stop test
|
2016-10-31 06:26:54 +01:00
|
|
|
$('#btn_stop_test').off().on('click',function() {
|
|
|
|
requestPriorityClear();
|
2017-02-15 15:53:35 +01:00
|
|
|
testrun = false;
|
2016-10-31 06:26:54 +01:00
|
|
|
});
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2018-12-20 14:29:18 +01:00
|
|
|
// Continuous test
|
2016-10-31 06:26:54 +01:00
|
|
|
$('#btn_cont_test').off().on('click',function() {
|
|
|
|
toggleClass('#btn_cont_test', "btn-success", "btn-danger");
|
2016-10-30 22:59:45 +01:00
|
|
|
});
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2018-12-20 14:29:18 +01:00
|
|
|
// Delete Effect
|
2016-11-18 18:39:27 +01:00
|
|
|
$('#btn_delete').off().on('click',function() {
|
2018-12-20 14:29:18 +01:00
|
|
|
var name = $("#effectsdellist").val().split("_")[1];
|
2016-11-18 18:39:27 +01:00
|
|
|
requestDeleteEffect(name);
|
2017-02-08 14:36:28 +01:00
|
|
|
$(hyperion).one("cmd-delete-effect", function(event) {
|
|
|
|
if (event.response.success)
|
|
|
|
showInfoDialog('success', "", $.i18n('infoDialog_effconf_deleted_text', name));
|
|
|
|
});
|
2016-12-04 19:32:23 +01:00
|
|
|
});
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2018-12-20 14:29:18 +01:00
|
|
|
// disable or enable Delete Effect Button
|
2016-12-04 19:32:23 +01:00
|
|
|
$('#effectsdellist').off().on('change', function(){
|
2017-07-30 14:36:23 +02:00
|
|
|
$(this).val() == null ? $('#btn_edit, #btn_delete').prop('disabled',true) : "";
|
|
|
|
$(this).val().startsWith("int_") ? $('#btn_delete').prop('disabled',true) : $('#btn_delete').prop('disabled',false);
|
|
|
|
});
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2018-12-20 14:29:18 +01:00
|
|
|
// Load Effect
|
2017-07-30 14:36:23 +02:00
|
|
|
$('#btn_edit').off().on('click', function(){
|
2017-10-12 11:55:03 +02:00
|
|
|
var name = $("#effectsdellist").val().replace("ext_","");
|
|
|
|
|
2017-07-30 14:36:23 +02:00
|
|
|
if(name.startsWith("int_"))
|
|
|
|
{ name = name.split("_").pop();
|
|
|
|
$("#name-input").val("My Modded Effect");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name = name.split("_").pop();
|
|
|
|
$("#name-input").val(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
var efx = serverInfo.effects;
|
|
|
|
for(var i = 0; i<efx.length; i++)
|
|
|
|
{
|
|
|
|
if(efx[i].name == name)
|
|
|
|
{
|
|
|
|
var py = efx[i].script.split("/").pop()
|
|
|
|
$("#effectslist").val(py).trigger("change");
|
|
|
|
|
|
|
|
for(key in efx[i].args)
|
|
|
|
{
|
|
|
|
var ed = effects_editor.getEditor('root.args.'+[key]);
|
|
|
|
if(ed)
|
|
|
|
ed.setValue(efx[i].args[key]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-11-18 18:39:27 +01:00
|
|
|
});
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
//create basic effect list
|
|
|
|
var effects = serverSchema.properties.effectSchemas.internal
|
|
|
|
for(var idx=0; idx<effects.length; idx++)
|
2019-01-06 19:49:56 +01:00
|
|
|
{
|
|
|
|
$("#effectslist").append(createSelOpt(effects[idx].schemaContent.script, $.i18n(effects[idx].schemaContent.title)));
|
|
|
|
}
|
2017-02-08 14:36:28 +01:00
|
|
|
$("#effectslist").trigger("change");
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
updateDelEffectlist();
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
//interval update
|
2018-12-27 23:11:32 +01:00
|
|
|
$(hyperion).on("cmd-effects-update", function(event){
|
|
|
|
serverInfo.effects = event.response.data.effects
|
|
|
|
updateDelEffectlist();
|
|
|
|
});
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
removeOverlay();
|
2017-10-12 11:55:03 +02:00
|
|
|
});
|