mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-11 16:18:10 +00:00
util: enforce formatting rules
This commit is contained in:
parent
c9cb3c8412
commit
57a590c536
@ -7,7 +7,6 @@
|
||||
* @license Distributed under the terms of the MIT License
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* <p>MonotonicClock offers a convenient way to keep track of time during experiments. An experiment can have as many independent clocks as needed, e.g. one to time responses, another one to keep track of stimuli, etc.</p>
|
||||
*
|
||||
@ -22,7 +21,6 @@ export class MonotonicClock
|
||||
this._timeAtLastReset = startTime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current time on this clock.
|
||||
*
|
||||
@ -36,7 +34,6 @@ export class MonotonicClock
|
||||
return MonotonicClock.getReferenceTime() - this._timeAtLastReset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current offset being applied to the high resolution timebase used by this Clock.
|
||||
*
|
||||
@ -50,7 +47,6 @@ export class MonotonicClock
|
||||
return this._timeAtLastReset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the time elapsed since the reference point.
|
||||
*
|
||||
@ -65,7 +61,6 @@ export class MonotonicClock
|
||||
// return (new Date().getTime()) / 1000.0 - MonotonicClock._referenceTime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current timestamp with language-sensitive formatting rules applied.
|
||||
*
|
||||
@ -79,18 +74,18 @@ export class MonotonicClock
|
||||
* @param {object} options - An object with detailed date and time styling information.
|
||||
* @return {string} The current timestamp in the chosen format.
|
||||
*/
|
||||
static getDate(locales = 'en-CA', optionsMaybe)
|
||||
static getDate(locales = "en-CA", optionsMaybe)
|
||||
{
|
||||
const date = new Date();
|
||||
const options = Object.assign({
|
||||
hour12: false,
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: 'numeric',
|
||||
minute: 'numeric',
|
||||
second: 'numeric',
|
||||
fractionalSecondDigits: 3
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
second: "numeric",
|
||||
fractionalSecondDigits: 3,
|
||||
}, optionsMaybe);
|
||||
|
||||
const dateTimeFormat = new Intl.DateTimeFormat(locales, options);
|
||||
@ -114,15 +109,14 @@ export class MonotonicClock
|
||||
// yyyy-mm-dd, hh:mm:ss.sss
|
||||
return MonotonicClock.getDate()
|
||||
// yyyy-mm-dd_hh:mm:ss.sss
|
||||
.replace(', ', '_')
|
||||
.replace(", ", "_")
|
||||
// yyyy-mm-dd_hh[h]mm:ss.sss
|
||||
.replace(':', 'h')
|
||||
.replace(":", "h")
|
||||
// yyyy-mm-dd_hh[h]mm.ss.sss
|
||||
.replace(':', '.');
|
||||
.replace(":", ".");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The clock's referenceTime is the time when the module was loaded (in seconds).
|
||||
*
|
||||
@ -135,7 +129,6 @@ MonotonicClock._referenceTime = performance.now() / 1000.0;
|
||||
|
||||
// MonotonicClock._referenceTime = new Date().getTime() / 1000.0;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Clock is a MonotonicClock that also offers the possibility of being reset.</p>
|
||||
*
|
||||
@ -164,7 +157,6 @@ export class Clock extends MonotonicClock
|
||||
this._timeAtLastReset = MonotonicClock.getReferenceTime() + newTime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add more time to the clock's 'start' time (t0).
|
||||
*
|
||||
@ -182,7 +174,6 @@ export class Clock extends MonotonicClock
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>CountdownTimer is a clock counts down from the time of last reset.</p.
|
||||
*
|
||||
@ -205,7 +196,6 @@ export class CountdownTimer extends Clock
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add more time to the clock's 'start' time (t0).
|
||||
*
|
||||
@ -222,7 +212,6 @@ export class CountdownTimer extends Clock
|
||||
this._timeAtLastReset += deltaTime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reset the time on the countdown.
|
||||
*
|
||||
@ -234,7 +223,7 @@ export class CountdownTimer extends Clock
|
||||
*/
|
||||
reset(newTime = undefined)
|
||||
{
|
||||
if (typeof newTime == 'undefined')
|
||||
if (typeof newTime == "undefined")
|
||||
{
|
||||
this._timeAtLastReset = MonotonicClock.getReferenceTime() + this._countdown_duration;
|
||||
}
|
||||
@ -245,7 +234,6 @@ export class CountdownTimer extends Clock
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the time currently left on the countdown.
|
||||
*
|
||||
@ -259,4 +247,3 @@ export class CountdownTimer extends Clock
|
||||
return this._timeAtLastReset - MonotonicClock.getReferenceTime();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
* @license Distributed under the terms of the MIT License
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* <p>This class handles multiple color spaces, and offers various
|
||||
* static methods for converting colors from one space to another.</p>
|
||||
@ -32,27 +31,26 @@
|
||||
*/
|
||||
export class Color
|
||||
{
|
||||
|
||||
constructor(obj = 'black', colorspace = Color.COLOR_SPACE.RGB)
|
||||
constructor(obj = "black", colorspace = Color.COLOR_SPACE.RGB)
|
||||
{
|
||||
const response = {
|
||||
origin: 'Color',
|
||||
context: 'when defining a color'
|
||||
origin: "Color",
|
||||
context: "when defining a color",
|
||||
};
|
||||
|
||||
// named color (e.g. 'seagreen') or string hexadecimal representation (e.g. '#FF0000'):
|
||||
// note: we expect the color space to be RGB
|
||||
if (typeof obj == 'string')
|
||||
if (typeof obj == "string")
|
||||
{
|
||||
if (colorspace !== Color.COLOR_SPACE.RGB)
|
||||
{
|
||||
throw Object.assign(response, {
|
||||
error: 'the colorspace must be RGB for a named color'
|
||||
error: "the colorspace must be RGB for a named color",
|
||||
});
|
||||
}
|
||||
|
||||
// hexademical representation:
|
||||
if (obj[0] === '#')
|
||||
if (obj[0] === "#")
|
||||
{
|
||||
this._hex = obj;
|
||||
}
|
||||
@ -61,7 +59,7 @@ export class Color
|
||||
{
|
||||
if (!(obj.toLowerCase() in Color.NAMED_COLORS))
|
||||
{
|
||||
throw Object.assign(response, {error: 'unknown named color: ' + obj});
|
||||
throw Object.assign(response, { error: "unknown named color: " + obj });
|
||||
}
|
||||
|
||||
this._hex = Color.NAMED_COLORS[obj.toLowerCase()];
|
||||
@ -69,23 +67,21 @@ export class Color
|
||||
|
||||
this._rgb = Color.hexToRgb(this._hex);
|
||||
}
|
||||
|
||||
// hexadecimal number representation (e.g. 0xFF0000)
|
||||
// note: we expect the color space to be RGB
|
||||
else if (typeof obj == 'number')
|
||||
else if (typeof obj == "number")
|
||||
{
|
||||
if (colorspace !== Color.COLOR_SPACE.RGB)
|
||||
{
|
||||
throw Object.assign(response, {
|
||||
error: 'the colorspace must be RGB for' +
|
||||
' a' +
|
||||
' named color'
|
||||
error: "the colorspace must be RGB for"
|
||||
+ " a"
|
||||
+ " named color",
|
||||
});
|
||||
}
|
||||
|
||||
this._rgb = Color._intToRgb(obj);
|
||||
}
|
||||
|
||||
// array of numbers:
|
||||
else if (Array.isArray(obj))
|
||||
{
|
||||
@ -124,17 +120,15 @@ export class Color
|
||||
break;
|
||||
|
||||
default:
|
||||
throw Object.assign(response, {error: 'unknown colorspace: ' + colorspace});
|
||||
throw Object.assign(response, { error: "unknown colorspace: " + colorspace });
|
||||
}
|
||||
}
|
||||
|
||||
else if (obj instanceof Color)
|
||||
{
|
||||
this._rgb = obj._rgb.slice();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the [0,1] RGB triplet equivalent of this Color.
|
||||
*
|
||||
@ -148,7 +142,6 @@ export class Color
|
||||
return this._rgb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the [0,255] RGB triplet equivalent of this Color.
|
||||
*
|
||||
@ -162,7 +155,6 @@ export class Color
|
||||
return [Math.round(this._rgb[0] * 255.0), Math.round(this._rgb[1] * 255.0), Math.round(this._rgb[2] * 255.0)];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the hexadecimal color code equivalent of this Color.
|
||||
*
|
||||
@ -173,7 +165,7 @@ export class Color
|
||||
*/
|
||||
get hex()
|
||||
{
|
||||
if (typeof this._hex === 'undefined')
|
||||
if (typeof this._hex === "undefined")
|
||||
{
|
||||
this._hex = Color._rgbToHex(this._rgb);
|
||||
}
|
||||
@ -190,14 +182,13 @@ export class Color
|
||||
*/
|
||||
get int()
|
||||
{
|
||||
if (typeof this._int === 'undefined')
|
||||
if (typeof this._int === "undefined")
|
||||
{
|
||||
this._int = Color._rgbToInt(this._rgb);
|
||||
}
|
||||
return this._int;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
get hsv() {
|
||||
if (typeof this._hsv === 'undefined')
|
||||
@ -216,7 +207,6 @@ export class Color
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* String representation of the color, i.e. the hexadecimal representation.
|
||||
*
|
||||
@ -230,7 +220,6 @@ export class Color
|
||||
return this.hex;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the [0,255] RGB triplet equivalent of the hexadecimal color code.
|
||||
*
|
||||
@ -247,16 +236,15 @@ export class Color
|
||||
if (result == null)
|
||||
{
|
||||
throw {
|
||||
origin: 'Color.hexToRgb255',
|
||||
context: 'when converting an hexadecimal color code to its 255- or [0,1]-based RGB color representation',
|
||||
error: 'unable to parse the argument: wrong type or wrong code'
|
||||
origin: "Color.hexToRgb255",
|
||||
context: "when converting an hexadecimal color code to its 255- or [0,1]-based RGB color representation",
|
||||
error: "unable to parse the argument: wrong type or wrong code",
|
||||
};
|
||||
}
|
||||
|
||||
return [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the [0,1] RGB triplet equivalent of the hexadecimal color code.
|
||||
*
|
||||
@ -273,7 +261,6 @@ export class Color
|
||||
return [r255 / 255.0, g255 / 255.0, b255 / 255.0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the hexadecimal color code equivalent of the [0, 255] RGB triplet.
|
||||
*
|
||||
@ -287,8 +274,8 @@ export class Color
|
||||
static rgb255ToHex(rgb255)
|
||||
{
|
||||
const response = {
|
||||
origin: 'Color.rgb255ToHex',
|
||||
context: 'when converting an rgb triplet to its hexadecimal color representation'
|
||||
origin: "Color.rgb255ToHex",
|
||||
context: "when converting an rgb triplet to its hexadecimal color representation",
|
||||
};
|
||||
|
||||
try
|
||||
@ -298,11 +285,10 @@ export class Color
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
throw Object.assign(response, {error});
|
||||
throw Object.assign(response, { error });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the hexadecimal color code equivalent of the [0, 1] RGB triplet.
|
||||
*
|
||||
@ -316,8 +302,8 @@ export class Color
|
||||
static rgbToHex(rgb)
|
||||
{
|
||||
const response = {
|
||||
origin: 'Color.rgbToHex',
|
||||
context: 'when converting an rgb triplet to its hexadecimal color representation'
|
||||
origin: "Color.rgbToHex",
|
||||
context: "when converting an rgb triplet to its hexadecimal color representation",
|
||||
};
|
||||
|
||||
try
|
||||
@ -327,11 +313,10 @@ export class Color
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
throw Object.assign(response, {error});
|
||||
throw Object.assign(response, { error });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the integer equivalent of the [0, 1] RGB triplet.
|
||||
*
|
||||
@ -345,8 +330,8 @@ export class Color
|
||||
static rgbToInt(rgb)
|
||||
{
|
||||
const response = {
|
||||
origin: 'Color.rgbToInt',
|
||||
context: 'when converting an rgb triplet to its integer representation'
|
||||
origin: "Color.rgbToInt",
|
||||
context: "when converting an rgb triplet to its integer representation",
|
||||
};
|
||||
|
||||
try
|
||||
@ -356,11 +341,10 @@ export class Color
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
throw Object.assign(response, {error});
|
||||
throw Object.assign(response, { error });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the integer equivalent of the [0, 255] RGB triplet.
|
||||
*
|
||||
@ -374,8 +358,8 @@ export class Color
|
||||
static rgb255ToInt(rgb255)
|
||||
{
|
||||
const response = {
|
||||
origin: 'Color.rgb255ToInt',
|
||||
context: 'when converting an rgb triplet to its integer representation'
|
||||
origin: "Color.rgb255ToInt",
|
||||
context: "when converting an rgb triplet to its integer representation",
|
||||
};
|
||||
try
|
||||
{
|
||||
@ -384,11 +368,10 @@ export class Color
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
throw Object.assign(response, {error});
|
||||
throw Object.assign(response, { error });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the hexadecimal color code equivalent of the [0, 255] RGB triplet.
|
||||
*
|
||||
@ -406,7 +389,6 @@ export class Color
|
||||
return "#" + ((1 << 24) + (rgb255[0] << 16) + (rgb255[1] << 8) + rgb255[2]).toString(16).slice(1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the hexadecimal color code equivalent of the [0, 1] RGB triplet.
|
||||
*
|
||||
@ -425,7 +407,6 @@ export class Color
|
||||
return Color._rgb255ToHex(rgb255);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the integer equivalent of the [0, 1] RGB triplet.
|
||||
*
|
||||
@ -444,7 +425,6 @@ export class Color
|
||||
return Color._rgb255ToInt(rgb255);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the integer equivalent of the [0, 255] RGB triplet.
|
||||
*
|
||||
@ -462,7 +442,6 @@ export class Color
|
||||
return rgb255[0] * 0x10000 + rgb255[1] * 0x100 + rgb255[2];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the [0, 255] based RGB triplet equivalent of the integer color code.
|
||||
*
|
||||
@ -484,7 +463,6 @@ export class Color
|
||||
return [r255, g255, b255];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the [0, 1] based RGB triplet equivalent of the integer color code.
|
||||
*
|
||||
@ -517,20 +495,21 @@ export class Color
|
||||
*/
|
||||
static _checkTypeAndRange(arg, range = undefined)
|
||||
{
|
||||
if (!Array.isArray(arg) || arg.length !== 3 ||
|
||||
typeof arg[0] !== 'number' || typeof arg[1] !== 'number' || typeof arg[2] !== 'number')
|
||||
if (
|
||||
!Array.isArray(arg) || arg.length !== 3
|
||||
|| typeof arg[0] !== "number" || typeof arg[1] !== "number" || typeof arg[2] !== "number"
|
||||
)
|
||||
{
|
||||
throw 'the argument should be an array of numbers of length 3';
|
||||
throw "the argument should be an array of numbers of length 3";
|
||||
}
|
||||
|
||||
if (typeof range !== 'undefined' && (arg[0] < range[0] || arg[0] > range[1] || arg[1] < range[0] || arg[1] > range[1] || arg[2] < range[0] || arg[2] > range[1]))
|
||||
if (typeof range !== "undefined" && (arg[0] < range[0] || arg[0] > range[1] || arg[1] < range[0] || arg[1] > range[1] || arg[2] < range[0] || arg[2] > range[1]))
|
||||
{
|
||||
throw 'the color components should all belong to [' + range[0] + ', ' + range[1] + ']';
|
||||
throw "the color components should all belong to [" + range[0] + ", " + range[1] + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Color spaces.
|
||||
*
|
||||
@ -543,13 +522,12 @@ Color.COLOR_SPACE = {
|
||||
/**
|
||||
* RGB colorspace: [r,g,b] with r,g,b in [-1, 1]
|
||||
*/
|
||||
RGB: Symbol.for('RGB'),
|
||||
RGB: Symbol.for("RGB"),
|
||||
|
||||
/**
|
||||
* RGB255 colorspace: [r,g,b] with r,g,b in [0, 255]
|
||||
*/
|
||||
RGB255: Symbol.for('RGB255'),
|
||||
|
||||
RGB255: Symbol.for("RGB255"),
|
||||
/*
|
||||
HSV: Symbol.for('HSV'),
|
||||
DKL: Symbol.for('DKL'),
|
||||
@ -557,7 +535,6 @@ Color.COLOR_SPACE = {
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Named colors.
|
||||
*
|
||||
@ -567,151 +544,151 @@ Color.COLOR_SPACE = {
|
||||
* @public
|
||||
*/
|
||||
Color.NAMED_COLORS = {
|
||||
'aliceblue': '#F0F8FF',
|
||||
'antiquewhite': '#FAEBD7',
|
||||
'aqua': '#00FFFF',
|
||||
'aquamarine': '#7FFFD4',
|
||||
'azure': '#F0FFFF',
|
||||
'beige': '#F5F5DC',
|
||||
'bisque': '#FFE4C4',
|
||||
'black': '#000000',
|
||||
'blanchedalmond': '#FFEBCD',
|
||||
'blue': '#0000FF',
|
||||
'blueviolet': '#8A2BE2',
|
||||
'brown': '#A52A2A',
|
||||
'burlywood': '#DEB887',
|
||||
'cadetblue': '#5F9EA0',
|
||||
'chartreuse': '#7FFF00',
|
||||
'chocolate': '#D2691E',
|
||||
'coral': '#FF7F50',
|
||||
'cornflowerblue': '#6495ED',
|
||||
'cornsilk': '#FFF8DC',
|
||||
'crimson': '#DC143C',
|
||||
'cyan': '#00FFFF',
|
||||
'darkblue': '#00008B',
|
||||
'darkcyan': '#008B8B',
|
||||
'darkgoldenrod': '#B8860B',
|
||||
'darkgray': '#A9A9A9',
|
||||
'darkgrey': '#A9A9A9',
|
||||
'darkgreen': '#006400',
|
||||
'darkkhaki': '#BDB76B',
|
||||
'darkmagenta': '#8B008B',
|
||||
'darkolivegreen': '#556B2F',
|
||||
'darkorange': '#FF8C00',
|
||||
'darkorchid': '#9932CC',
|
||||
'darkred': '#8B0000',
|
||||
'darksalmon': '#E9967A',
|
||||
'darkseagreen': '#8FBC8B',
|
||||
'darkslateblue': '#483D8B',
|
||||
'darkslategray': '#2F4F4F',
|
||||
'darkslategrey': '#2F4F4F',
|
||||
'darkturquoise': '#00CED1',
|
||||
'darkviolet': '#9400D3',
|
||||
'deeppink': '#FF1493',
|
||||
'deepskyblue': '#00BFFF',
|
||||
'dimgray': '#696969',
|
||||
'dimgrey': '#696969',
|
||||
'dodgerblue': '#1E90FF',
|
||||
'firebrick': '#B22222',
|
||||
'floralwhite': '#FFFAF0',
|
||||
'forestgreen': '#228B22',
|
||||
'fuchsia': '#FF00FF',
|
||||
'gainsboro': '#DCDCDC',
|
||||
'ghostwhite': '#F8F8FF',
|
||||
'gold': '#FFD700',
|
||||
'goldenrod': '#DAA520',
|
||||
'gray': '#808080',
|
||||
'grey': '#808080',
|
||||
'green': '#008000',
|
||||
'greenyellow': '#ADFF2F',
|
||||
'honeydew': '#F0FFF0',
|
||||
'hotpink': '#FF69B4',
|
||||
'indianred': '#CD5C5C',
|
||||
'indigo': '#4B0082',
|
||||
'ivory': '#FFFFF0',
|
||||
'khaki': '#F0E68C',
|
||||
'lavender': '#E6E6FA',
|
||||
'lavenderblush': '#FFF0F5',
|
||||
'lawngreen': '#7CFC00',
|
||||
'lemonchiffon': '#FFFACD',
|
||||
'lightblue': '#ADD8E6',
|
||||
'lightcoral': '#F08080',
|
||||
'lightcyan': '#E0FFFF',
|
||||
'lightgoldenrodyellow': '#FAFAD2',
|
||||
'lightgray': '#D3D3D3',
|
||||
'lightgrey': '#D3D3D3',
|
||||
'lightgreen': '#90EE90',
|
||||
'lightpink': '#FFB6C1',
|
||||
'lightsalmon': '#FFA07A',
|
||||
'lightseagreen': '#20B2AA',
|
||||
'lightskyblue': '#87CEFA',
|
||||
'lightslategray': '#778899',
|
||||
'lightslategrey': '#778899',
|
||||
'lightsteelblue': '#B0C4DE',
|
||||
'lightyellow': '#FFFFE0',
|
||||
'lime': '#00FF00',
|
||||
'limegreen': '#32CD32',
|
||||
'linen': '#FAF0E6',
|
||||
'magenta': '#FF00FF',
|
||||
'maroon': '#800000',
|
||||
'mediumaquamarine': '#66CDAA',
|
||||
'mediumblue': '#0000CD',
|
||||
'mediumorchid': '#BA55D3',
|
||||
'mediumpurple': '#9370DB',
|
||||
'mediumseagreen': '#3CB371',
|
||||
'mediumslateblue': '#7B68EE',
|
||||
'mediumspringgreen': '#00FA9A',
|
||||
'mediumturquoise': '#48D1CC',
|
||||
'mediumvioletred': '#C71585',
|
||||
'midnightblue': '#191970',
|
||||
'mintcream': '#F5FFFA',
|
||||
'mistyrose': '#FFE4E1',
|
||||
'moccasin': '#FFE4B5',
|
||||
'navajowhite': '#FFDEAD',
|
||||
'navy': '#000080',
|
||||
'oldlace': '#FDF5E6',
|
||||
'olive': '#808000',
|
||||
'olivedrab': '#6B8E23',
|
||||
'orange': '#FFA500',
|
||||
'orangered': '#FF4500',
|
||||
'orchid': '#DA70D6',
|
||||
'palegoldenrod': '#EEE8AA',
|
||||
'palegreen': '#98FB98',
|
||||
'paleturquoise': '#AFEEEE',
|
||||
'palevioletred': '#DB7093',
|
||||
'papayawhip': '#FFEFD5',
|
||||
'peachpuff': '#FFDAB9',
|
||||
'peru': '#CD853F',
|
||||
'pink': '#FFC0CB',
|
||||
'plum': '#DDA0DD',
|
||||
'powderblue': '#B0E0E6',
|
||||
'purple': '#800080',
|
||||
'red': '#FF0000',
|
||||
'rosybrown': '#BC8F8F',
|
||||
'royalblue': '#4169E1',
|
||||
'saddlebrown': '#8B4513',
|
||||
'salmon': '#FA8072',
|
||||
'sandybrown': '#F4A460',
|
||||
'seagreen': '#2E8B57',
|
||||
'seashell': '#FFF5EE',
|
||||
'sienna': '#A0522D',
|
||||
'silver': '#C0C0C0',
|
||||
'skyblue': '#87CEEB',
|
||||
'slateblue': '#6A5ACD',
|
||||
'slategray': '#708090',
|
||||
'slategrey': '#708090',
|
||||
'snow': '#FFFAFA',
|
||||
'springgreen': '#00FF7F',
|
||||
'steelblue': '#4682B4',
|
||||
'tan': '#D2B48C',
|
||||
'teal': '#008080',
|
||||
'thistle': '#D8BFD8',
|
||||
'tomato': '#FF6347',
|
||||
'turquoise': '#40E0D0',
|
||||
'violet': '#EE82EE',
|
||||
'wheat': '#F5DEB3',
|
||||
'white': '#FFFFFF',
|
||||
'whitesmoke': '#F5F5F5',
|
||||
'yellow': '#FFFF00',
|
||||
'yellowgreen': '#9ACD32'
|
||||
"aliceblue": "#F0F8FF",
|
||||
"antiquewhite": "#FAEBD7",
|
||||
"aqua": "#00FFFF",
|
||||
"aquamarine": "#7FFFD4",
|
||||
"azure": "#F0FFFF",
|
||||
"beige": "#F5F5DC",
|
||||
"bisque": "#FFE4C4",
|
||||
"black": "#000000",
|
||||
"blanchedalmond": "#FFEBCD",
|
||||
"blue": "#0000FF",
|
||||
"blueviolet": "#8A2BE2",
|
||||
"brown": "#A52A2A",
|
||||
"burlywood": "#DEB887",
|
||||
"cadetblue": "#5F9EA0",
|
||||
"chartreuse": "#7FFF00",
|
||||
"chocolate": "#D2691E",
|
||||
"coral": "#FF7F50",
|
||||
"cornflowerblue": "#6495ED",
|
||||
"cornsilk": "#FFF8DC",
|
||||
"crimson": "#DC143C",
|
||||
"cyan": "#00FFFF",
|
||||
"darkblue": "#00008B",
|
||||
"darkcyan": "#008B8B",
|
||||
"darkgoldenrod": "#B8860B",
|
||||
"darkgray": "#A9A9A9",
|
||||
"darkgrey": "#A9A9A9",
|
||||
"darkgreen": "#006400",
|
||||
"darkkhaki": "#BDB76B",
|
||||
"darkmagenta": "#8B008B",
|
||||
"darkolivegreen": "#556B2F",
|
||||
"darkorange": "#FF8C00",
|
||||
"darkorchid": "#9932CC",
|
||||
"darkred": "#8B0000",
|
||||
"darksalmon": "#E9967A",
|
||||
"darkseagreen": "#8FBC8B",
|
||||
"darkslateblue": "#483D8B",
|
||||
"darkslategray": "#2F4F4F",
|
||||
"darkslategrey": "#2F4F4F",
|
||||
"darkturquoise": "#00CED1",
|
||||
"darkviolet": "#9400D3",
|
||||
"deeppink": "#FF1493",
|
||||
"deepskyblue": "#00BFFF",
|
||||
"dimgray": "#696969",
|
||||
"dimgrey": "#696969",
|
||||
"dodgerblue": "#1E90FF",
|
||||
"firebrick": "#B22222",
|
||||
"floralwhite": "#FFFAF0",
|
||||
"forestgreen": "#228B22",
|
||||
"fuchsia": "#FF00FF",
|
||||
"gainsboro": "#DCDCDC",
|
||||
"ghostwhite": "#F8F8FF",
|
||||
"gold": "#FFD700",
|
||||
"goldenrod": "#DAA520",
|
||||
"gray": "#808080",
|
||||
"grey": "#808080",
|
||||
"green": "#008000",
|
||||
"greenyellow": "#ADFF2F",
|
||||
"honeydew": "#F0FFF0",
|
||||
"hotpink": "#FF69B4",
|
||||
"indianred": "#CD5C5C",
|
||||
"indigo": "#4B0082",
|
||||
"ivory": "#FFFFF0",
|
||||
"khaki": "#F0E68C",
|
||||
"lavender": "#E6E6FA",
|
||||
"lavenderblush": "#FFF0F5",
|
||||
"lawngreen": "#7CFC00",
|
||||
"lemonchiffon": "#FFFACD",
|
||||
"lightblue": "#ADD8E6",
|
||||
"lightcoral": "#F08080",
|
||||
"lightcyan": "#E0FFFF",
|
||||
"lightgoldenrodyellow": "#FAFAD2",
|
||||
"lightgray": "#D3D3D3",
|
||||
"lightgrey": "#D3D3D3",
|
||||
"lightgreen": "#90EE90",
|
||||
"lightpink": "#FFB6C1",
|
||||
"lightsalmon": "#FFA07A",
|
||||
"lightseagreen": "#20B2AA",
|
||||
"lightskyblue": "#87CEFA",
|
||||
"lightslategray": "#778899",
|
||||
"lightslategrey": "#778899",
|
||||
"lightsteelblue": "#B0C4DE",
|
||||
"lightyellow": "#FFFFE0",
|
||||
"lime": "#00FF00",
|
||||
"limegreen": "#32CD32",
|
||||
"linen": "#FAF0E6",
|
||||
"magenta": "#FF00FF",
|
||||
"maroon": "#800000",
|
||||
"mediumaquamarine": "#66CDAA",
|
||||
"mediumblue": "#0000CD",
|
||||
"mediumorchid": "#BA55D3",
|
||||
"mediumpurple": "#9370DB",
|
||||
"mediumseagreen": "#3CB371",
|
||||
"mediumslateblue": "#7B68EE",
|
||||
"mediumspringgreen": "#00FA9A",
|
||||
"mediumturquoise": "#48D1CC",
|
||||
"mediumvioletred": "#C71585",
|
||||
"midnightblue": "#191970",
|
||||
"mintcream": "#F5FFFA",
|
||||
"mistyrose": "#FFE4E1",
|
||||
"moccasin": "#FFE4B5",
|
||||
"navajowhite": "#FFDEAD",
|
||||
"navy": "#000080",
|
||||
"oldlace": "#FDF5E6",
|
||||
"olive": "#808000",
|
||||
"olivedrab": "#6B8E23",
|
||||
"orange": "#FFA500",
|
||||
"orangered": "#FF4500",
|
||||
"orchid": "#DA70D6",
|
||||
"palegoldenrod": "#EEE8AA",
|
||||
"palegreen": "#98FB98",
|
||||
"paleturquoise": "#AFEEEE",
|
||||
"palevioletred": "#DB7093",
|
||||
"papayawhip": "#FFEFD5",
|
||||
"peachpuff": "#FFDAB9",
|
||||
"peru": "#CD853F",
|
||||
"pink": "#FFC0CB",
|
||||
"plum": "#DDA0DD",
|
||||
"powderblue": "#B0E0E6",
|
||||
"purple": "#800080",
|
||||
"red": "#FF0000",
|
||||
"rosybrown": "#BC8F8F",
|
||||
"royalblue": "#4169E1",
|
||||
"saddlebrown": "#8B4513",
|
||||
"salmon": "#FA8072",
|
||||
"sandybrown": "#F4A460",
|
||||
"seagreen": "#2E8B57",
|
||||
"seashell": "#FFF5EE",
|
||||
"sienna": "#A0522D",
|
||||
"silver": "#C0C0C0",
|
||||
"skyblue": "#87CEEB",
|
||||
"slateblue": "#6A5ACD",
|
||||
"slategray": "#708090",
|
||||
"slategrey": "#708090",
|
||||
"snow": "#FFFAFA",
|
||||
"springgreen": "#00FF7F",
|
||||
"steelblue": "#4682B4",
|
||||
"tan": "#D2B48C",
|
||||
"teal": "#008080",
|
||||
"thistle": "#D8BFD8",
|
||||
"tomato": "#FF6347",
|
||||
"turquoise": "#40E0D0",
|
||||
"violet": "#EE82EE",
|
||||
"wheat": "#F5DEB3",
|
||||
"white": "#FFFFFF",
|
||||
"whitesmoke": "#F5F5F5",
|
||||
"yellow": "#FFFF00",
|
||||
"yellowgreen": "#9ACD32",
|
||||
};
|
||||
|
@ -7,9 +7,7 @@
|
||||
* @license Distributed under the terms of the MIT License
|
||||
*/
|
||||
|
||||
|
||||
import {Color} from './Color.js';
|
||||
|
||||
import { Color } from "./Color.js";
|
||||
|
||||
/**
|
||||
* <p>This mixin implement color and contrast changes for visual stimuli</p>
|
||||
@ -17,15 +15,15 @@ import {Color} from './Color.js';
|
||||
* @name module:util.ColorMixin
|
||||
* @mixin
|
||||
*/
|
||||
export let ColorMixin = (superclass) => class extends superclass
|
||||
{
|
||||
constructor(args)
|
||||
export let ColorMixin = (superclass) =>
|
||||
class extends superclass
|
||||
{
|
||||
super(args);
|
||||
}
|
||||
constructor(args)
|
||||
{
|
||||
super(args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Setter for Color attribute.
|
||||
*
|
||||
* @name module:util.ColorMixin#setColor
|
||||
@ -34,16 +32,15 @@ export let ColorMixin = (superclass) => class extends superclass
|
||||
* @param {Color} color - the new color
|
||||
* @param {boolean} [log= false] - whether or not to log
|
||||
*/
|
||||
setColor(color, log)
|
||||
{
|
||||
this._setAttribute('color', color, log);
|
||||
setColor(color, log)
|
||||
{
|
||||
this._setAttribute("color", color, log);
|
||||
|
||||
this._needUpdate = true;
|
||||
this._needPixiUpdate = true;
|
||||
}
|
||||
this._needUpdate = true;
|
||||
this._needPixiUpdate = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Setter for Contrast attribute.
|
||||
*
|
||||
* @name module:util.ColorMixin#setContrast
|
||||
@ -52,16 +49,15 @@ export let ColorMixin = (superclass) => class extends superclass
|
||||
* @param {number} contrast - the new contrast (must be between 0 and 1)
|
||||
* @param {boolean} [log= false] - whether or not to log
|
||||
*/
|
||||
setContrast(contrast, log)
|
||||
{
|
||||
this._setAttribute('contrast', contrast, log);
|
||||
setContrast(contrast, log)
|
||||
{
|
||||
this._setAttribute("contrast", contrast, log);
|
||||
|
||||
this._needUpdate = true;
|
||||
this._needPixiUpdate = true;
|
||||
}
|
||||
this._needUpdate = true;
|
||||
this._needPixiUpdate = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get a new contrasted Color.
|
||||
*
|
||||
* @name module:util.ColorMixin#getContrastedColor
|
||||
@ -70,10 +66,9 @@ export let ColorMixin = (superclass) => class extends superclass
|
||||
* @param {string|number|Array.<number>} color - the color
|
||||
* @param {number} contrast - the contrast (must be between 0 and 1)
|
||||
*/
|
||||
getContrastedColor(color, contrast)
|
||||
{
|
||||
const rgb = color.rgb.map(c => (c * 2.0 - 1.0) * contrast);
|
||||
return new Color(rgb, Color.COLOR_SPACE.RGB);
|
||||
}
|
||||
|
||||
};
|
||||
getContrastedColor(color, contrast)
|
||||
{
|
||||
const rgb = color.rgb.map((c) => (c * 2.0 - 1.0) * contrast);
|
||||
return new Color(rgb, Color.COLOR_SPACE.RGB);
|
||||
}
|
||||
};
|
||||
|
@ -7,9 +7,7 @@
|
||||
* @license Distributed under the terms of the MIT License
|
||||
*/
|
||||
|
||||
|
||||
import * as util from './Util.js';
|
||||
|
||||
import * as util from "./Util.js";
|
||||
|
||||
/**
|
||||
* <p>EventEmitter implements the classic observer/observable pattern.</p>
|
||||
@ -34,7 +32,6 @@ export class EventEmitter
|
||||
this._onceUuids = new Map();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Listener called when this instance emits an event for which it is registered.
|
||||
*
|
||||
@ -42,7 +39,6 @@ export class EventEmitter
|
||||
* @param {object} data - the data passed to the listener
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Register a new listener for events with the given name emitted by this instance.
|
||||
*
|
||||
@ -56,9 +52,9 @@ export class EventEmitter
|
||||
on(name, listener)
|
||||
{
|
||||
// check that the listener is a function:
|
||||
if (typeof listener !== 'function')
|
||||
if (typeof listener !== "function")
|
||||
{
|
||||
throw new TypeError('listener must be a function');
|
||||
throw new TypeError("listener must be a function");
|
||||
}
|
||||
|
||||
// generate a new uuid:
|
||||
@ -69,12 +65,11 @@ export class EventEmitter
|
||||
{
|
||||
this._listeners.set(name, []);
|
||||
}
|
||||
this._listeners.get(name).push({uuid, listener});
|
||||
this._listeners.get(name).push({ uuid, listener });
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register a new listener for the given event name, and remove it as soon as the event has been emitted.
|
||||
*
|
||||
@ -98,7 +93,6 @@ export class EventEmitter
|
||||
return uuid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the listener with the given uuid associated to the given event name.
|
||||
*
|
||||
@ -114,13 +108,12 @@ export class EventEmitter
|
||||
|
||||
if (relevantUuidListeners && relevantUuidListeners.length)
|
||||
{
|
||||
this._listeners.set(name, relevantUuidListeners.filter(uuidlistener => (uuidlistener.uuid != uuid)));
|
||||
this._listeners.set(name, relevantUuidListeners.filter((uuidlistener) => (uuidlistener.uuid != uuid)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Emit an event with a given name and associated data.
|
||||
*
|
||||
@ -138,11 +131,11 @@ export class EventEmitter
|
||||
{
|
||||
let onceUuids = this._onceUuids.get(name);
|
||||
let self = this;
|
||||
relevantUuidListeners.forEach(({uuid, listener}) =>
|
||||
relevantUuidListeners.forEach(({ uuid, listener }) =>
|
||||
{
|
||||
listener(data);
|
||||
|
||||
if (typeof onceUuids !== 'undefined' && onceUuids.includes(uuid))
|
||||
if (typeof onceUuids !== "undefined" && onceUuids.includes(uuid))
|
||||
{
|
||||
self.off(name, uuid);
|
||||
}
|
||||
@ -152,6 +145,4 @@ export class EventEmitter
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,10 +8,8 @@
|
||||
* @license Distributed under the terms of the MIT License
|
||||
*/
|
||||
|
||||
|
||||
import {EventEmitter} from './EventEmitter.js';
|
||||
import * as util from './Util.js';
|
||||
|
||||
import { EventEmitter } from "./EventEmitter.js";
|
||||
import * as util from "./Util.js";
|
||||
|
||||
/**
|
||||
* <p>PsychoObject is the base class for all PsychoJS objects.
|
||||
@ -32,14 +30,13 @@ export class PsychObject extends EventEmitter
|
||||
this._userAttributes = new Set();
|
||||
|
||||
// name:
|
||||
if (typeof name === 'undefined')
|
||||
if (typeof name === "undefined")
|
||||
{
|
||||
name = this.constructor.name;
|
||||
}
|
||||
this._addAttribute('name', name);
|
||||
this._addAttribute("name", name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the PsychoJS instance.
|
||||
*
|
||||
@ -51,7 +48,6 @@ export class PsychObject extends EventEmitter
|
||||
return this._psychoJS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setter for the PsychoJS attribute.
|
||||
*
|
||||
@ -63,7 +59,6 @@ export class PsychObject extends EventEmitter
|
||||
this._psychoJS = psychoJS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* String representation of the PsychObject.
|
||||
*
|
||||
@ -74,38 +69,37 @@ export class PsychObject extends EventEmitter
|
||||
*/
|
||||
toString()
|
||||
{
|
||||
let representation = this.constructor.name + '( ';
|
||||
let representation = this.constructor.name + "( ";
|
||||
let addComma = false;
|
||||
for (const attribute of this._userAttributes)
|
||||
{
|
||||
if (addComma)
|
||||
{
|
||||
representation += ', ';
|
||||
representation += ", ";
|
||||
}
|
||||
addComma = true;
|
||||
|
||||
let value = util.toString(this['_' + attribute]);
|
||||
let value = util.toString(this["_" + attribute]);
|
||||
const l = value.length;
|
||||
if (l > 50)
|
||||
{
|
||||
if (value[l - 1] === ')')
|
||||
if (value[l - 1] === ")")
|
||||
{
|
||||
value = value.substring(0, 50) + '~)';
|
||||
value = value.substring(0, 50) + "~)";
|
||||
}
|
||||
else
|
||||
{
|
||||
value = value.substring(0, 50) + '~';
|
||||
value = value.substring(0, 50) + "~";
|
||||
}
|
||||
}
|
||||
|
||||
representation += attribute + '=' + value;
|
||||
representation += attribute + "=" + value;
|
||||
}
|
||||
representation += ' )';
|
||||
representation += " )";
|
||||
|
||||
return representation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the value of an attribute.
|
||||
*
|
||||
@ -121,31 +115,30 @@ export class PsychObject extends EventEmitter
|
||||
_setAttribute(attributeName, attributeValue, log = false, operation = undefined, stealth = false)
|
||||
{
|
||||
const response = {
|
||||
origin: 'PsychObject.setAttribute',
|
||||
context: 'when setting the attribute of an object'
|
||||
origin: "PsychObject.setAttribute",
|
||||
context: "when setting the attribute of an object",
|
||||
};
|
||||
|
||||
if (typeof attributeName == 'undefined')
|
||||
if (typeof attributeName == "undefined")
|
||||
{
|
||||
throw Object.assign(response, {
|
||||
error: 'the attribute name cannot be' +
|
||||
' undefined'
|
||||
error: "the attribute name cannot be"
|
||||
+ " undefined",
|
||||
});
|
||||
}
|
||||
if (typeof attributeValue == 'undefined')
|
||||
if (typeof attributeValue == "undefined")
|
||||
{
|
||||
this._psychoJS.logger.warn('setting the value of attribute: ' + attributeName + ' in PsychObject: ' + this._name + ' as: undefined');
|
||||
this._psychoJS.logger.warn("setting the value of attribute: " + attributeName + " in PsychObject: " + this._name + " as: undefined");
|
||||
}
|
||||
|
||||
// (*) apply operation to old and new values:
|
||||
if (typeof operation !== 'undefined' && this.hasOwnProperty('_' + attributeName))
|
||||
if (typeof operation !== "undefined" && this.hasOwnProperty("_" + attributeName))
|
||||
{
|
||||
let oldValue = this['_' + attributeName];
|
||||
let oldValue = this["_" + attributeName];
|
||||
|
||||
// operations can only be applied to numbers and array of numbers (which can be empty):
|
||||
if (typeof attributeValue == 'number' || (Array.isArray(attributeValue) && (attributeValue.length === 0 || typeof attributeValue[0] == 'number')))
|
||||
if (typeof attributeValue == "number" || (Array.isArray(attributeValue) && (attributeValue.length === 0 || typeof attributeValue[0] == "number")))
|
||||
{
|
||||
|
||||
// value is an array:
|
||||
if (Array.isArray(attributeValue))
|
||||
{
|
||||
@ -155,160 +148,158 @@ export class PsychObject extends EventEmitter
|
||||
if (attributeValue.length !== oldValue.length)
|
||||
{
|
||||
throw Object.assign(response, {
|
||||
error: 'old and new' +
|
||||
' value should have' +
|
||||
' the same size when they are both arrays'
|
||||
error: "old and new"
|
||||
+ " value should have"
|
||||
+ " the same size when they are both arrays",
|
||||
});
|
||||
}
|
||||
|
||||
switch (operation)
|
||||
{
|
||||
case '':
|
||||
case "":
|
||||
// no change to value;
|
||||
break;
|
||||
case '+':
|
||||
case "+":
|
||||
attributeValue = attributeValue.map((v, i) => oldValue[i] + v);
|
||||
break;
|
||||
case '*':
|
||||
case "*":
|
||||
attributeValue = attributeValue.map((v, i) => oldValue[i] * v);
|
||||
break;
|
||||
case '-':
|
||||
case "-":
|
||||
attributeValue = attributeValue.map((v, i) => oldValue[i] - v);
|
||||
break;
|
||||
case '/':
|
||||
case "/":
|
||||
attributeValue = attributeValue.map((v, i) => oldValue[i] / v);
|
||||
break;
|
||||
case '**':
|
||||
case "**":
|
||||
attributeValue = attributeValue.map((v, i) => oldValue[i] ** v);
|
||||
break;
|
||||
case '%':
|
||||
case "%":
|
||||
attributeValue = attributeValue.map((v, i) => oldValue[i] % v);
|
||||
break;
|
||||
default:
|
||||
throw Object.assign(response, {
|
||||
error: 'unsupported' +
|
||||
' operation: ' + operation + ' when setting: ' + attributeName + ' in: ' + this.name
|
||||
error: "unsupported"
|
||||
+ " operation: " + operation + " when setting: " + attributeName + " in: " + this.name,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
// old value is a scalar
|
||||
else
|
||||
{
|
||||
switch (operation)
|
||||
{
|
||||
case '':
|
||||
case "":
|
||||
// no change to value;
|
||||
break;
|
||||
case '+':
|
||||
attributeValue = attributeValue.map(v => oldValue + v);
|
||||
case "+":
|
||||
attributeValue = attributeValue.map((v) => oldValue + v);
|
||||
break;
|
||||
case '*':
|
||||
attributeValue = attributeValue.map(v => oldValue * v);
|
||||
case "*":
|
||||
attributeValue = attributeValue.map((v) => oldValue * v);
|
||||
break;
|
||||
case '-':
|
||||
attributeValue = attributeValue.map(v => oldValue - v);
|
||||
case "-":
|
||||
attributeValue = attributeValue.map((v) => oldValue - v);
|
||||
break;
|
||||
case '/':
|
||||
attributeValue = attributeValue.map(v => oldValue / v);
|
||||
case "/":
|
||||
attributeValue = attributeValue.map((v) => oldValue / v);
|
||||
break;
|
||||
case '**':
|
||||
attributeValue = attributeValue.map(v => oldValue ** v);
|
||||
case "**":
|
||||
attributeValue = attributeValue.map((v) => oldValue ** v);
|
||||
break;
|
||||
case '%':
|
||||
attributeValue = attributeValue.map(v => oldValue % v);
|
||||
case "%":
|
||||
attributeValue = attributeValue.map((v) => oldValue % v);
|
||||
break;
|
||||
default:
|
||||
throw Object.assign(response, {
|
||||
error: 'unsupported' +
|
||||
' value: ' + JSON.stringify(attributeValue) + ' for' +
|
||||
' operation: ' + operation + ' when setting: ' + attributeName + ' in: ' + this.name
|
||||
error: "unsupported"
|
||||
+ " value: " + JSON.stringify(attributeValue) + " for"
|
||||
+ " operation: " + operation + " when setting: " + attributeName + " in: " + this.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
// value is a scalar
|
||||
else
|
||||
{
|
||||
// old value is an array
|
||||
if (Array.isArray(oldValue))
|
||||
{
|
||||
switch (operation)
|
||||
{
|
||||
case '':
|
||||
attributeValue = oldValue.map(v => attributeValue);
|
||||
case "":
|
||||
attributeValue = oldValue.map((v) => attributeValue);
|
||||
break;
|
||||
case '+':
|
||||
attributeValue = oldValue.map(v => v + attributeValue);
|
||||
case "+":
|
||||
attributeValue = oldValue.map((v) => v + attributeValue);
|
||||
break;
|
||||
case '*':
|
||||
attributeValue = oldValue.map(v => v * attributeValue);
|
||||
case "*":
|
||||
attributeValue = oldValue.map((v) => v * attributeValue);
|
||||
break;
|
||||
case '-':
|
||||
attributeValue = oldValue.map(v => v - attributeValue);
|
||||
case "-":
|
||||
attributeValue = oldValue.map((v) => v - attributeValue);
|
||||
break;
|
||||
case '/':
|
||||
attributeValue = oldValue.map(v => v / attributeValue);
|
||||
case "/":
|
||||
attributeValue = oldValue.map((v) => v / attributeValue);
|
||||
break;
|
||||
case '**':
|
||||
attributeValue = oldValue.map(v => v ** attributeValue);
|
||||
case "**":
|
||||
attributeValue = oldValue.map((v) => v ** attributeValue);
|
||||
break;
|
||||
case '%':
|
||||
attributeValue = oldValue.map(v => v % attributeValue);
|
||||
case "%":
|
||||
attributeValue = oldValue.map((v) => v % attributeValue);
|
||||
break;
|
||||
default:
|
||||
throw Object.assign(response, {
|
||||
error: 'unsupported' +
|
||||
' operation: ' + operation + ' when setting: ' + attributeName + ' in: ' + this.name
|
||||
error: "unsupported"
|
||||
+ " operation: " + operation + " when setting: " + attributeName + " in: " + this.name,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
// old value is a scalar
|
||||
else
|
||||
{
|
||||
switch (operation)
|
||||
{
|
||||
case '':
|
||||
case "":
|
||||
// no change to value;
|
||||
break;
|
||||
case '+':
|
||||
case "+":
|
||||
attributeValue = oldValue + attributeValue;
|
||||
break;
|
||||
case '*':
|
||||
case "*":
|
||||
attributeValue = oldValue * attributeValue;
|
||||
break;
|
||||
case '-':
|
||||
case "-":
|
||||
attributeValue = oldValue - attributeValue;
|
||||
break;
|
||||
case '/':
|
||||
case "/":
|
||||
attributeValue = oldValue / attributeValue;
|
||||
break;
|
||||
case '**':
|
||||
case "**":
|
||||
attributeValue = oldValue ** attributeValue;
|
||||
break;
|
||||
case '%':
|
||||
case "%":
|
||||
attributeValue = oldValue % attributeValue;
|
||||
break;
|
||||
default:
|
||||
throw Object.assign(response, {
|
||||
error: 'unsupported' +
|
||||
' value: ' + JSON.stringify(attributeValue) + ' for operation: ' + operation + ' when setting: ' + attributeName + ' in: ' + this.name
|
||||
error: "unsupported"
|
||||
+ " value: " + JSON.stringify(attributeValue) + " for operation: " + operation + " when setting: " + attributeName + " in: " + this.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Object.assign(response, {error: 'operation: ' + operation + ' is invalid for old value: ' + JSON.stringify(oldValue) + ' and new value: ' + JSON.stringify(attributeValue)});
|
||||
throw Object.assign(response, {
|
||||
error: "operation: " + operation + " is invalid for old value: " + JSON.stringify(oldValue) + " and new value: " + JSON.stringify(attributeValue),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// (*) log if appropriate:
|
||||
if (!stealth && (log || this._autoLog) && (typeof this.win !== 'undefined'))
|
||||
if (!stealth && (log || this._autoLog) && (typeof this.win !== "undefined"))
|
||||
{
|
||||
const msg = this.name + ": " + attributeName + " = " + util.toString(attributeValue);
|
||||
this.win.logOnFlip({
|
||||
@ -317,13 +308,12 @@ export class PsychObject extends EventEmitter
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// (*) set the value of the attribute and return whether it has changed:
|
||||
const previousAttributeValue = this['_' + attributeName];
|
||||
this['_' + attributeName] = attributeValue;
|
||||
const previousAttributeValue = this["_" + attributeName];
|
||||
this["_" + attributeName] = attributeValue;
|
||||
|
||||
// Things seem OK without this check except for 'vertices'
|
||||
if (typeof previousAttributeValue === 'undefined')
|
||||
if (typeof previousAttributeValue === "undefined")
|
||||
{
|
||||
// Not that any of the following lines should throw, but evaluating
|
||||
// `this._vertices.map` on `ShapeStim._getVertices_px()` seems to
|
||||
@ -342,10 +332,9 @@ export class PsychObject extends EventEmitter
|
||||
// `Util.toString()` might try, but fail to stringify in a meaningful way are assigned
|
||||
// an 'Object (circular)' string representation. For being opaque as to their raw
|
||||
// value, those types of input are liable to produce PIXI updates.
|
||||
return prev === 'Object (circular)' || next === 'Object (circular)' || prev !== next;
|
||||
return prev === "Object (circular)" || next === "Object (circular)" || prev !== next;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an attribute to this instance (e.g. define setters and getters) and affect a value to it.
|
||||
*
|
||||
@ -355,20 +344,21 @@ export class PsychObject extends EventEmitter
|
||||
* @param {object} [defaultValue] - the default value for the attribute
|
||||
* @param {function} [onChange] - function called upon changes to the attribute value
|
||||
*/
|
||||
_addAttribute(name, value, defaultValue = undefined, onChange = () => {})
|
||||
_addAttribute(name, value, defaultValue = undefined, onChange = () =>
|
||||
{})
|
||||
{
|
||||
const getPropertyName = 'get' + name[0].toUpperCase() + name.substr(1);
|
||||
if (typeof this[getPropertyName] === 'undefined')
|
||||
const getPropertyName = "get" + name[0].toUpperCase() + name.substr(1);
|
||||
if (typeof this[getPropertyName] === "undefined")
|
||||
{
|
||||
this[getPropertyName] = () => this['_' + name];
|
||||
this[getPropertyName] = () => this["_" + name];
|
||||
}
|
||||
|
||||
const setPropertyName = 'set' + name[0].toUpperCase() + name.substr(1);
|
||||
if (typeof this[setPropertyName] === 'undefined')
|
||||
const setPropertyName = "set" + name[0].toUpperCase() + name.substr(1);
|
||||
if (typeof this[setPropertyName] === "undefined")
|
||||
{
|
||||
this[setPropertyName] = (value, log = false) =>
|
||||
{
|
||||
if (typeof value === 'undefined' || value === null)
|
||||
if (typeof value === "undefined" || value === null)
|
||||
{
|
||||
value = defaultValue;
|
||||
}
|
||||
@ -382,7 +372,7 @@ export class PsychObject extends EventEmitter
|
||||
else
|
||||
{
|
||||
// deal with default value:
|
||||
if (typeof value === 'undefined' || value === null)
|
||||
if (typeof value === "undefined" || value === null)
|
||||
{
|
||||
value = defaultValue;
|
||||
}
|
||||
@ -397,16 +387,14 @@ export class PsychObject extends EventEmitter
|
||||
set(value)
|
||||
{
|
||||
this[setPropertyName](value);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
// note: we use this[name] instead of this['_' + name] since a this.set<Name> method may available
|
||||
// in the object, in which case we need to call it
|
||||
this[name] = value;
|
||||
//this['_' + name] = value;
|
||||
// this['_' + name] = value;
|
||||
|
||||
this._userAttributes.add(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
* @license Distributed under the terms of the MIT License
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* <p>A scheduler helps run the main loop by managing scheduled functions,
|
||||
* called tasks, after each frame is displayed.</p>
|
||||
@ -53,7 +52,6 @@ export class Scheduler
|
||||
this._status = Scheduler.Status.STOPPED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the status of the scheduler.
|
||||
*
|
||||
@ -66,7 +64,6 @@ export class Scheduler
|
||||
return this._status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Task to be run by the scheduler.
|
||||
*
|
||||
@ -87,7 +84,6 @@ export class Scheduler
|
||||
this._argsList.push(args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Condition evaluated when the task is run.
|
||||
*
|
||||
@ -108,7 +104,7 @@ export class Scheduler
|
||||
addConditional(condition, thenScheduler, elseScheduler)
|
||||
{
|
||||
const self = this;
|
||||
let task = function ()
|
||||
let task = function()
|
||||
{
|
||||
if (condition())
|
||||
{
|
||||
@ -125,7 +121,6 @@ export class Scheduler
|
||||
this.add(task);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start this scheduler.
|
||||
*
|
||||
@ -173,7 +168,6 @@ export class Scheduler
|
||||
requestAnimationFrame(update);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stop this scheduler.
|
||||
*
|
||||
@ -187,7 +181,6 @@ export class Scheduler
|
||||
this._stopAtNextUpdate = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the next scheduled tasks, in sequence, until a rendering of the scene is requested.
|
||||
*
|
||||
@ -209,9 +202,8 @@ export class Scheduler
|
||||
}
|
||||
|
||||
// if there is no current task, we look for the next one in the list or quit if there is none:
|
||||
if (typeof this._currentTask == 'undefined')
|
||||
if (typeof this._currentTask == "undefined")
|
||||
{
|
||||
|
||||
// a task is available in the taskList:
|
||||
if (this._taskList.length > 0)
|
||||
{
|
||||
@ -259,15 +251,12 @@ export class Scheduler
|
||||
this._currentTask = undefined;
|
||||
this._currentArgs = undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Events.
|
||||
*
|
||||
@ -280,25 +269,24 @@ Scheduler.Event = {
|
||||
/**
|
||||
* Move onto the next task *without* rendering the scene first.
|
||||
*/
|
||||
NEXT: Symbol.for('NEXT'),
|
||||
NEXT: Symbol.for("NEXT"),
|
||||
|
||||
/**
|
||||
* Render the scene and repeat the task.
|
||||
*/
|
||||
FLIP_REPEAT: Symbol.for('FLIP_REPEAT'),
|
||||
FLIP_REPEAT: Symbol.for("FLIP_REPEAT"),
|
||||
|
||||
/**
|
||||
* Render the scene and move onto the next task.
|
||||
*/
|
||||
FLIP_NEXT: Symbol.for('FLIP_NEXT'),
|
||||
FLIP_NEXT: Symbol.for("FLIP_NEXT"),
|
||||
|
||||
/**
|
||||
* Quit the scheduler.
|
||||
*/
|
||||
QUIT: Symbol.for('QUIT')
|
||||
QUIT: Symbol.for("QUIT"),
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Status.
|
||||
*
|
||||
@ -311,10 +299,10 @@ Scheduler.Status = {
|
||||
/**
|
||||
* The Scheduler is running.
|
||||
*/
|
||||
RUNNING: Symbol.for('RUNNING'),
|
||||
RUNNING: Symbol.for("RUNNING"),
|
||||
|
||||
/**
|
||||
* The Scheduler is stopped.
|
||||
*/
|
||||
STOPPED: Symbol.for('STOPPED')
|
||||
STOPPED: Symbol.for("STOPPED"),
|
||||
};
|
||||
|
422
src/util/Util.js
422
src/util/Util.js
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,8 @@
|
||||
export * from './Clock.js';
|
||||
export * from './Color.js';
|
||||
export * from './ColorMixin.js';
|
||||
export * from './EventEmitter.js';
|
||||
export * from "./Clock.js";
|
||||
export * from "./Color.js";
|
||||
export * from "./ColorMixin.js";
|
||||
export * from "./EventEmitter.js";
|
||||
export * from "./Pixi.js";
|
||||
export * from './PsychObject.js';
|
||||
export * from './Scheduler.js';
|
||||
export * from './Util.js';
|
||||
export * from "./PsychObject.js";
|
||||
export * from "./Scheduler.js";
|
||||
export * from "./Util.js";
|
||||
|
Loading…
Reference in New Issue
Block a user