Mscript #2
|
@ -23,6 +23,21 @@ const ALTS = {
|
||||||
'F ' : ['FADE']
|
'F ' : ['FADE']
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** helper functions */
|
||||||
|
|
||||||
|
/** startswith function from lodash, do not want the entire lib for this */
|
||||||
|
function startsWith(string, target, position) {
|
||||||
|
const { length } = string;
|
||||||
|
position = position == null ? 0 : position;
|
||||||
|
if (position < 0) {
|
||||||
|
position = 0;
|
||||||
|
} else if (position > length) {
|
||||||
|
position = length;
|
||||||
|
}
|
||||||
|
target = `${target}`;
|
||||||
|
return string.slice(position, position + target.length) == target;
|
||||||
|
}
|
||||||
|
|
||||||
/** class Mscript */
|
/** class Mscript */
|
||||||
class Mscript {
|
class Mscript {
|
||||||
constructor () {
|
constructor () {
|
||||||
|
@ -32,6 +47,8 @@ class Mscript {
|
||||||
* Clear the state of the script
|
* Clear the state of the script
|
||||||
*/
|
*/
|
||||||
clear () {
|
clear () {
|
||||||
|
this.lines = [];
|
||||||
|
|
||||||
this.cam = 0;
|
this.cam = 0;
|
||||||
this.proj = 0;
|
this.proj = 0;
|
||||||
this.color = '';
|
this.color = '';
|
||||||
|
@ -44,6 +61,8 @@ class Mscript {
|
||||||
this.target = 0; //move to target using CAM # or PROJ #
|
this.target = 0; //move to target using CAM # or PROJ #
|
||||||
this.dist = 0;
|
this.dist = 0;
|
||||||
|
|
||||||
|
this.variables = {};
|
||||||
|
|
||||||
this.output = {};
|
this.output = {};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -59,30 +78,36 @@ class Mscript {
|
||||||
}
|
}
|
||||||
|
|
||||||
//split string into lines, each containing a command
|
//split string into lines, each containing a command
|
||||||
let lines = text.split('\n');
|
this.lines = text.split('\n');
|
||||||
|
|
||||||
for (let line of lines) {
|
this.lines = this.lines.map(line => {
|
||||||
line = line.replace(/\t+/g, ""); //strip tabs
|
line = line.replace(/\t+/g, ''); //strip tabs
|
||||||
line = line.trim(); //remove excess whitespace before and after command
|
line = line.trim(); //remove excess whitespace before and after command
|
||||||
line = line.toUpperCase();
|
line = line.toUpperCase();
|
||||||
|
return line;
|
||||||
|
})
|
||||||
|
|
||||||
|
for (let line of this.lines) {
|
||||||
this.two = line.substring(0, 2);
|
this.two = line.substring(0, 2);
|
||||||
if (CMD.indexOf(this.two) !== -1) {
|
if (CMD.indexOf(this.two) !== -1) {
|
||||||
this.basic_cmd(line);
|
this.basic_cmd(line);
|
||||||
} else if (line.substring(0, 4) === 'LOOP') {
|
} else if (startsWith(line, '@') || line.indexOf('@') !== -1) {
|
||||||
|
this.variable(line);
|
||||||
|
} else if (startsWith(line, 'LOOP')) {
|
||||||
this.new_loop(line);
|
this.new_loop(line);
|
||||||
} else if (line.substring(0, 2) === 'L ') {
|
} else if (startsWith(line, 'L ')) {
|
||||||
this.light_state(line);
|
this.light_state(line);
|
||||||
} else if (line.substring(0, 2) === 'F ') {
|
} else if (startsWith(line, 'F ')) {
|
||||||
this.new_loop(line, true);
|
this.new_loop(line, true);
|
||||||
} else if (line.substring(0, 3) === 'END') {
|
} else if (startsWith(line, 'END')) {
|
||||||
this.end_loop(line);
|
this.end_loop(line);
|
||||||
} else if (line.substring(0, 3) === 'CAM') { //directly go to that frame (black?)
|
} else if (startsWith(line, 'CAM')) { //directly go to that frame (black?)
|
||||||
this.move_cam(line);
|
this.move_cam(line);
|
||||||
} else if (line.substring(0, 4) === 'PROJ') { //directly go to that frame
|
} else if (startsWith(line, 'PROJ')) { //directly go to that frame
|
||||||
this.move_proj(line);
|
this.move_proj(line);
|
||||||
} else if (line.substring(0, 3) === 'SET') { //set that state
|
} else if (startsWith(line, 'SET')) { //set that state
|
||||||
this.set_state(line);
|
this.set_state(line);
|
||||||
} else if (line.substring(0, 1) === '#' || line.substring(0, 2) === '//') {
|
} else if (startsWith(line, '#') || startsWith(line, '//')) {
|
||||||
//comments
|
//comments
|
||||||
//ignore while parsing
|
//ignore while parsing
|
||||||
}
|
}
|
||||||
|
@ -98,6 +123,46 @@ class Mscript {
|
||||||
//should only be invoked by running mscript.tests()
|
//should only be invoked by running mscript.tests()
|
||||||
callback(this.output);
|
callback(this.output);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
variable (line) {
|
||||||
|
let parts = line.split('=');
|
||||||
|
let key = parts[0];
|
||||||
|
let value = parts[1];
|
||||||
|
let update = false;
|
||||||
|
|
||||||
|
if (value && value.indexOf('#') !== -1) {
|
||||||
|
value = value.split('#')[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value && value.indexOf('//') !== -1) {
|
||||||
|
value = value.split('//')[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value && value.indexOf('+') !== -1) {
|
||||||
|
if (value)
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.indexOf('-') !== -1) {
|
||||||
|
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.indexOf(',') === -1) { //if not color string
|
||||||
|
try {
|
||||||
|
value = parseInt(value);
|
||||||
|
} catch (err) {
|
||||||
|
//supress parsing error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//console.dir(parts)
|
||||||
|
if (!this.variables[key] || update) {
|
||||||
|
this.variables[key] = value;
|
||||||
|
}
|
||||||
|
console.dir(this.variables)
|
||||||
|
}
|
||||||
|
variable_replace(line) {
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Apply a basic two character command
|
* Apply a basic two character command
|
||||||
|
@ -252,9 +317,9 @@ class Mscript {
|
||||||
* Set the state of either the cam or projector
|
* Set the state of either the cam or projector
|
||||||
*/
|
*/
|
||||||
set_state (line) {
|
set_state (line) {
|
||||||
if (line.substring(0, 7) === 'SET CAM') {
|
if (startsWith(line, 'SET CAM')) {
|
||||||
this.cam = parseInt(line.split('SET CAM')[1]);
|
this.cam = parseInt(line.split('SET CAM')[1]);
|
||||||
} else if (line.substring(0, 8) === 'SET PROJ') {
|
} else if (startsWith(line, 'SET PROJ')) {
|
||||||
this.proj = parseInt(line.split('SET PROJ')[1]);
|
this.proj = parseInt(line.split('SET PROJ')[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,7 +531,7 @@ END LOOP - (or END) closes loop
|
||||||
|
|
||||||
L #RGB - sets light to rgb value
|
L #RGB - sets light to rgb value
|
||||||
|
|
||||||
FADE
|
FADE 24 0,0,0 255,255,255
|
||||||
|
|
||||||
CF - Camera forwards
|
CF - Camera forwards
|
||||||
PF - Projector forwards
|
PF - Projector forwards
|
||||||
|
|
Loading…
Reference in New Issue