From e28c349c758c94dc202feb6cdda574c4788d8d0a Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Sun, 4 Mar 2018 23:55:31 -0500 Subject: [PATCH] Migrate mscript functions into their own source file --- app/lib/ui/index.js | 90 ------------------------------------------ app/lib/ui/mscript.js | 91 +++++++++++++++++++++++++++++++++++++++++++ app/src/index.js | 5 ++- 3 files changed, 94 insertions(+), 92 deletions(-) create mode 100644 app/lib/ui/mscript.js diff --git a/app/lib/ui/index.js b/app/lib/ui/index.js index 5bb3ab5..7812464 100644 --- a/app/lib/ui/index.js +++ b/app/lib/ui/index.js @@ -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 *******/ diff --git a/app/lib/ui/mscript.js b/app/lib/ui/mscript.js new file mode 100644 index 0000000..f87254f --- /dev/null +++ b/app/lib/ui/mscript.js @@ -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 \ No newline at end of file diff --git a/app/src/index.js b/app/src/index.js index 60c8f03..e92ab1b 100644 --- a/app/src/index.js +++ b/app/src/index.js @@ -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();