2018-03-05 04:55:31 +00:00
|
|
|
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';
|
2018-03-15 03:19:23 +00:00
|
|
|
let str;
|
|
|
|
let tmp = [];
|
|
|
|
let cont;
|
2018-03-15 18:52:41 +00:00
|
|
|
//str = mcopy.state.sequence.arr.join('\n'); //quick hack
|
|
|
|
console.dir(mcopy.state.sequence);
|
2018-03-15 03:19:23 +00:00
|
|
|
for (let cmd of mcopy.state.sequence.arr) {
|
|
|
|
if (tmp.length > 0 && tmp[tmp.length - 1].cmd === cmd) {
|
|
|
|
tmp[tmp.length - 1].num++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
tmp.push({ cmd : cmd, num : 1 });
|
|
|
|
}
|
|
|
|
tmp = tmp.map(line => {
|
|
|
|
return `${line.cmd} ${line.num}`
|
|
|
|
})
|
|
|
|
str = tmp.join('\n');
|
|
|
|
nav.change('script');
|
|
|
|
cont = confirm(`Are you sure you want to over-write the current sequence?`);
|
|
|
|
if (cont) {
|
|
|
|
mse.mscript.editor.getDoc().setValue(str);
|
|
|
|
}
|
2018-03-05 04:55:31 +00:00
|
|
|
};
|
2018-03-15 18:52:41 +00:00
|
|
|
mse.mscript.toGUI = function () {
|
|
|
|
'use strict';
|
|
|
|
let c;
|
|
|
|
for (let i = 0; i < mse.mscript.data.arr.length; i++) {
|
|
|
|
c = mse.mscript.data.arr[i];
|
|
|
|
mcopy.state.sequence.arr[i] = c;
|
2018-03-16 16:59:23 +00:00
|
|
|
console.dir(mse.mscript.data);
|
|
|
|
if (c === 'CF' || c === 'CB') {
|
|
|
|
if (typeof mse.mscript.data.light[i] !== 'undefined' && mse.mscript.data.light[i] !== '') {
|
|
|
|
mcopy.state.sequence.light[i] = mse.mscript.data.light[i];
|
|
|
|
} else {
|
|
|
|
mcopy.state.sequence.light[i] = light.color.join(',');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mcopy.state.sequence.light[i] = '';
|
|
|
|
}
|
2018-03-15 18:52:41 +00:00
|
|
|
gui.grid.state(i);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mse.mscript.toSequence = function () {
|
|
|
|
'use strict';
|
|
|
|
const data = mse.mscript.editor.getValue();
|
|
|
|
let cont;
|
|
|
|
if (data !== mse.mscript.raw) {
|
|
|
|
cont = confirm(`Current script has not been compiled. Compile first?`);
|
|
|
|
if (cont) {
|
|
|
|
return mse.mscript.compile(() => {
|
|
|
|
mse.console.print(`Sending compiled script to GUI sequencer...`);
|
|
|
|
seq.clear();
|
|
|
|
mse.mscript.toGUI();
|
|
|
|
gui.grid.refresh();
|
|
|
|
seq.stats();
|
|
|
|
return nav.change('sequencer');
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mse.console.print(`Sending compiled script to GUI sequencer...`);
|
|
|
|
seq.clear();
|
|
|
|
mse.mscript.toGUI();
|
|
|
|
gui.grid.refresh();
|
|
|
|
seq.stats();
|
|
|
|
return nav.change('sequencer');
|
|
|
|
}
|
2018-03-15 03:19:23 +00:00
|
|
|
mse.mscript.compile = function (cb) {
|
2018-03-05 04:55:31 +00:00
|
|
|
'use strict';
|
|
|
|
const data = mse.mscript.editor.getValue();
|
2018-06-17 03:19:58 +00:00
|
|
|
let mscript = new Mscript();
|
2018-03-15 03:19:23 +00:00
|
|
|
let output;
|
|
|
|
mse.mscript.raw = data;
|
|
|
|
mscript.interpret(data, (output) => {
|
|
|
|
let len = output.arr.length;
|
|
|
|
mse.mscript.data = output;
|
|
|
|
//mse.console.print(JSON.stringify(output, null, '\t') + '\n')
|
|
|
|
mse.console.print(`Sequence contains ${len} step${(len === 1 ? '' : 's')}, CAM: ${output.cam}, PROJ: ${output.proj}`);
|
|
|
|
if (cb) cb();
|
2018-03-05 04:55:31 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-03-15 03:19:23 +00:00
|
|
|
mse.mscript.prepare = function () {
|
|
|
|
'use strict';
|
|
|
|
const arr = [];
|
|
|
|
let obj;
|
|
|
|
for (let i = 0; i < mse.mscript.data.arr.length; i++) {
|
|
|
|
obj = {
|
|
|
|
cmd : mse.mscript.data.arr[i]
|
|
|
|
};
|
2018-03-16 16:59:23 +00:00
|
|
|
if (typeof mse.mscript.data.light[i] !== 'undefined' && mse.mscript.data.light[i] !== '') {
|
2018-03-15 03:19:23 +00:00
|
|
|
obj.light = mse.mscript.data.light[i];
|
|
|
|
} else {
|
|
|
|
obj.light = light.color.join(',');
|
2018-03-16 16:59:23 +00:00
|
|
|
}
|
2018-03-15 03:19:23 +00:00
|
|
|
arr.push(obj);
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
};
|
|
|
|
|
|
|
|
mse.mscript.run = function () {
|
|
|
|
'use strict';
|
|
|
|
const data = mse.mscript.editor.getValue();
|
|
|
|
let arr;
|
|
|
|
let cont;
|
|
|
|
if (data !== mse.mscript.raw) {
|
|
|
|
cont = confirm(`Current script has not been compiled. Compile first?`);
|
|
|
|
if (cont) {
|
|
|
|
return mse.mscript.compile(() => {
|
|
|
|
mse.console.print(`Started running compiled sequence...`);
|
|
|
|
arr = mse.mscript.prepare();
|
|
|
|
return seq.exec(arr);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mse.console.print(`Started running compiled sequence...`);
|
|
|
|
arr = mse.mscript.prepare();
|
|
|
|
return seq.exec(arr);
|
|
|
|
};
|
|
|
|
|
2018-03-05 04:55:31 +00:00
|
|
|
/*******
|
|
|
|
* 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);
|
|
|
|
};
|
2018-03-15 03:19:23 +00:00
|
|
|
|
2018-03-05 04:55:31 +00:00
|
|
|
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);
|
2018-03-15 03:19:23 +00:00
|
|
|
mse.console.newLine();
|
2018-03-05 04:55:31 +00:00
|
|
|
if (mscript.cmd.indexOf(command) !== -1) {
|
|
|
|
if (command === 'CF') {
|
|
|
|
cmd.cam_forward(light.color);
|
|
|
|
} else if (cmd === 'CB') {
|
|
|
|
cmd.cam_backward(light.color);
|
|
|
|
}
|
|
|
|
}
|
2018-03-15 03:19:23 +00:00
|
|
|
|
|
|
|
if (command === 'compile') {
|
|
|
|
mse.mscript.compile();
|
|
|
|
} else if (command === 'run') {
|
|
|
|
mse.mscript.run();
|
|
|
|
}
|
2018-03-05 04:55:31 +00:00
|
|
|
};
|
2018-03-15 03:19:23 +00:00
|
|
|
|
2018-03-05 04:55:31 +00:00
|
|
|
mse.console.newLine = function () {
|
|
|
|
'use strict';
|
|
|
|
let current = mse.console.elem.val();
|
2018-03-15 03:19:23 +00:00
|
|
|
let height;
|
2018-03-05 04:55:31 +00:00
|
|
|
current += '> ';
|
|
|
|
mse.console.elem.val(current);
|
2018-03-15 03:19:23 +00:00
|
|
|
height = mse.console.elem[0].scrollHeight;
|
|
|
|
mse.console.elem.animate({
|
|
|
|
scrollTop : height
|
|
|
|
},'normal');
|
2018-03-05 04:55:31 +00:00
|
|
|
};
|
|
|
|
|
2018-03-05 18:27:00 +00:00
|
|
|
mse.console.print = function (str) {
|
|
|
|
'use strict'
|
|
|
|
let current = mse.console.elem.val();
|
2018-03-15 03:19:23 +00:00
|
|
|
let height;
|
2018-03-05 18:27:00 +00:00
|
|
|
current += str;
|
2018-03-15 03:19:23 +00:00
|
|
|
current += '\n> ';
|
2018-03-05 18:27:00 +00:00
|
|
|
mse.console.elem.val(current);
|
2018-03-15 03:19:23 +00:00
|
|
|
mse.console.elem.focus();
|
|
|
|
|
|
|
|
height = mse.console.elem[0].scrollHeight;
|
|
|
|
mse.console.elem.animate({
|
|
|
|
scrollTop : height
|
|
|
|
},'normal');
|
2018-03-05 18:27:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = mse;
|