* compile sequence
* run sequence
This commit is contained in:
mmcwilliams 2018-03-14 23:19:23 -04:00
parent 394ef0d1e3
commit dddd3214e1
1 changed files with 91 additions and 7 deletions

View File

@ -32,17 +32,81 @@ mse.mscript.open = function () {
mse.mscript.fromSequence = function () {
//ehhhhh
'use strict';
$('#mscript textarea').val(mcopy.state.sequence.arr.join('\n'));
let str;
let tmp = [];
let cont;
str = mcopy.state.sequence.arr.join('\n'); //quick hack
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);
}
};
mse.mscript.eval = function () {
mse.mscript.compile = function (cb) {
'use strict';
const data = mse.mscript.editor.getValue();
const output = mscript.interpret(data, function (output) {
console.dir(output);
mse.console.print(JSON.stringify(output, null, '\t'))
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();
});
};
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]
};
/*if (mse.mscript.data.light[i] !== '') {
obj.light = mse.mscript.data.light[i];
} else {
obj.light = light.color.join(',');
}*/
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);
};
/*******
* gui console
*******/
@ -67,12 +131,14 @@ mse.console.parse = function () {
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);
mse.console.newLine();
if (mscript.cmd.indexOf(command) !== -1) {
if (command === 'CF') {
cmd.cam_forward(light.color);
@ -80,21 +146,39 @@ mse.console.exec = function () {
cmd.cam_backward(light.color);
}
}
mse.console.newLine();
if (command === 'compile') {
mse.mscript.compile();
} else if (command === 'run') {
mse.mscript.run();
}
};
mse.console.newLine = function () {
'use strict';
let current = mse.console.elem.val();
let height;
current += '> ';
mse.console.elem.val(current);
height = mse.console.elem[0].scrollHeight;
mse.console.elem.animate({
scrollTop : height
},'normal');
};
mse.console.print = function (str) {
'use strict'
let current = mse.console.elem.val();
current += '> ';
let height;
current += str;
current += '\n> ';
mse.console.elem.val(current);
mse.console.elem.focus();
height = mse.console.elem[0].scrollHeight;
mse.console.elem.animate({
scrollTop : height
},'normal');
};
module.exports = mse;