Remove callback from mscript (never used) and make all non-public methods private.

This commit is contained in:
Matt McWilliams 2024-05-24 00:26:12 -04:00
parent b4a974a33e
commit 6c8d2d712d
12 changed files with 134 additions and 211 deletions

View File

@ -1,5 +1,5 @@
{
"version": "1.8.114",
"version": "1.8.116",
"ext_port": 1111,
"profiles": {
"mcopy": {

View File

@ -8,14 +8,6 @@
</dd>
</dl>
## Functions
<dl>
<dt><a href="#startsWith">startsWith(str, target, position)</a><code>boolean</code></dt>
<dd><p>startswith function from lodash, do not want the entire lib for this</p>
</dd>
</dl>
<a name="Create new Mscript interpreter"></a>
## Create new Mscript interpreter
@ -76,10 +68,10 @@ of steps to be fed into the mcopy sequence.
**Kind**: instance method of [<code>Mscript</code>](#Mscript)
**Returns**: <code>object</code> - if callback is not provided
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| text | <code>string</code> | | Mscript text to interpret |
| callback | <code>function</code> | <code></code> | Function to call when string is interpreted |
| Param | Type | Description |
| --- | --- | --- |
| text | <code>string</code> | Mscript text to interpret |
| callback | <code>function</code> | Function to call when string is interpreted |
<a name="Mscript+variable"></a>
@ -408,17 +400,3 @@ another array
| arr | <code>Array</code> | Original array to compare |
| arr2 | <code>Array</code> | Array to compare elements from |
<a name="startsWith"></a>
## startsWith(str, target, position) ⇒ <code>boolean</code>
startswith function from lodash, do not want the entire lib for this
**Kind**: global function
**Returns**: <code>boolean</code> - True for match, false for no match
| Param | Type | Description |
| --- | --- | --- |
| str | <code>string</code> | Text to evaluate |
| target | <code>string</code> | Text to compare string against |
| position | <code>integer</code> | Position in the string to make comparison at |

View File

@ -29,7 +29,7 @@ export default class Mscript {
/**
* Clear the state of the script
*/
clear(): void;
private clear;
/**
* Main function, accepts multi-line string, parses into lines
* and interprets the instructions from the text. Returns an array
@ -40,7 +40,7 @@ export default class Mscript {
*
* @returns {object} if callback is not provided
*/
interpret(text: string, callback?: Function): any;
interpret(text: string): any;
/**
* Interprets variables for complex sequence behavior.
* TODO: Fully implement, add test coverage
@ -48,7 +48,7 @@ export default class Mscript {
* @param {string} line Line containing a variable assignment
*
**/
variable(line: string): void;
private variable;
/**
* Replace variable with value at time of interpretation
* TODO: Implement this please
@ -57,87 +57,87 @@ export default class Mscript {
*
* @returns {string} New string to be interpreted
**/
variable_replace(line: string): string;
private variable_replace;
/**
* Interpret a basic two character command
*
* @param {string} line Line of script to interpret
* @param {string} short The short command to use
*/
basic_cmd(line: string, short: string): void;
private basic_cmd;
/**
* Start a new loop
*
* @param {string} line Line to evaluate as either loop or fade
* @param {boolean} fade Flag as true if fade
*/
new_loop(line: string, fade?: boolean): void;
private new_loop;
/**
* Close the most recent loop
*
* @param {string} line Line to interpret
*/
end_loop(line: string): void;
private end_loop;
/**
* Move camera to explicitly-defined frame
*
* @param {string} line Line to interpret with camera move statement
*/
move_cam(line: string): void;
private move_cam;
/**
* Move secondary camera to explicitly-defined frame
*
* @param {string} line Line to interpret with camera move statement
*/
move_cam2(line: string): void;
private move_cam2;
/**
* Move projector to explicitly-defined frame
*
* @param {string} line Line containing `move` statement to interpret
*/
move_proj(line: string): void;
private move_proj;
/**
* Move projector to explicitly-defined frame
*
* @param {string} line Line containing `move` statement to interpret
*/
move_proj2(line: string): void;
private move_proj2;
/**
* Set the state of either the cam or projector
*
* @param line {string} String containing set statement
*/
set_state(line: string): void;
private set_state;
/**
* Return the last loop
*
* @returns {object}
*/
last_loop(): any;
private last_loop;
/**
* Return the second-last loop
*
* @returns {object} Loop array
*/
parent_loop(): any;
private parent_loop;
/**
* Extract the loop count integer from a LOOP cmd
*
* @returns {integer} Loop count in string parsed into integer
*/
loop_count(str: string): number;
private loop_count;
/**
* Execute a fade of frame length, from color to another color
*
* @param {string} line Line containing a fade initiator
*/
fade(line: string): void;
private fade;
/**
* Extract the fade length integer from a FADE cmd
*
* @param {string} str Line containing the length of fade in frames
*/
fade_count(str: string): number;
private fade_count;
/**
* Extract the start color from a string
*
@ -145,7 +145,7 @@ export default class Mscript {
*
* @returns {array} Array containing RGB color values
*/
fade_start(str: string): RGB;
private fade_start;
/**
* Extract the end color from a string
*
@ -153,7 +153,7 @@ export default class Mscript {
*
* @returns {array} Array containing RGB color values
*/
fade_end(str: string): RGB;
private fade_end;
/**
* Determine the state of a fade at a particular frame in the sequence, x
*
@ -164,13 +164,13 @@ export default class Mscript {
*
* @returns {array} Array containing RGB color values
*/
fade_rgb(start: RGB, end: RGB, len: number, x: number): string;
private fade_rgb;
/**
* Parse string into array of RGB color values. 0-255 octet.
*
* @param {string} str String containing only color values as `#,#,#`
**/
rgb(str: string): RGB;
private rgb;
/**
* Cast RGB color values as string
*
@ -178,14 +178,14 @@ export default class Mscript {
*
* @returns {string} String of RGB values
**/
rgb_str(arr: RGB): string;
private rgb_str;
/**
* Increase the state of a specific object, such as the camera/projector,
* by the value defined in val.
*
* @param {string} cmd String representing command to interpret and update state
*/
update(cmd: string, val?: number): void;
private update;
/**
* Split string on command, turn into array of commands
* as long as count variable. Default 1.
@ -195,7 +195,7 @@ export default class Mscript {
*
* @returns {array} Array containing commands
*/
str_to_arr(str: string, cmd: string): string[];
private str_to_arr;
/**
* Split a string on a command to extract data for light array
*
@ -204,37 +204,37 @@ export default class Mscript {
*
* @returns {array} An RGB array containing the color values
*/
light_to_arr(str: string, cmd: string): RGB;
private light_to_arr;
/**
* Split a string to extract an rgb color value
*
* @param {string} Color string assign to color property
*/
light_state(str: string): void;
private light_state;
/**
* Interpret a delay command
*
* @param {string} line String containing delay command
**/
delay(line: string): void;
private delay;
/**
* Interpret an alert command
*
* @param {string} line String containing alert message
**/
alert(line: string): void;
private alert;
/**
* Interpret an pause command
*
* @param {string} line String containing alert message
**/
pause(line: string): void;
private pause;
/**
* Throw an error with specific message
*
* @param {string} msg Error message to print
*/
fail(msg: string): void;
private fail;
/**
* Determine if array contains matching elements of
* another array
@ -244,6 +244,6 @@ export default class Mscript {
*
* @returns {boolean} Whether arr contains elements in arr2
**/
contains(arr: string[], arr2: string[]): boolean;
private contains;
}
export type { RGB };

View File

@ -63,26 +63,6 @@ const ALTS = {
const DELAY = 'DELAY';
const PAUSE = 'PAUSE';
const ALERT = 'ALERT';
/** helper functions */
/** startswith function from lodash, do not want the entire lib for this
* @param str {string} Text to evaluate
* @param target {string} Text to compare string against
* @param position {integer} Position in the string to make comparison at
*
* @returns {boolean} True for match, false for no match
**/
function startsWith(str, target, position) {
const { length } = str;
position = position == null ? 0 : position;
if (position < 0) {
position = 0;
}
else if (position > length) {
position = length;
}
target = `${target}`;
return str.slice(position, position + target.length) == target;
}
/** class Mscript */
class Mscript {
/**
@ -124,15 +104,15 @@ class Mscript {
*
* @returns {object} if callback is not provided
*/
interpret(text, callback = null) {
interpret(text) {
this.clear();
if (typeof text === 'undefined') {
return this.fail('No input');
}
//split string into lines, each containing a command
this.lines = text.split('\n');
this.lines = this.lines.map(line => {
line = line.replace(/\t+/g, ''); //strip tabs
this.lines = this.lines.map((line) => {
line = line.replace(/\t+/g, ' '); //strip tabs
line = line.trim(); //remove excess whitespace before and after command
line = line.toUpperCase();
return line;
@ -150,46 +130,46 @@ class Mscript {
else if (CMD.indexOf(this.two) !== -1) {
this.basic_cmd(line, this.two);
}
else if (startsWith(line, DELAY)) {
else if (line.startsWith(DELAY)) {
this.delay(line);
}
else if (startsWith(line, PAUSE)) {
else if (line.startsWith(PAUSE)) {
this.pause(line);
}
else if (startsWith(line, ALERT)) {
else if (line.startsWith(ALERT)) {
this.alert(line);
}
else if (startsWith(line, '@') || line.indexOf('@') !== -1) {
else if (line.startsWith('@') || line.indexOf('@') !== -1) {
this.variable(line);
}
else if (startsWith(line, 'LOOP')) {
else if (line.startsWith('LOOP')) {
this.new_loop(line);
}
else if (startsWith(line, 'L ')) {
else if (line.startsWith('L ')) {
this.light_state(line);
}
else if (startsWith(line, 'F ')) {
else if (line.startsWith('F ')) {
this.new_loop(line, true);
}
else if (startsWith(line, 'END')) {
else if (line.startsWith('END')) {
this.end_loop(line);
}
else if (startsWith(line, 'CAM2')) { //directly go to that frame
else if (line.startsWith('CAM2')) { //directly go to that frame
this.move_cam2(line);
}
else if (startsWith(line, 'CAM')) { //directly go to that frame
else if (line.startsWith('CAM')) { //directly go to that frame
this.move_cam(line);
}
else if (startsWith(line, 'PROJ2')) { //directly go to that frame
else if (line.startsWith('PROJ2')) { //directly go to that frame
this.move_proj2(line);
}
else if (startsWith(line, 'PROJ')) { //directly go to that frame
else if (line.startsWith('PROJ')) { //directly go to that frame
this.move_proj(line);
}
else if (startsWith(line, 'SET')) { //set that state
else if (line.startsWith('SET')) { //set that state
this.set_state(line);
}
else if (startsWith(line, '#') || startsWith(line, '//')) {
else if (line.startsWith('#') || line.startsWith('//')) {
//comments
//ignore while parsing
}
@ -205,14 +185,8 @@ class Mscript {
if (this.contains(this.arr, PROJECTOR_SECONDARY)) {
this.output.proj2 = this.proj2;
}
if (typeof callback !== 'undefined' && callback != null) {
//should only be invoked by running mscript.tests()
callback(this.output);
}
else {
return this.output;
}
}
/**
* Interprets variables for complex sequence behavior.
* TODO: Fully implement, add test coverage
@ -319,7 +293,7 @@ class Mscript {
start = this.loops[this.rec].start;
end = this.loops[this.rec].end;
len = this.loops[this.rec].fade_len;
meta_arr = meta_arr.map(l => {
meta_arr = meta_arr.map((l) => {
return this.fade_rgb(start, end, len, x);
});
}
@ -520,16 +494,16 @@ class Mscript {
* @param line {string} String containing set statement
*/
set_state(line) {
if (startsWith(line, 'SET CAM2')) {
if (line.startsWith('SET CAM2')) {
parseInt(line.split('SET CAM2')[1]);
}
else if (startsWith(line, 'SET PROJ2')) {
else if (line.startsWith('SET PROJ2')) {
this.cam2 = parseInt(line.split('SET PROJ2')[1]);
}
else if (startsWith(line, 'SET CAM')) {
else if (line.startsWith('SET CAM')) {
this.cam = parseInt(line.split('SET CAM')[1]);
}
else if (startsWith(line, 'SET PROJ')) {
else if (line.startsWith('SET PROJ')) {
this.proj = parseInt(line.split('SET PROJ')[1]);
}
}
@ -563,9 +537,9 @@ class Mscript {
* @param {string} line Line containing a fade initiator
*/
fade(line) {
let len = this.fade_count(line);
let start = this.fade_start(line);
let end = this.fade_end(line);
const len = this.fade_count(line);
const start = this.fade_start(line);
const end = this.fade_end(line);
this.loops[this.rec].start = start;
this.loops[this.rec].end = end;
this.loops[this.rec].fade = true;
@ -599,7 +573,7 @@ class Mscript {
* @returns {array} Array containing RGB color values
*/
fade_end(str) {
let color = str.split(' ')[3];
const color = str.split(' ')[3];
return this.rgb(color.trim());
}
/**
@ -636,7 +610,7 @@ class Mscript {
* @param {string} str String containing only color values as `#,#,#`
**/
rgb(str) {
let rgb = str.split(',');
const rgb = str.split(',');
return rgb.map((char) => {
return parseInt(char);
});
@ -988,7 +962,7 @@ class Mscript {
* @returns {boolean} Whether arr contains elements in arr2
**/
contains(arr, arr2) {
return arr.some(r => arr2.includes(r));
return arr.some((r) => arr2.includes(r));
}
}
exports.default = Mscript;

File diff suppressed because one or more lines are too long

2
app/package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "mcopy-app",
"version": "1.8.114",
"version": "1.8.116",
"lockfileVersion": 2,
"requires": true,
"packages": {

View File

@ -1,6 +1,6 @@
{
"name": "mcopy-app",
"version": "1.8.114",
"version": "1.8.116",
"description": "GUI for the mcopy small gauge film optical printer platform",
"main": "main.js",
"scripts": {

View File

@ -1,5 +1,5 @@
{
"version": "1.8.114",
"version": "1.8.116",
"ext_port": 1111,
"profiles": {
"mcopy": {

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "mcopy",
"version": "1.8.114",
"version": "1.8.116",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "mcopy",
"version": "1.8.114",
"version": "1.8.116",
"license": "MIT",
"dependencies": {
"alert": "file:app/lib/alert",

View File

@ -1,6 +1,6 @@
{
"name": "mcopy",
"version": "1.8.114",
"version": "1.8.116",
"description": "Small gauge film optical printer platform",
"main": "build.js",
"directories": {

View File

@ -1,5 +1,5 @@
{
"version": "1.8.114",
"version": "1.8.116",
"ext_port": 1111,
"profiles": {
"mcopy": {

View File

@ -76,30 +76,6 @@ const DELAY : string = 'DELAY';
const PAUSE : string = 'PAUSE';
const ALERT : string = 'ALERT';
/** helper functions */
/** startswith function from lodash, do not want the entire lib for this
* @param str {string} Text to evaluate
* @param target {string} Text to compare string against
* @param position {integer} Position in the string to make comparison at
*
* @returns {boolean} True for match, false for no match
**/
function startsWith (str : string, target : string, position? : number) : boolean {
const { length } = str;
position = position == null ? 0 : position;
if (position < 0) {
position = 0;
} else if (position > length) {
position = length;
}
target = `${target}`;
return str.slice(position, position + target.length) == target;
}
/** class Mscript */
export default class Mscript {
@ -132,7 +108,7 @@ export default class Mscript {
/**
* Clear the state of the script
*/
clear () {
private clear () {
this.lines = [];
this.cam = 0;
@ -164,7 +140,7 @@ export default class Mscript {
*
* @returns {object} if callback is not provided
*/
interpret (text : string, callback : Function = null) {
public interpret (text : string) {
this.clear()
if (typeof text === 'undefined') {
@ -174,8 +150,8 @@ export default class Mscript {
//split string into lines, each containing a command
this.lines = text.split('\n');
this.lines = this.lines.map(line => {
line = line.replace(/\t+/g, ''); //strip tabs
this.lines = this.lines.map((line : string) => {
line = line.replace(/\t+/g, ' '); //strip tabs
line = line.trim(); //remove excess whitespace before and after command
line = line.toUpperCase();
return line;
@ -191,33 +167,33 @@ export default class Mscript {
this.basic_cmd(line, this.three);
} else if (CMD.indexOf(this.two) !== -1) {
this.basic_cmd(line, this.two);
} else if (startsWith(line, DELAY)) {
} else if (line.startsWith(DELAY)) {
this.delay(line);
} else if (startsWith(line, PAUSE)) {
} else if (line.startsWith(PAUSE)) {
this.pause(line);
} else if (startsWith(line, ALERT)) {
} else if (line.startsWith(ALERT)) {
this.alert(line);
} else if (startsWith(line, '@') || line.indexOf('@') !== -1) {
} else if (line.startsWith('@') || line.indexOf('@') !== -1) {
this.variable(line);
} else if (startsWith(line, 'LOOP')) {
} else if (line.startsWith('LOOP')) {
this.new_loop(line);
} else if (startsWith(line, 'L ')) {
} else if (line.startsWith('L ')) {
this.light_state(line);
} else if (startsWith(line, 'F ')) {
} else if (line.startsWith('F ')) {
this.new_loop(line, true);
} else if (startsWith(line, 'END')) {
} else if (line.startsWith('END')) {
this.end_loop(line);
} else if (startsWith(line, 'CAM2')) { //directly go to that frame
} else if (line.startsWith('CAM2')) { //directly go to that frame
this.move_cam2(line);
} else if (startsWith(line, 'CAM')) { //directly go to that frame
} else if (line.startsWith('CAM')) { //directly go to that frame
this.move_cam(line);
} else if (startsWith(line, 'PROJ2')) { //directly go to that frame
} else if (line.startsWith('PROJ2')) { //directly go to that frame
this.move_proj2(line);
} else if (startsWith(line, 'PROJ')) { //directly go to that frame
} else if (line.startsWith('PROJ')) { //directly go to that frame
this.move_proj(line);
} else if (startsWith(line, 'SET')) { //set that state
} else if (line.startsWith('SET')) { //set that state
this.set_state(line);
} else if (startsWith(line, '#') || startsWith(line, '//')) {
} else if (line.startsWith('#') || line.startsWith('//')) {
//comments
//ignore while parsing
}
@ -235,13 +211,8 @@ export default class Mscript {
this.output.proj2 = this.proj2;
}
if (typeof callback !== 'undefined' && callback != null) {
//should only be invoked by running mscript.tests()
callback(this.output);
} else {
return this.output;
}
}
/**
* Interprets variables for complex sequence behavior.
* TODO: Fully implement, add test coverage
@ -249,7 +220,7 @@ export default class Mscript {
* @param {string} line Line containing a variable assignment
*
**/
variable (line : string) {
private variable (line : string) {
let parts : string[] = line.split('=');
let key : string = parts[0];
let value : any = parts[1];
@ -294,7 +265,7 @@ export default class Mscript {
*
* @returns {string} New string to be interpreted
**/
variable_replace(line : string) : string {
private variable_replace(line : string) : string {
return line;
}
/**
@ -303,7 +274,7 @@ export default class Mscript {
* @param {string} line Line of script to interpret
* @param {string} short The short command to use
*/
basic_cmd (line : string, short : string) {
private basic_cmd (line : string, short : string) {
if (this.rec !== -1) {
//hold generated arr in state loop array
this.loops[this.rec].arr
@ -325,7 +296,7 @@ export default class Mscript {
* @param {string} line Line to evaluate as either loop or fade
* @param {boolean} fade Flag as true if fade
*/
new_loop (line : string, fade? : boolean) {
private new_loop (line : string, fade? : boolean) {
this.rec++;
this.loops[this.rec] = {
arr : [],
@ -345,7 +316,7 @@ export default class Mscript {
*
* @param {string} line Line to interpret
*/
end_loop (line : string) {
private end_loop (line : string) {
let meta_arr : string[];
let start : RGB;
let end : RGB;
@ -357,7 +328,7 @@ export default class Mscript {
start = this.loops[this.rec].start;
end = this.loops[this.rec].end;
len = this.loops[this.rec].fade_len;
meta_arr = meta_arr.map(l => {
meta_arr = meta_arr.map((l : string) => {
return this.fade_rgb(start, end, len, x);
})
}
@ -383,7 +354,7 @@ export default class Mscript {
*
* @param {string} line Line to interpret with camera move statement
*/
move_cam (line : string) {
private move_cam (line : string) {
this.target = parseInt(line.split('CAM ')[1]);
if (this.rec !== -1) {
if (this.target > this.cam) {
@ -425,7 +396,7 @@ export default class Mscript {
*
* @param {string} line Line to interpret with camera move statement
*/
move_cam2 (line : string) {
private move_cam2 (line : string) {
this.target = parseInt(line.split('CAM2 ')[1]);
if (this.rec !== -1) {
if (this.target > this.cam2) {
@ -467,7 +438,7 @@ export default class Mscript {
*
* @param {string} line Line containing `move` statement to interpret
*/
move_proj (line : string) {
private move_proj (line : string) {
this.target = parseInt(line.split('PROJ ')[1]);
if (this.rec !== -1) {
if (this.target > this.proj) {
@ -509,7 +480,7 @@ export default class Mscript {
*
* @param {string} line Line containing `move` statement to interpret
*/
move_proj2 (line : string) {
private move_proj2 (line : string) {
this.target = parseInt(line.split('PROJ2 ')[1]);
if (this.rec !== -1) {
if (this.target > this.proj2) {
@ -550,14 +521,14 @@ export default class Mscript {
*
* @param line {string} String containing set statement
*/
set_state (line : string) {
if (startsWith(line, 'SET CAM2')) {
private set_state (line : string) {
if (line.startsWith('SET CAM2')) {
parseInt(line.split('SET CAM2')[1]);
} else if (startsWith(line, 'SET PROJ2')) {
} else if (line.startsWith('SET PROJ2')) {
this.cam2 = parseInt(line.split('SET PROJ2')[1]);
} else if (startsWith(line, 'SET CAM')) {
} else if (line.startsWith('SET CAM')) {
this.cam = parseInt(line.split('SET CAM')[1]);
} else if (startsWith(line, 'SET PROJ')) {
} else if (line.startsWith('SET PROJ')) {
this.proj = parseInt(line.split('SET PROJ')[1]);
}
}
@ -566,7 +537,7 @@ export default class Mscript {
*
* @returns {object}
*/
last_loop () : any {
private last_loop () : any {
return this.loops[this.loops.length - 1];
}
/**
@ -574,7 +545,7 @@ export default class Mscript {
*
* @returns {object} Loop array
*/
parent_loop () : any {
private parent_loop () : any {
return this.loops[this.loops.length - 2];
}
/**
@ -582,7 +553,7 @@ export default class Mscript {
*
* @returns {integer} Loop count in string parsed into integer
*/
loop_count (str : string) : number {
private loop_count (str : string) : number {
return parseInt(str.split(' ')[1]);
}
/**
@ -590,10 +561,10 @@ export default class Mscript {
*
* @param {string} line Line containing a fade initiator
*/
fade (line : string) {
let len = this.fade_count(line);
let start = this.fade_start(line);
let end = this.fade_end(line);
private fade (line : string) {
const len : number = this.fade_count(line);
const start : RGB = this.fade_start(line);
const end : RGB = this.fade_end(line);
this.loops[this.rec].start = start;
this.loops[this.rec].end = end;
@ -606,7 +577,7 @@ export default class Mscript {
*
* @param {string} str Line containing the length of fade in frames
*/
fade_count (str : string) {
private fade_count (str : string) {
return parseInt(str.split(' ')[1]);
}
/**
@ -616,7 +587,7 @@ export default class Mscript {
*
* @returns {array} Array containing RGB color values
*/
fade_start (str : string) : RGB {
private fade_start (str : string) : RGB {
let color : string = str.split(' ')[2];
return this.rgb(color.trim())
}
@ -627,8 +598,8 @@ export default class Mscript {
*
* @returns {array} Array containing RGB color values
*/
fade_end (str : string) : RGB {
let color : string = str.split(' ')[3];
private fade_end (str : string) : RGB {
const color : string = str.split(' ')[3];
return this.rgb(color.trim())
}
/**
@ -641,9 +612,9 @@ export default class Mscript {
*
* @returns {array} Array containing RGB color values
*/
fade_rgb (start : RGB, end : RGB, len : number, x : number) {
private fade_rgb (start : RGB, end : RGB, len : number, x : number) {
let cur = [];
let diff;
let diff : number;
for (let i : number = 0; i < 3; i++) {
if (x === len - 1) {
cur[i] = end[i];
@ -663,11 +634,11 @@ export default class Mscript {
*
* @param {string} str String containing only color values as `#,#,#`
**/
rgb (str : string) : RGB {
let rgb = str.split(',');
private rgb (str : string) : RGB {
const rgb : string[] = str.split(',');
return rgb.map( (char : string) => {
return parseInt(char);
})
});
}
/**
* Cast RGB color values as string
@ -676,7 +647,7 @@ export default class Mscript {
*
* @returns {string} String of RGB values
**/
rgb_str (arr : RGB) : string {
private rgb_str (arr : RGB) : string {
return arr.join(',');
}
/**
@ -685,7 +656,7 @@ export default class Mscript {
*
* @param {string} cmd String representing command to interpret and update state
*/
update (cmd : string, val : number = 1) {
private update (cmd : string, val : number = 1) {
if (cmd === 'END') {
//I don't understand this loop
for (let i = 0; i < val; i++) {
@ -834,7 +805,7 @@ export default class Mscript {
*
* @returns {array} Array containing commands
*/
str_to_arr (str : string, cmd : string) : string[] {
private str_to_arr (str : string, cmd : string) : string[] {
const cnt : string[] = str.split(cmd);
let c : number = parseInt(cnt[1]);
let arr : any[] = [];
@ -855,7 +826,7 @@ export default class Mscript {
*
* @returns {array} An RGB array containing the color values
*/
light_to_arr (str : string, cmd : string) : RGB {
private light_to_arr (str : string, cmd : string) : RGB {
const cnt : string[] = str.split(cmd);
let c : number = parseInt(cnt[1]);
let arr : any[] = [];
@ -882,7 +853,7 @@ export default class Mscript {
*
* @param {string} Color string assign to color property
*/
light_state (str : string) {
private light_state (str : string) {
//add parsers for other color spaces
const color : string = str.replace('L ', '').trim();
this.color = color;
@ -893,7 +864,7 @@ export default class Mscript {
*
* @param {string} line String containing delay command
**/
delay (line : string) {
private delay (line : string) {
let lenStr : string = line.split(' ')[1] || ''
let len : number;
lenStr = lenStr.trim();
@ -927,7 +898,7 @@ export default class Mscript {
*
* @param {string} line String containing alert message
**/
alert (line : string) {
private alert (line : string) {
let msg : string = line.split(' ')[1] || ''
msg = msg.trim();
if (this.rec !== -1) {
@ -947,7 +918,7 @@ export default class Mscript {
*
* @param {string} line String containing alert message
**/
pause (line : string) {
private pause (line : string) {
const msg : string = "Paused script. Click OK to continue."
if (this.rec !== -1) {
//hold generated arr in state loop array
@ -966,7 +937,7 @@ export default class Mscript {
*
* @param {string} msg Error message to print
*/
fail (msg : string) {
private fail (msg : string) {
throw new Error(msg);
}
@ -979,8 +950,8 @@ export default class Mscript {
*
* @returns {boolean} Whether arr contains elements in arr2
**/
contains (arr : string[], arr2 : string[]) {
return arr.some(r => arr2.includes(r));
private contains (arr : string[], arr2 : string[]) {
return arr.some((r : string) => arr2.includes(r));
}
}