Start mscript docs. Will describe each method to facilitate the addition of the "fade" feature.

This commit is contained in:
mmcw-dev 2018-03-16 12:57:02 -04:00
parent df0806efa9
commit c1d5e52a10
2 changed files with 210 additions and 5 deletions

136
app/lib/mscript/Readme.md Normal file
View File

@ -0,0 +1,136 @@
<a name="module_lib/mscript"></a>
## lib/mscript
* [lib/mscript](#module_lib/mscript)
* [~mscript](#module_lib/mscript..mscript)
* [.arg(shrt, lng)](#module_lib/mscript..mscript.arg) ⇒ <code>boolean</code>
* [.arg_pos(shrt, lng)](#module_lib/mscript..mscript.arg_pos) ⇒ <code>boolean</code>
* [.state_clear()](#module_lib/mscript..mscript.state_clear)
* [.alts_unique()](#module_lib/mscript..mscript.alts_unique)
* [.interpret()](#module_lib/mscript..mscript.interpret)
* [.last_loop()](#module_lib/mscript..mscript.last_loop)
* [.parent_loop()](#module_lib/mscript..mscript.parent_loop)
* [.state_update()](#module_lib/mscript..mscript.state_update)
* [.str_to_arr()](#module_lib/mscript..mscript.str_to_arr)
* [.light_state()](#module_lib/mscript..mscript.light_state)
* [.light_to_arr()](#module_lib/mscript..mscript.light_to_arr)
* [.loop_count()](#module_lib/mscript..mscript.loop_count)
* [.fail()](#module_lib/mscript..mscript.fail)
* [.output()](#module_lib/mscript..mscript.output)
* [.init()](#module_lib/mscript..mscript.init)
* [.tests()](#module_lib/mscript..mscript.tests)
<a name="module_lib/mscript..mscript"></a>
### lib/mscript~mscript
object mscript
**Kind**: inner constant of [<code>lib/mscript</code>](#module_lib/mscript)
* [~mscript](#module_lib/mscript..mscript)
* [.arg(shrt, lng)](#module_lib/mscript..mscript.arg) ⇒ <code>boolean</code>
* [.arg_pos(shrt, lng)](#module_lib/mscript..mscript.arg_pos) ⇒ <code>boolean</code>
* [.state_clear()](#module_lib/mscript..mscript.state_clear)
* [.alts_unique()](#module_lib/mscript..mscript.alts_unique)
* [.interpret()](#module_lib/mscript..mscript.interpret)
* [.last_loop()](#module_lib/mscript..mscript.last_loop)
* [.parent_loop()](#module_lib/mscript..mscript.parent_loop)
* [.state_update()](#module_lib/mscript..mscript.state_update)
* [.str_to_arr()](#module_lib/mscript..mscript.str_to_arr)
* [.light_state()](#module_lib/mscript..mscript.light_state)
* [.light_to_arr()](#module_lib/mscript..mscript.light_to_arr)
* [.loop_count()](#module_lib/mscript..mscript.loop_count)
* [.fail()](#module_lib/mscript..mscript.fail)
* [.output()](#module_lib/mscript..mscript.output)
* [.init()](#module_lib/mscript..mscript.init)
* [.tests()](#module_lib/mscript..mscript.tests)
<a name="module_lib/mscript..mscript.arg"></a>
#### mscript.arg(shrt, lng) ⇒ <code>boolean</code>
Check for the presence of specific arguments in process
argv
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
**Returns**: <code>boolean</code> - Is flag present
| Param | Type | Description |
| --- | --- | --- |
| shrt | <code>string</code> | Short version of argument or flag |
| lng | <code>string</code> | Long version of argument or flag |
<a name="module_lib/mscript..mscript.arg_pos"></a>
#### mscript.arg_pos(shrt, lng) ⇒ <code>boolean</code>
Check for the position of specific arguments in process
argv
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
**Returns**: <code>boolean</code> - Position of arg or flag, for locating input
| Param | Type | Description |
| --- | --- | --- |
| shrt | <code>string</code> | Short version of argument or flag |
| lng | <code>string</code> | Long version of argument or flag |
<a name="module_lib/mscript..mscript.state_clear"></a>
#### mscript.state_clear()
Clear the state object
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
<a name="module_lib/mscript..mscript.alts_unique"></a>
#### mscript.alts_unique()
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
<a name="module_lib/mscript..mscript.interpret"></a>
#### mscript.interpret()
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
<a name="module_lib/mscript..mscript.last_loop"></a>
#### mscript.last_loop()
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
<a name="module_lib/mscript..mscript.parent_loop"></a>
#### mscript.parent_loop()
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
<a name="module_lib/mscript..mscript.state_update"></a>
#### mscript.state_update()
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
<a name="module_lib/mscript..mscript.str_to_arr"></a>
#### mscript.str_to_arr()
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
<a name="module_lib/mscript..mscript.light_state"></a>
#### mscript.light_state()
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
<a name="module_lib/mscript..mscript.light_to_arr"></a>
#### mscript.light_to_arr()
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
<a name="module_lib/mscript..mscript.loop_count"></a>
#### mscript.loop_count()
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
<a name="module_lib/mscript..mscript.fail"></a>
#### mscript.fail()
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
<a name="module_lib/mscript..mscript.output"></a>
#### mscript.output()
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
<a name="module_lib/mscript..mscript.init"></a>
#### mscript.init()
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)
<a name="module_lib/mscript..mscript.tests"></a>
#### mscript.tests()
Legacy tests. To be deprecated in future releases.
**Kind**: static method of [<code>mscript</code>](#module_lib/mscript..mscript)

View File

@ -1,10 +1,22 @@
'use strict';
/** @module lib/mscript */
let fs;
let input;
/** object mscript */
const mscript = {};
/**
* Check for the presence of specific arguments in process
* argv
*
* @param {string} shrt Short version of argument or flag
* @param {string} lng Long version of argument or flag
*
* @return {boolean} Is flag present
*/
mscript.arg = function arg (shrt, lng) {
if (process.argv.indexOf(shrt) !== -1 ||
process.argv.indexOf(lng) !== -1) {
@ -13,6 +25,15 @@ mscript.arg = function arg (shrt, lng) {
return false;
};
/**
* Check for the position of specific arguments in process
* argv
*
* @param {string} shrt Short version of argument or flag
* @param {string} lng Long version of argument or flag
*
* @return {boolean} Position of arg or flag, for locating input
*/
mscript.arg_pos = function arg_pos (shrt, lng) {
var pos = -1;
pos = process.argv.indexOf(shrt);
@ -21,6 +42,7 @@ mscript.arg_pos = function arg_pos (shrt, lng) {
}
return pos;
};
mscript.black = '0,0,0';
mscript.cmd = [
'CF',
@ -33,13 +55,19 @@ mscript.cmd = [
mscript.alts = {
'CF' : ['CAMERA FORWARD', 'CAM FORWARD'],
'PF' : ['PROJECTOR FORWARD', 'PROJ FORWARD'],
'BF': ['BLACK FORWARD'],
'BF': ['BLACK FORWARD', 'BLACK', 'BLANK FORWARD', 'BLANK'],
'CB' : ['CAMERA BACKWARD', 'CAM BACKWARD', 'CAMERA BACK', 'CAM BACK'],
'PB' : ['PROJECTOR FORWARD', 'PROJ FORWARD', 'PROJECTOR BACK', 'PROJ BACK'],
'BB' : ['BLACK BACKWARD', 'BLACK BACK'],
'L ' : ['LIGHT', 'COLOR', 'LAMP']
'BB' : ['BLACK BACKWARD', 'BLACK BACK', 'BLANK BACK'],
'L ' : ['LIGHT', 'COLOR', 'LAMP'],
'F ' : ['FADE']
};
mscript.state = {};
/**
* Clear the state object
*/
mscript.state_clear = function state_clear () {
mscript.state = {
cam : 0,
@ -49,6 +77,9 @@ mscript.state_clear = function state_clear () {
rec : -1
};
};
/**
*
*/
mscript.alts_unique = function alts_unique () {
var ids = Object.keys(mscript.alts),
all = [];
@ -60,6 +91,9 @@ mscript.alts_unique = function alts_unique () {
}
}
};
/**
*
*/
mscript.interpret = function interpret (text, callback) {
mscript.state_clear();
if (typeof text === 'undefined') {
@ -214,12 +248,21 @@ mscript.interpret = function interpret (text, callback) {
return mscript.output(output);
}
};
/**
*
*/
mscript.last_loop = function last_loop () {
return mscript.state.loops[mscript.state.loops.length - 1];
};
/**
*
*/
mscript.parent_loop = function parent_loop () {
return mscript.state.loops[mscript.state.loops.length - 2];
};
/**
*
*/
mscript.state_update = function state_update (cmd, val) {
if (cmd === 'END') {
for (var i = 0; i < val; i++) {
@ -271,6 +314,9 @@ mscript.state_update = function state_update (cmd, val) {
}
};
/**
*
*/
mscript.str_to_arr = function str_to_arr (str, cmd) {
var cnt = str.split(cmd),
c = parseInt(cnt[1]),
@ -286,11 +332,17 @@ mscript.str_to_arr = function str_to_arr (str, cmd) {
}
return arr;
};
/**
*
*/
mscript.light_state = function light_state (str) {
//add parsers for other color spaces
var color = str.replace('L ', '').trim();
mscript.state.color = color;
};
/**
*
*/
mscript.light_to_arr = function light_to_arr (str, cmd) {
var cnt = str.split(cmd),
c = parseInt(cnt[1]),
@ -313,13 +365,25 @@ mscript.light_to_arr = function light_to_arr (str, cmd) {
}
return arr;
};
/**
*
*/
mscript.loop_count = function loop_count (str) {
return parseInt(str.split('LOOP ')[1]);
return parseInt(str.split(' ')[1]);
};
mscript.fade_count = function fade_count (str) {
return parseInt(str.split(' ')[1]);
}
/**
*
*/
mscript.fail = function fail (reason) {
console.error(JSON.stringify({success: false, error: true, msg : reason}));
if (process) process.exit();
};
/**
*
*/
mscript.output = function output (data) {
var json = true; //default
if (mscript.arg('-j', '--json')) {
@ -339,6 +403,9 @@ mscript.output = function output (data) {
}
}
};
/**
*
*/
mscript.init = function init () {
if (mscript.arg('-t', '--tests')) {
return mscript.tests();
@ -367,7 +434,9 @@ mscript.init = function init () {
console.timeEnd('mscript');
}
};
/**
* Legacy tests. To be deprecated in future releases.
*/
mscript.tests = function tests () {
console.log('Running mscript tests');
console.time('Tests took');