CAM/PROJ goto feature works within loops

This commit is contained in:
Matt 2016-04-18 12:23:14 -04:00
parent fc05992558
commit 479240a6c3
1 changed files with 130 additions and 46 deletions

View File

@ -21,7 +21,7 @@ mscript.arg_pos = function arg_pos (shrt, lng) {
} }
return pos; return pos;
}; };
mscript.black = '0,0,0';
mscript.cmd = [ mscript.cmd = [
'CF', 'CF',
'PF', 'PF',
@ -39,6 +39,17 @@ mscript.alts = {
'BB' : ['BLACK BACKWARD', 'BLACK BACK'], 'BB' : ['BLACK BACKWARD', 'BLACK BACK'],
'L ' : ['LIGHT', 'COLOR', 'LAMP'] 'L ' : ['LIGHT', 'COLOR', 'LAMP']
}; };
mscript.state = {};
mscript.state_clear = function state_clear () {
'use strict';
mscript.state = {
cam : 0,
proj : 0,
color : '',
loops : [],
rec : -1
};
};
mscript.alts_unique = function alts_unique () { mscript.alts_unique = function alts_unique () {
'use strict'; 'use strict';
var ids = Object.keys(mscript.alts), var ids = Object.keys(mscript.alts),
@ -51,17 +62,6 @@ mscript.alts_unique = function alts_unique () {
} }
} }
}; };
mscript.state = {};
mscript.state_clear = function state_clear () {
'use strict';
mscript.state = {
cam : 0,
proj : 0,
color : '',
loops : [],
rec : -1
};
};
mscript.interpret = function interpret (text, callback) { mscript.interpret = function interpret (text, callback) {
'use strict'; 'use strict';
mscript.state_clear(); mscript.state_clear();
@ -80,6 +80,7 @@ mscript.interpret = function interpret (text, callback) {
lines[i] = lines[i].trim(); //remove excess whitespace before and after command lines[i] = lines[i].trim(); //remove excess whitespace before and after command
two = lines[i].substring(0, 2); two = lines[i].substring(0, 2);
if (mscript.cmd.indexOf(two) !== -1) { if (mscript.cmd.indexOf(two) !== -1) {
if (mscript.state.loops.length > 0) { if (mscript.state.loops.length > 0) {
//hold generated arr in state loop array //hold generated arr in state loop array
mscript.state.loops[mscript.state.rec].arr mscript.state.loops[mscript.state.rec].arr
@ -94,6 +95,7 @@ mscript.interpret = function interpret (text, callback) {
arr.push.apply(arr, mscript.str_to_arr(lines[i], two)); arr.push.apply(arr, mscript.str_to_arr(lines[i], two));
light.push.apply(light, mscript.light_to_arr(lines[i], two)) light.push.apply(light, mscript.light_to_arr(lines[i], two))
} }
} else if (lines[i].substring(0, 4) === 'LOOP') { } else if (lines[i].substring(0, 4) === 'LOOP') {
mscript.state.rec++; mscript.state.rec++;
mscript.state.loops[mscript.state.rec] = { mscript.state.loops[mscript.state.rec] = {
@ -123,44 +125,74 @@ mscript.interpret = function interpret (text, callback) {
delete mscript.state.loops[mscript.state.rec]; delete mscript.state.loops[mscript.state.rec];
mscript.state.rec--; mscript.state.rec--;
} else if (lines[i].substring(0, 3) === 'CAM') { //directly go to that frame (black?) } else if (lines[i].substring(0, 3) === 'CAM') { //directly go to that frame (black?)
if (mscript.state.loops.length > 0) {
mscript.fail('Cannot go to absolute camera frame within a loop... yet.');
}
target = parseInt(lines[i].split('CAM ')[1]); target = parseInt(lines[i].split('CAM ')[1]);
if (target > mscript.state.cam) { if (mscript.state.loops.length > 0) {
dist = target - mscript.state.cam; if (target > mscript.state.cam) {
for (var x = 0; x < dist; x++) { dist = target - mscript.state.cam;
arr.push('BF'); for (var x = 0; x < dist; x++) {
light.push('0,0,0'); mscript.state.loops[mscript.state.rec].arr.push('BF');
mscript.state_update('BF'); mscript.state.loops[mscript.state.rec].light.push(mscript.black);
} mscript.state_update('BF');
}
} else {
dist = mscript.state.cam - target;
for (var x = 0; x < dist; x++) {
mscript.state.loops[mscript.state.rec].arr.push('BB');
mscript.state.loops[mscript.state.rec].light.push(mscript.black);
mscript.state_update('BB');
}
}
} else { } else {
dist = mscript.state.cam - target; if (target > mscript.state.cam) {
for (var x = 0; x < dist; x++) { dist = target - mscript.state.cam;
arr.push('BB'); for (var x = 0; x < dist; x++) {
light.push('0,0,0'); arr.push('BF');
mscript.state_update('BB'); light.push(mscript.black);
mscript.state_update('BF');
}
} else {
dist = mscript.state.cam - target;
for (var x = 0; x < dist; x++) {
arr.push('BB');
light.push(mscript.black);
mscript.state_update('BB');
}
} }
} }
} else if (lines[i].substring(0, 4) === 'PROJ') { //directly go to that frame } else if (lines[i].substring(0, 4) === 'PROJ') { //directly go to that frame
if (mscript.state.loops.length > 0) {
mscript.fail('Cannot go to absolute projector frame within a loop... yet.');
}
target = parseInt(lines[i].split('PROJ ')[1]); target = parseInt(lines[i].split('PROJ ')[1]);
if (target > mscript.state.proj) { if (mscript.state.loops.length > 0) {
dist = target - mscript.state.proj; if (target > mscript.state.proj) {
for (var x = 0; x < dist; x++) { dist = target - mscript.state.proj;
arr.push('PF'); for (var x = 0; x < dist; x++) {
light.push(''); mscript.state.loops[mscript.state.rec].arr.push('PF');
mscript.state_update('PF'); mscript.state.loops[mscript.state.rec].light.push('');
} mscript.state_update('PF');
}
} else {
dist = mscript.state.proj - target;
for (var x = 0; x < dist; x++) {
mscript.state.loops[mscript.state.rec].arr.push('PB');
mscript.state.loops[mscript.state.rec].light.push('');
mscript.state_update('PB');
}
}
} else { } else {
dist = mscript.state.proj - target; if (target > mscript.state.proj) {
for (var x = 0; x < dist; x++) { dist = target - mscript.state.proj;
arr.push('PB'); for (var x = 0; x < dist; x++) {
light.push(''); arr.push('PF');
mscript.state_update('PB'); light.push('');
} mscript.state_update('PF');
}
} else {
dist = mscript.state.proj - target;
for (var x = 0; x < dist; x++) {
arr.push('PB');
light.push('');
mscript.state_update('PB');
}
}
} }
} else if (lines[i].substring(0, 3) === 'SET') { //set that state } else if (lines[i].substring(0, 3) === 'SET') { //set that state
if (lines[i].substring(0, 7) === 'SET CAM') { if (lines[i].substring(0, 7) === 'SET CAM') {
@ -278,10 +310,11 @@ mscript.light_to_arr = function light_to_arr (str, cmd) {
} }
for (var i = 0; i < c; i++) { for (var i = 0; i < c; i++) {
if (cmd === 'CF' if (cmd === 'CF'
|| cmd === 'CB' || cmd === 'CB') {
|| cmd === 'BF'
|| cmd === 'BB') {
arr.push(mscript.state.color); arr.push(mscript.state.color);
} else if (cmd === 'BF'
|| cmd === 'BB') {
arr.push(mscript.black);
} else { } else {
arr.push(''); arr.push('');
} }
@ -439,6 +472,53 @@ mscript.tests = function tests () {
fail(script, obj); fail(script, obj);
} }
}); });
script = 'L 255,255,255\nCF\nPF\nBF';
console.log('Basic black test...');
mscript.interpret(script, function (obj) {
if (obj.success === true
&& obj.cam === 2
&& obj.proj === 1
&& obj.arr.length === 3
&& obj.light.length === 3
&& obj.light[0] === '255,255,255'
&& obj.light[1] === ''
&& obj.light[2] === mscript.black) {
console.log('...Passed!');
} else {
fail(script, obj);
}
});
script = 'LOOP 2\nL 1,1,1\nCF\nL 2,2,2\nCF\nEND';
console.log('Basic light loop test...');
mscript.interpret(script, function (obj) {
if (obj.success === true
&& obj.cam === 4
&& obj.proj === 0
&& obj.arr.length === 4
&& obj.light.length === 4
&& obj.light[0] === '1,1,1'
&& obj.light[3] === '2,2,2') {
console.log('...Passed!');
} else {
fail(script, obj);
}
});
//LOOP W/ CAM and PROJ
script = 'LOOP 2\nCAM 4\nPROJ 4\nEND';
console.log('Basic cam/proj loop test...');
mscript.interpret(script, function (obj) {
if (obj.success === true
&& obj.cam === 8
&& obj.proj === 8
&& obj.arr.length === 16
&& obj.light.length === 16
&& obj.light[0] === mscript.black) {
console.log('...Passed!');
} else {
fail(script, obj);
}
});
console.log('All tests completed'); console.log('All tests completed');
console.timeEnd('Tests took'); console.timeEnd('Tests took');
@ -471,6 +551,10 @@ SET PROJ # - sets projector count to #
LOOP # - begin loop, can nest recursively, # times LOOP # - begin loop, can nest recursively, # times
END LOOP - (or END) closes loop END LOOP - (or END) closes loop
L #RGB - sets light to rgb value
FADE
CF - Camera forwards CF - Camera forwards
PF - Projector forwards PF - Projector forwards
BF - Black forwards BF - Black forwards