Migrate mscript functions into their own source file
This commit is contained in:
parent
8d8ce64ff7
commit
e28c349c75
|
@ -171,96 +171,6 @@ gui.warn = function (title, message) {
|
|||
};
|
||||
gui.error = function () {};
|
||||
|
||||
/******
|
||||
Mscript GUI
|
||||
*******/
|
||||
gui.mscript = {};
|
||||
gui.mscript.editor = {};
|
||||
gui.mscript.data = {};
|
||||
gui.mscript.raw = '';
|
||||
gui.mscript.init = function () {
|
||||
'use strict';
|
||||
$('#editor').val('CF 1\nPF 1');
|
||||
gui.mscript.editor = CodeMirror.fromTextArea(document.getElementById('editor'), {
|
||||
lineNumbers: true,
|
||||
mode: 'python',
|
||||
matchBrackets: true,
|
||||
theme: 'monokai'
|
||||
});
|
||||
gui.mscript.editor.setSize(null, $(window).height() - $('footer').eq(0).height() - 30);
|
||||
gui.mscript.editor.on('change', function (e) {
|
||||
const data = gui.mscript.editor.getValue();
|
||||
const output = gui.mscript.parse(data);
|
||||
});
|
||||
$(document).on('resize', function (e) {
|
||||
gui.mscript.editor.setSize(null, $(window).height() - $('footer').eq(0).height() - 30);
|
||||
});
|
||||
};
|
||||
gui.mscript.open = function () {
|
||||
'use strict';
|
||||
gui.mscript.editor.setSize(null, $(window).height() - $('footer').eq(0).height() - 30);
|
||||
gui.mscript.editor.refresh();
|
||||
};
|
||||
gui.mscript.update = function () {
|
||||
//ehhhhh
|
||||
'use strict';
|
||||
$('#mscript textarea').val(mcopy.state.sequence.arr.join('\n'));
|
||||
};
|
||||
gui.mscript.parse = function (str) {
|
||||
'use strict';
|
||||
/*var cmd = 'node mscript.js "' + str + '\n"';
|
||||
gui.mscript.raw = str;
|
||||
mcopy.exec(cmd, function (data) {
|
||||
gui.mscript.data = JSON.parse(data);
|
||||
});*/
|
||||
};
|
||||
|
||||
/*******
|
||||
* gui console
|
||||
*******/
|
||||
gui.console = {};
|
||||
gui.console.elem = {};
|
||||
gui.console.init = function () {
|
||||
'use script';
|
||||
gui.console.elem = $('#console textarea');
|
||||
gui.console.elem.on('keyup', function (e) {
|
||||
var code = e.keyCode || e.which;
|
||||
if (code === 13) {
|
||||
gui.console.exec();
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
};
|
||||
gui.console.lines = [];
|
||||
gui.console.parse = function () {
|
||||
'use strict';
|
||||
const lines = gui.console.elem.val().split('\n');
|
||||
const line = lines[lines.length - 2].replace('>', '').trim();
|
||||
gui.console.lines.push(line);
|
||||
};
|
||||
gui.console.exec = function () {
|
||||
'use strict';
|
||||
let command;
|
||||
gui.console.parse();
|
||||
command = gui.console.lines[gui.console.lines.length - 1].replace('>', '').trim();
|
||||
console.log(command);
|
||||
if (mscript.cmd.indexOf(command) !== -1) {
|
||||
if (command === 'CF') {
|
||||
cmd.cam_forward(light.color);
|
||||
} else if (cmd === 'CB') {
|
||||
cmd.cam_backward(light.color);
|
||||
}
|
||||
}
|
||||
gui.console.newLine();
|
||||
};
|
||||
gui.console.newLine = function () {
|
||||
'use strict';
|
||||
let current = gui.console.elem.val();
|
||||
current += '> ';
|
||||
gui.console.elem.val(current);
|
||||
};
|
||||
|
||||
/******
|
||||
Sequencer grid
|
||||
*******/
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
var mse = {};
|
||||
|
||||
/******
|
||||
Mscript GUI
|
||||
*******/
|
||||
mse.mscript = {};
|
||||
mse.mscript.editor = {};
|
||||
mse.mscript.data = {};
|
||||
mse.mscript.raw = '';
|
||||
mse.mscript.init = function () {
|
||||
'use strict';
|
||||
$('#editor').val('CF 1\nPF 1');
|
||||
mse.mscript.editor = CodeMirror.fromTextArea(document.getElementById('editor'), {
|
||||
lineNumbers: true,
|
||||
mode: 'python',
|
||||
matchBrackets: true,
|
||||
theme: 'monokai'
|
||||
});
|
||||
mse.mscript.editor.setSize(null, $(window).height() - $('footer').eq(0).height() - 30);
|
||||
mse.mscript.editor.on('change', function (e) {
|
||||
//
|
||||
});
|
||||
$(document).on('resize', function (e) {
|
||||
mse.mscript.editor.setSize(null, $(window).height() - $('footer').eq(0).height() - 30);
|
||||
});
|
||||
};
|
||||
mse.mscript.open = function () {
|
||||
'use strict';
|
||||
mse.mscript.editor.setSize(null, $(window).height() - $('footer').eq(0).height() - 30);
|
||||
mse.mscript.editor.refresh();
|
||||
};
|
||||
mse.mscript.fromSequence = function () {
|
||||
//ehhhhh
|
||||
'use strict';
|
||||
$('#mscript textarea').val(mcopy.state.sequence.arr.join('\n'));
|
||||
};
|
||||
mse.mscript.eval = function () {
|
||||
'use strict';
|
||||
const data = mse.mscript.editor.getValue();
|
||||
const output = mscript.interpret(data, function (output) {
|
||||
console.dir(output);
|
||||
});
|
||||
};
|
||||
|
||||
/*******
|
||||
* gui console
|
||||
*******/
|
||||
mse.console = {};
|
||||
mse.console.elem = {};
|
||||
mse.console.init = function () {
|
||||
'use script';
|
||||
mse.console.elem = $('#console textarea');
|
||||
mse.console.elem.on('keyup', function (e) {
|
||||
var code = e.keyCode || e.which;
|
||||
if (code === 13) {
|
||||
mse.console.exec();
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
};
|
||||
mse.console.lines = [];
|
||||
mse.console.parse = function () {
|
||||
'use strict';
|
||||
const lines = mse.console.elem.val().split('\n');
|
||||
const line = lines[lines.length - 2].replace('>', '').trim();
|
||||
mse.console.lines.push(line);
|
||||
};
|
||||
mse.console.exec = function () {
|
||||
'use strict';
|
||||
let command;
|
||||
mse.console.parse();
|
||||
command = mse.console.lines[mse.console.lines.length - 1].replace('>', '').trim();
|
||||
console.log(command);
|
||||
if (mscript.cmd.indexOf(command) !== -1) {
|
||||
if (command === 'CF') {
|
||||
cmd.cam_forward(light.color);
|
||||
} else if (cmd === 'CB') {
|
||||
cmd.cam_backward(light.color);
|
||||
}
|
||||
}
|
||||
mse.console.newLine();
|
||||
};
|
||||
mse.console.newLine = function () {
|
||||
'use strict';
|
||||
let current = mse.console.elem.val();
|
||||
current += '> ';
|
||||
mse.console.elem.val(current);
|
||||
};
|
||||
|
||||
module.exports = mse
|
|
@ -19,6 +19,7 @@ const seq = require('./lib/ui/seq.js');
|
|||
const cmd = require('./lib/ui/cmd.js');
|
||||
const log = require('./lib/ui/log.js');
|
||||
const devices = require('./lib/ui/devices.js');
|
||||
const mse = require('./lib/ui/mscript.js');
|
||||
const mscript = require('./lib/mscript');
|
||||
|
||||
|
||||
|
@ -65,8 +66,8 @@ function init () {
|
|||
'use strict';
|
||||
nav.init();
|
||||
gui.grid.init();
|
||||
gui.mscript.init();
|
||||
gui.console.init();
|
||||
mse.mscript.init();
|
||||
mse.console.init();
|
||||
log.init();
|
||||
devices.init();
|
||||
light.init();
|
||||
|
|
Loading…
Reference in New Issue